Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix directory listing with leading slash #1644

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ public DirectoryStream<Path> newDirectoryStream(Path dir, final Filter<? super P
final CloudStoragePath cloudPath = CloudStorageUtil.checkPath(dir);
checkNotNull(filter);
initStorage();
String prefix = cloudPath.toString();
String prefix = cloudPath.toRealPath().toString();
final Iterator<Blob> blobIterator = storage.list(cloudPath.bucket(),
Storage.BlobListOption.prefix(prefix), Storage.BlobListOption.currentDirectory(),
Storage.BlobListOption.fields()).iterateAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ public void testListFiles() throws IOException {
got.add(path);
}
assertThat(got).containsExactlyElementsIn(goodPaths);

// Must also work with relative path
got.clear();
for (Path path : Files.newDirectoryStream(fs.getPath("dir/"))) {
got.add(path);
}
assertThat(got).containsExactlyElementsIn(goodPaths);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,13 @@ public void testListFiles() throws IOException {
}

List<Path> got = new ArrayList<>();
for (Path path : Files.newDirectoryStream(fs.getPath("/dir/"))) {
got.add(path);
}
assertThat(got).containsExactlyElementsIn(goodPaths);

// Must also work with relative path
got.clear();
for (Path path : Files.newDirectoryStream(fs.getPath("dir/"))) {
got.add(path);
}
Expand Down