From a30b1c62e0bba7ed1365ba13ad9559dfd1ec791c Mon Sep 17 00:00:00 2001 From: KillianG Date: Tue, 29 Oct 2024 10:27:57 +0100 Subject: [PATCH] Fix complete MPU with missing parts Issue: CLDSRV-570 --- lib/api/completeMultipartUpload.js | 60 +++++++++++++++--------------- 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/lib/api/completeMultipartUpload.js b/lib/api/completeMultipartUpload.js index 841e9839d1..09beb6135b 100644 --- a/lib/api/completeMultipartUpload.js +++ b/lib/api/completeMultipartUpload.js @@ -367,9 +367,9 @@ function completeMultipartUpload(authInfo, request, log, callback) { // if x-scal-s3-version-id header is specified, we overwrite the object/version metadata. if (isPutVersion) { const options = overwritingVersioning(objMD, metaStoreParams); - return process.nextTick(() => next(null, destBucket, dataLocations, + return process.nextTick(() => next(null, destBucket, extraPartLocations, dataLocations, metaStoreParams, mpuBucket, keysToDelete, aggregateETag, - objMD, extraPartLocations, pseudoCipherBundle, + objMD, pseudoCipherBundle, completeObjData, options)); } return versioningPreprocessing(bucketName, @@ -384,16 +384,32 @@ function completeMultipartUpload(authInfo, request, log, callback) { }); return next(err, destBucket); } - return next(null, destBucket, dataLocations, + return next(null, destBucket, extraPartLocations, dataLocations, metaStoreParams, mpuBucket, keysToDelete, aggregateETag, - objMD, extraPartLocations, pseudoCipherBundle, - completeObjData, options); + objMD, pseudoCipherBundle, completeObjData, options); }); }, + function batchDeleteExtraParts(destinationBucket, extraPartLocations, + dataLocations, metaStoreParams, mpuBucket, keysToDelete, + aggregateETag, objMD, pseudoCipherBundle, completeObjData, options, next) { + if (extraPartLocations && extraPartLocations.length > 0) { + return data.batchDelete(extraPartLocations, request.method, null, log, + err => { + if (err) { + return next(err); + } + return next(null, destinationBucket, + dataLocations, metaStoreParams, mpuBucket, keysToDelete, + aggregateETag, objMD, pseudoCipherBundle, completeObjData, options); + }); + } + return next(null, destinationBucket, dataLocations, metaStoreParams, + mpuBucket, keysToDelete, aggregateETag, objMD, pseudoCipherBundle, + completeObjData, options); + }, function storeAsNewObj(destinationBucket, dataLocations, metaStoreParams, mpuBucket, keysToDelete, aggregateETag, objMD, - extraPartLocations, pseudoCipherBundle, - completeObjData, options, next) { + pseudoCipherBundle, completeObjData, options, next) { const dataToDelete = options.dataToDelete; /* eslint-disable no-param-reassign */ metaStoreParams.versionId = options.versionId; @@ -442,10 +458,9 @@ function completeMultipartUpload(authInfo, request, log, callback) { objectKey: metaStoreParams.objectKey, uploadId: metaStoreParams.uploadId, }); + // pass the original version ID as generatedVersionId return next(null, mpuBucket, keysToDelete, aggregateETag, - extraPartLocations, destinationBucket, - // pass the original version ID as generatedVersionId - objMD.versionId); + destinationBucket, objMD.versionId); } } return services.metadataStoreObject(destinationBucket.getName(), @@ -481,36 +496,19 @@ function completeMultipartUpload(authInfo, request, log, callback) { return next(err); } return next(null, mpuBucket, keysToDelete, - aggregateETag, extraPartLocations, - destinationBucket, generatedVersionId); + aggregateETag, destinationBucket, generatedVersionId); }); } return next(null, mpuBucket, keysToDelete, aggregateETag, - extraPartLocations, destinationBucket, - generatedVersionId); + destinationBucket, generatedVersionId); }); }, function deletePartsMetadata(mpuBucket, keysToDelete, aggregateETag, - extraPartLocations, destinationBucket, generatedVersionId, next) { + destinationBucket, generatedVersionId, next) { services.batchDeleteObjectMetadata(mpuBucket.getName(), - keysToDelete, log, err => next(err, extraPartLocations, + keysToDelete, log, err => next(err, destinationBucket, aggregateETag, generatedVersionId)); }, - function batchDeleteExtraParts(extraPartLocations, destinationBucket, - aggregateETag, generatedVersionId, next) { - if (extraPartLocations && extraPartLocations.length > 0) { - return data.batchDelete(extraPartLocations, request.method, - null, log, err => { - if (err) { - return next(err); - } - return next(null, destinationBucket, aggregateETag, - generatedVersionId); - }); - } - return next(null, destinationBucket, aggregateETag, - generatedVersionId); - }, ], (err, destinationBucket, aggregateETag, generatedVersionId) => { const corsHeaders = collectCorsHeaders(request.headers.origin, request.method,