Skip to content

Commit

Permalink
More consistently use Path objects
Browse files Browse the repository at this point in the history
This improves compatibility on Windows.  References #740.
  • Loading branch information
gaul committed Dec 14, 2024
1 parent b523c44 commit 1e6763e
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ public final PageSet<? extends StorageMetadata> list(String container,
} else {
prefix = "";
}
prefix = "/" + container + "/" + prefix;
var pathPrefix = root.resolve(container).resolve(prefix);
var set = ImmutableSortedSet.<StorageMetadata>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;
Expand Down Expand Up @@ -217,7 +217,7 @@ public final PageSet<? extends StorageMetadata> list(String container,
}

private void listHelper(ImmutableSortedSet.Builder<StorageMetadata> 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
Expand All @@ -226,7 +226,7 @@ private void listHelper(ImmutableSortedSet.Builder<StorageMetadata> builder,
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)) {
Expand Down

0 comments on commit 1e6763e

Please sign in to comment.