@@ -3,12 +3,10 @@ const async = require('async');
33const constants = require ( '../../../../constants' ) ;
44const { data } = require ( '../../../data/wrapper' ) ;
55const locationConstraintCheck = require ( '../object/locationConstraintCheck' ) ;
6- const { standardMetadataValidateBucketAndObj } =
7- require ( '../../../metadata/metadataUtils' ) ;
6+ const metadataUtils = require ( '../../../metadata/metadataUtils' ) ;
87const { validateQuotas } = require ( '../quotas/quotaUtils' ) ;
98const services = require ( '../../../services' ) ;
109const metadata = require ( '../../../metadata/wrapper' ) ;
11- const { versioning } = require ( 'arsenal' ) ;
1210
1311function abortMultipartUpload ( authInfo , bucketName , objectKey , uploadId , log ,
1412 callback , request ) {
@@ -31,7 +29,8 @@ function abortMultipartUpload(authInfo, bucketName, objectKey, uploadId, log,
3129
3230 async . waterfall ( [
3331 function checkDestBucketVal ( next ) {
34- standardMetadataValidateBucketAndObj ( metadataValParams , authzIdentityResult , log ,
32+ // FIX: Call the function from the imported module object.
33+ metadataUtils . standardMetadataValidateBucketAndObj ( metadataValParams , authzIdentityResult , log ,
3534 ( err , destinationBucket , objectMD ) => {
3635 if ( err ) {
3736 log . error ( 'error validating request' , { error : err } ) ;
@@ -105,9 +104,13 @@ function abortMultipartUpload(authInfo, bucketName, objectKey, uploadId, log,
105104 // supported by Metadata.
106105 function ensureCleanupIsRequired ( mpuBucket , storedParts , destBucket ,
107106 objectMD , skipDataDelete , next ) {
107+ if ( ! objectMD ) {
108+ return next ( null , mpuBucket , storedParts , destBucket , null , skipDataDelete ) ;
109+ }
110+
108111 // If objectMD exists and has matching uploadId, use it directly
109112 // This handles all non-versioned cases, and some versioned cases.
110- if ( objectMD && objectMD . uploadId === uploadId ) {
113+ if ( objectMD . uploadId === uploadId ) {
111114 return next ( null , mpuBucket , storedParts , destBucket , objectMD , skipDataDelete ) ;
112115 }
113116
@@ -117,64 +120,21 @@ function abortMultipartUpload(authInfo, bucketName, objectKey, uploadId, log,
117120 return next ( null , mpuBucket , storedParts , destBucket , null , skipDataDelete ) ;
118121 }
119122
120- // Otherwise, we list all versions of the object. We try to stop as early
121- // as possible, by using pagination.
122- let keyMarker = null ;
123- let versionIdMarker = null ;
124- let foundVersion = null ;
125- let shouldContinue = true ;
126-
127- return async . whilst (
128- ( ) => shouldContinue && ! foundVersion ,
129- callback => {
130- const listParams = {
131- listingType : 'DelimiterVersions' ,
132- // To only list the specific key, we need to add the versionId separator
133- prefix : `${ objectKey } ${ versioning . VersioningConstants . VersionId . Separator } ` ,
134- maxKeys : 1000 ,
135- } ;
136-
137- if ( keyMarker ) {
138- listParams . keyMarker = keyMarker ;
139- }
140- if ( versionIdMarker ) {
141- listParams . versionIdMarker = versionIdMarker ;
142- }
143-
144- return services . getObjectListing ( bucketName , listParams , log , ( err , listResponse ) => {
145- if ( err ) {
146- log . error ( 'error listing object versions' , { error : err } ) ;
147- return callback ( err ) ;
148- }
149-
150- // Check each version in current batch for matching uploadId
151- const matchedVersion = ( listResponse . Versions || [ ] ) . find ( version =>
152- version . key === objectKey &&
153- version . value &&
154- version . value . uploadId === uploadId
155- ) ;
156-
157- if ( matchedVersion ) {
158- foundVersion = matchedVersion . value ;
159- }
160-
161- // Set up for next iteration if needed
162- if ( listResponse . IsTruncated && ! foundVersion ) {
163- keyMarker = listResponse . NextKeyMarker ;
164- versionIdMarker = listResponse . NextVersionIdMarker ;
165- } else {
166- shouldContinue = false ;
167- }
168-
169- return callback ( ) ;
123+ // Otherwise, list all versions to find one with a matching uploadId.
124+ return services . findObjectVersionByUploadId ( bucketName , objectKey , uploadId , log , ( err , foundVersion ) => {
125+ if ( err ) {
126+ log . error ( 'error finding object version by uploadId, proceeding without cleanup' , {
127+ error : err ,
128+ method : 'abortMultipartUpload.ensureCleanupIsRequired' ,
170129 } ) ;
171- } ,
172- err => next ( null , mpuBucket , storedParts , destBucket , err ? null : foundVersion , skipDataDelete )
173- ) ;
130+ // On error, continue the abort without an objectMD to clean up.
131+ return next ( null , mpuBucket , storedParts , destBucket , null , skipDataDelete ) ;
132+ }
133+ return next ( null , mpuBucket , storedParts , destBucket , foundVersion , skipDataDelete ) ;
134+ } ) ;
174135 } ,
175136 function deleteObjectMetadata ( mpuBucket , storedParts , destBucket , objMDWithMatchingUploadID ,
176137 skipDataDelete , next ) {
177- // If no objMDWithMatchingUploadID, nothing to delete
178138 if ( ! objMDWithMatchingUploadID ) {
179139 return next ( null , mpuBucket , storedParts , destBucket , objMDWithMatchingUploadID , skipDataDelete ) ;
180140 }
0 commit comments