Skip to content

Commit

Permalink
feat(fs/s3): object lock mode need content md5
Browse files Browse the repository at this point in the history
and the middleware consume addiitionnal memory
  • Loading branch information
fbeauchamp authored and julien-f committed Oct 23, 2023
1 parent 9e66753 commit 5048485
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions @xen-orchestra/fs/src/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
CreateMultipartUploadCommand,
DeleteObjectCommand,
GetObjectCommand,
GetObjectLockConfigurationCommand,
HeadObjectCommand,
ListObjectsV2Command,
PutObjectCommand,
Expand Down Expand Up @@ -71,9 +72,6 @@ export default class S3Handler extends RemoteHandlerAbstract {
}),
})

// Workaround for https://github.com/aws/aws-sdk-js-v3/issues/2673
this.#s3.middlewareStack.use(getApplyMd5BodyChecksumPlugin(this.#s3.config))

const parts = split(path)
this.#bucket = parts.shift()
this.#dir = join(...parts)
Expand Down Expand Up @@ -439,6 +437,24 @@ export default class S3Handler extends RemoteHandlerAbstract {

async _closeFile(fd) {}

async _sync() {
await super._sync()
try {
// if Object Lock is enabled, each upload must come with a contentMD5 header
// the computation of this md5 is memory-intensive, especially when uploading a stream
const res = await this.#s3.send(new GetObjectLockConfigurationCommand({ Bucket: this.#bucket }))
if (res.ObjectLockConfiguration?.ObjectLockEnabled === 'Enabled') {
// Workaround for https://github.com/aws/aws-sdk-js-v3/issues/2673
// will automatically add the contentMD5 header to any upload to S3
this.#s3.middlewareStack.use(getApplyMd5BodyChecksumPlugin(this.#s3.config))
}
} catch (error) {
if (error.Code !== 'ObjectLockConfigurationNotFoundError') {
throw error
}
}
}

useVhdDirectory() {
return true
}
Expand Down

0 comments on commit 5048485

Please sign in to comment.