Skip to content

Commit

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

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

const log = new Logger('s3utils::bucketVersionsStats');
const { ENDPOINT } = process.env;
Expand Down Expand Up @@ -166,7 +167,7 @@ const logProgressInterval = setInterval(
);

function _listObjectVersions(bucket, KeyMarker, VersionIdMarker, cb) {
return s3.listObjectVersions({
return safeListObjectVersions(s3, {
Bucket: bucket,
MaxKeys: LISTING_LIMIT,
Prefix: TARGET_PREFIX,
Expand All @@ -191,8 +192,11 @@ function listBucket(bucket, cb) {
return done(err);
}
for (const version of data.Versions) {
if (_OLDER_THAN_TIMESTAMP && new Date(version.LastModified) > _OLDER_THAN_TIMESTAMP) {
continue;
if (_OLDER_THAN_TIMESTAMP) {
const parsed = new Date(version.LastModified);
if (Number.isNaN(parsed.getTime()) || parsed > _OLDER_THAN_TIMESTAMP) {
continue;
}
}
const statObj = version.IsLatest ? stats.current : stats.noncurrent;
statObj.count += 1;
Expand Down

0 comments on commit 10e3739

Please sign in to comment.