diff --git a/src/main/java/org/gaul/s3proxy/nio2blob/AbstractNio2BlobStore.java b/src/main/java/org/gaul/s3proxy/nio2blob/AbstractNio2BlobStore.java index 0937b61..a29a172 100644 --- a/src/main/java/org/gaul/s3proxy/nio2blob/AbstractNio2BlobStore.java +++ b/src/main/java/org/gaul/s3proxy/nio2blob/AbstractNio2BlobStore.java @@ -179,10 +179,10 @@ public abstract class AbstractNio2BlobStore extends BaseBlobStore { } else { prefix = ""; } - prefix = "/" + container + "/" + prefix; + var pathPrefix = root.resolve(container).resolve(prefix); var set = ImmutableSortedSet.naturalOrder(); try { - listHelper(set, container, dirPrefix, prefix, delimiter); + listHelper(set, container, dirPrefix, pathPrefix, delimiter); var sorted = set.build(); if (options.getMarker() != null) { var found = false; @@ -217,7 +217,7 @@ public abstract class AbstractNio2BlobStore extends BaseBlobStore { } private void listHelper(ImmutableSortedSet.Builder builder, - String container, Path parent, String prefix, String delimiter) + String container, Path parent, Path prefix, String delimiter) throws IOException { logger.debug("recursing at: {} with prefix: {}", parent, prefix); if (!Files.isDirectory(parent)) { // TODO: TOCTOU @@ -226,7 +226,7 @@ public abstract class AbstractNio2BlobStore extends BaseBlobStore { try (var stream = Files.newDirectoryStream(parent)) { for (var path : stream) { logger.debug("examining: {}", path); - if (!path.toAbsolutePath().toString().startsWith(root + prefix)) { + if (!path.toAbsolutePath().toString().startsWith(root.resolve(prefix).toAbsolutePath().toString())) { // ignore } else if (Files.isDirectory(path)) { if (!"/".equals(delimiter)) {