* Finds a specific object version by its uploadId by listing and filtering all versions. * This is used during MPU abort to clean up potentially orphaned object metadata. * @param {string} bucketName - The name of the bucket. * @param {string} objectKey - The key of the object. *
(bucketName, objectKey, uploadId, log, cb)
| 429 | * @returns {undefined} |
| 430 | */ |
| 431 | findObjectVersionByUploadId(bucketName, objectKey, uploadId, log, cb) { |
| 432 | let keyMarker = null; |
| 433 | let versionIdMarker = null; |
| 434 | let foundVersion = null; |
| 435 | let shouldContinue = true; |
| 436 | |
| 437 | return async.whilst( |
| 438 | () => shouldContinue && !foundVersion, |
| 439 | callback => { |
| 440 | const listParams = { |
| 441 | listingType: 'DelimiterVersions', |
| 442 | // To only list the specific key, we need to add the versionId separator |
| 443 | prefix: `${objectKey}${versioning.VersioningConstants.VersionId.Separator}`, |
| 444 | maxKeys: 1000, |
| 445 | }; |
| 446 | |
| 447 | if (keyMarker) { |
| 448 | listParams.keyMarker = keyMarker; |
| 449 | } |
| 450 | if (versionIdMarker) { |
| 451 | listParams.versionIdMarker = versionIdMarker; |
| 452 | } |
| 453 | |
| 454 | return this.getObjectListing(bucketName, listParams, log, (err, listResponse) => { |
| 455 | if (err) { |
| 456 | log.error('error listing object versions', { error: err }); |
| 457 | return callback(err); |
| 458 | } |
| 459 | |
| 460 | // Check each version in current batch for matching uploadId |
| 461 | const matchedVersion = (listResponse.Versions || []).find(version => |
| 462 | version.key === objectKey && |
| 463 | version.value && |
| 464 | version.value.uploadId === uploadId |
| 465 | ); |
| 466 | |
| 467 | if (matchedVersion) { |
| 468 | foundVersion = matchedVersion.value; |
| 469 | } |
| 470 | |
| 471 | // Set up for next iteration if needed |
| 472 | if (listResponse.IsTruncated && !foundVersion) { |
| 473 | keyMarker = listResponse.NextKeyMarker; |
| 474 | versionIdMarker = listResponse.NextVersionIdMarker; |
| 475 | } else { |
| 476 | shouldContinue = false; |
| 477 | } |
| 478 | |
| 479 | return callback(); |
| 480 | }); |
| 481 | }, |
| 482 | err => cb(err, err ? null : foundVersion) |
| 483 | ); |
| 484 | }, |
| 485 | |
| 486 | /** |
| 487 | * Gets list of objects ready to be lifecycled |