fix(fs/S3Handler#_write): work when file doesn't exist (#5561)

This commit is contained in:
Nicolas Raynaud
2021-02-16 13:45:01 +01:00
committed by GitHub
parent 10b127ca55
commit e5d711dd28
2 changed files with 12 additions and 2 deletions

View File

@@ -152,10 +152,19 @@ export default class S3Handler extends RemoteHandlerAbstract {
file = file.fd
}
const uploadParams = this._createParams(file)
const fileSize = +(await this._s3.headObject(uploadParams)).ContentLength
let fileSize
try {
fileSize = +(await this._s3.headObject(uploadParams)).ContentLength
} catch (e) {
if (e.code === 'NotFound') {
fileSize = 0
} else {
throw e
}
}
if (fileSize < MIN_PART_SIZE) {
const resultBuffer = Buffer.alloc(Math.max(fileSize, position + buffer.length))
const fileContent = (await this._s3.getObject(uploadParams)).Body
const fileContent = fileSize !== 0 ? (await this._s3.getObject(uploadParams)).Body : Buffer.alloc(0)
fileContent.copy(resultBuffer)
buffer.copy(resultBuffer, position)
await this._s3.putObject({ ...uploadParams, Body: resultBuffer })

View File

@@ -38,6 +38,7 @@
>
> In case of conflict, the highest (lowest in previous list) `$version` wins.
- @xen-orchestra/fs minor
- xen-api patch
- xo-common minor
- xo-server minor