Skip to content

Commit

Permalink
impr(S3UTILS-146): Use safeListObjectVersions in cleanupNoncurrentVer…
Browse files Browse the repository at this point in the history
…sions
  • Loading branch information
tmacro committed Oct 30, 2023
1 parent f5891a2 commit 462e90b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions cleanupNoncurrentVersions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const { doWhilst, eachSeries } = require('async');
const { Logger } = require('werelogs');

const parseOlderThan = require('./utils/parseOlderThan');
const { safeListObjectVersions } = require('./utils/safeList');

const log = new Logger('s3utils::cleanupNoncurrentVersions');

Expand Down Expand Up @@ -231,7 +232,7 @@ const logProgressInterval = setInterval(
);

function _listObjectVersions(bucket, VersionIdMarker, KeyMarker, cb) {
return s3.listObjectVersions({
return safeListObjectVersions(s3, {
Bucket: bucket,
MaxKeys: LISTING_LIMIT,
Prefix: TARGET_PREFIX,
Expand All @@ -241,11 +242,19 @@ function _listObjectVersions(bucket, VersionIdMarker, KeyMarker, cb) {
}

function _lastModifiedIsEligible(lastModifiedString) {
return !OLDER_THAN || (new Date(lastModifiedString) < OLDER_THAN);
const ts = new Date(lastModifiedString);
if (Number.isNaN(ts.getTime())) {
return false;
}
return !OLDER_THAN || (ts < OLDER_THAN);
}

function _deleteMarkerIsEligible(lastModifiedString) {
return !DELETED_BEFORE || (new Date(lastModifiedString) < DELETED_BEFORE);
const ts = new Date(lastModifiedString);
if (Number.isNaN(ts.getTime())) {
return false;
}
return !DELETED_BEFORE || (ts < DELETED_BEFORE);
}

let deleteQueue = [];
Expand Down

0 comments on commit 462e90b

Please sign in to comment.