Skip to content
This repository was archived by the owner on Jul 25, 2026. It is now read-only.

Commit 1e185ab

Browse files
authored
Fix S3 listSubDirectories pagination marker handling
1 parent 3e9c40f commit 1e185ab

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

  • packages/oc-s3-storage-adapter/src

packages/oc-s3-storage-adapter/src/index.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ export default function s3Adapter(conf: S3Config): StorageAdapter {
188188
const prefixes: string[] = [];
189189
let marker: string | undefined;
190190

191-
do {
191+
while (true) {
192192
const data = await getClient().listObjects({
193193
Bucket: bucket,
194194
Prefix: normalisedPath,
@@ -202,10 +202,21 @@ export default function s3Adapter(conf: S3Config): StorageAdapter {
202202
}
203203
}
204204

205-
// S3 returns NextMarker when a Delimiter is set and the list is truncated.
206-
// Guard against an infinite loop if S3 ever omits it while truncated.
207-
marker = data.IsTruncated && data.NextMarker ? data.NextMarker : undefined;
208-
} while (marker);
205+
if (!data.IsTruncated) {
206+
break;
207+
}
208+
209+
const nextMarker =
210+
data.NextMarker ??
211+
data.Contents?.[data.Contents.length - 1]?.Key ??
212+
data.CommonPrefixes?.[data.CommonPrefixes.length - 1]?.Prefix;
213+
214+
if (!nextMarker || nextMarker === marker) {
215+
throw new Error('S3 listObjects returned no (or unchanged) pagination marker while truncated');
216+
}
217+
218+
marker = nextMarker;
219+
}
209220

210221
if (prefixes.length === 0) {
211222
throw {

0 commit comments

Comments
 (0)