Skip to content

Commit

Permalink
Fix directory listing with leading slash (#1644)
Browse files Browse the repository at this point in the history
newDirectoryStream("dir1/") and newDirectoryStream("/dir1/") should
return the
same result. Added a test to show they didn't, then fixed it
so the test passes.
  • Loading branch information
jean-philippe-martin authored and garrettjonesgoogle committed Feb 22, 2017
1 parent 235874d commit 0fb03eb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
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

0 comments on commit 0fb03eb

Please sign in to comment.