@@ -3,12 +3,10 @@ const async = require('async');
3
3
const constants = require ( '../../../../constants' ) ;
4
4
const { data } = require ( '../../../data/wrapper' ) ;
5
5
const locationConstraintCheck = require ( '../object/locationConstraintCheck' ) ;
6
- const { standardMetadataValidateBucketAndObj } =
7
- require ( '../../../metadata/metadataUtils' ) ;
6
+ const metadataUtils = require ( '../../../metadata/metadataUtils' ) ;
8
7
const { validateQuotas } = require ( '../quotas/quotaUtils' ) ;
9
8
const services = require ( '../../../services' ) ;
10
9
const metadata = require ( '../../../metadata/wrapper' ) ;
11
- const { versioning } = require ( 'arsenal' ) ;
12
10
13
11
function abortMultipartUpload ( authInfo , bucketName , objectKey , uploadId , log ,
14
12
callback , request ) {
@@ -31,7 +29,8 @@ function abortMultipartUpload(authInfo, bucketName, objectKey, uploadId, log,
31
29
32
30
async . waterfall ( [
33
31
function checkDestBucketVal ( next ) {
34
- standardMetadataValidateBucketAndObj ( metadataValParams , authzIdentityResult , log ,
32
+ // FIX: Call the function from the imported module object.
33
+ metadataUtils . standardMetadataValidateBucketAndObj ( metadataValParams , authzIdentityResult , log ,
35
34
( err , destinationBucket , objectMD ) => {
36
35
if ( err ) {
37
36
log . error ( 'error validating request' , { error : err } ) ;
@@ -105,9 +104,13 @@ function abortMultipartUpload(authInfo, bucketName, objectKey, uploadId, log,
105
104
// supported by Metadata.
106
105
function ensureCleanupIsRequired ( mpuBucket , storedParts , destBucket ,
107
106
objectMD , skipDataDelete , next ) {
107
+ if ( ! objectMD ) {
108
+ return next ( null , mpuBucket , storedParts , destBucket , null , skipDataDelete ) ;
109
+ }
110
+
108
111
// If objectMD exists and has matching uploadId, use it directly
109
112
// This handles all non-versioned cases, and some versioned cases.
110
- if ( objectMD && objectMD . uploadId === uploadId ) {
113
+ if ( objectMD . uploadId === uploadId ) {
111
114
return next ( null , mpuBucket , storedParts , destBucket , objectMD , skipDataDelete ) ;
112
115
}
113
116
@@ -117,64 +120,21 @@ function abortMultipartUpload(authInfo, bucketName, objectKey, uploadId, log,
117
120
return next ( null , mpuBucket , storedParts , destBucket , null , skipDataDelete ) ;
118
121
}
119
122
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' ,
170
129
} ) ;
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
+ } ) ;
174
135
} ,
175
136
function deleteObjectMetadata ( mpuBucket , storedParts , destBucket , objMDWithMatchingUploadID ,
176
137
skipDataDelete , next ) {
177
- // If no objMDWithMatchingUploadID, nothing to delete
178
138
if ( ! objMDWithMatchingUploadID ) {
179
139
return next ( null , mpuBucket , storedParts , destBucket , objMDWithMatchingUploadID , skipDataDelete ) ;
180
140
}
0 commit comments