diff --git a/cleanupNoncurrentVersions.js b/cleanupNoncurrentVersions.js index b22c5b72..eee83c6d 100644 --- a/cleanupNoncurrentVersions.js +++ b/cleanupNoncurrentVersions.js @@ -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'); @@ -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, @@ -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 = [];