fix(s3): include non-versioned objects in ListObjectVersions response (#359)

This commit is contained in:
Hector Ventura authored and GitHub committed 2026-04-11 21:26:12 -05:00
1 parent fddb1c7bfd
commit 5129897946
3 files changed
+77 -1

No files matched your search

@@ -949,7 +949,7 @@ public class S3Controller {
} else {
xml.start("Version")
.elem("Key", obj.getKey())
.elem("VersionId", obj.getVersionId())
.elem("VersionId", obj.getVersionId() != null ? obj.getVersionId() : "null")
.elem("IsLatest", obj.isLatest())
.elem("LastModified", ISO_FORMAT.format(obj.getLastModified()))
.elem("ETag", obj.getETag())
@@ -663,6 +663,15 @@ public class S3Service {
List<S3Object> versions = new ArrayList<>(objectStore.scan(key ->
key.startsWith(fullPrefix) && key.contains("#v#")));
// Also include non-versioned objects (no #v# in storage key, versionId == null).
// These are objects uploaded when versioning was disabled or before versioning was enabled.
// Versioned latest-pointer entries (also stored at the plain key) are excluded because
// they have a non-null versionId; their #v# entry is already captured above.
objectStore.scan(key -> key.startsWith(fullPrefix) && !key.contains("#v#"))
.stream()
.filter(obj -> obj.getVersionId() == null)
.forEach(versions::add);
// Sort by key, then by lastModified descending
versions.sort((a, b) -> {
int keyCompare = a.getKey().compareTo(b.getKey());