Skip to content

Commit 23ac77e

Browse files
jean-philippe-martinneozwu
authored andcommitted
---
yaml --- r: 5749 b: refs/heads/master c: 466a8d4 h: refs/heads/master i: 5747: b2c30be
1 parent eccf713 commit 23ac77e

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 7c20c6f0663147ed667d782c1e37551d80fc74e7
2+
refs/heads/master: 466a8d4f70aab42596007f4a3fb07b791f363509
33
refs/heads/travis: dae77e558b884bc1b165155482d76c8e40b0fca4
44
refs/heads/gh-pages: 3c5e576ef43acaafb4d9c2c093fad59827a77ffa
55
refs/tags/0.0.9: 22f1839238f66c39e67ed4dfdcd273b1ae2e8444

trunk/google-cloud-contrib/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystemProvider.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,13 @@ private static class LazyPathIterator extends AbstractIterator<Path> {
9797
private final Iterator<Blob> blobIterator;
9898
private final Filter<? super Path> filter;
9999
private final CloudStorageFileSystem fileSystem;
100+
private final String prefix;
100101

101-
LazyPathIterator(CloudStorageFileSystem fileSystem, Iterator<Blob> blobIterator,
102+
LazyPathIterator(CloudStorageFileSystem fileSystem,
103+
String prefix,
104+
Iterator<Blob> blobIterator,
102105
Filter<? super Path> filter) {
106+
this.prefix = prefix;
103107
this.blobIterator = blobIterator;
104108
this.filter = filter;
105109
this.fileSystem = fileSystem;
@@ -110,6 +114,10 @@ protected Path computeNext() {
110114
while (blobIterator.hasNext()) {
111115
Path path = fileSystem.getPath(blobIterator.next().getName());
112116
try {
117+
if (path.toString().equals(prefix)) {
118+
// do not return ourselves, because that confuses recursive descents.
119+
continue;
120+
}
113121
if (filter.accept(path)) {
114122
return path;
115123
}
@@ -617,14 +625,14 @@ public DirectoryStream<Path> newDirectoryStream(Path dir, final Filter<? super P
617625
final CloudStoragePath cloudPath = CloudStorageUtil.checkPath(dir);
618626
checkNotNull(filter);
619627
initStorage();
620-
String prefix = cloudPath.toRealPath().toString();
628+
final String prefix = cloudPath.toRealPath().toString();
621629
final Iterator<Blob> blobIterator = storage.list(cloudPath.bucket(),
622630
Storage.BlobListOption.prefix(prefix), Storage.BlobListOption.currentDirectory(),
623631
Storage.BlobListOption.fields()).iterateAll().iterator();
624632
return new DirectoryStream<Path>() {
625633
@Override
626634
public Iterator<Path> iterator() {
627-
return new LazyPathIterator(cloudPath.getFileSystem(), blobIterator, filter);
635+
return new LazyPathIterator(cloudPath.getFileSystem(), prefix, blobIterator, filter);
628636
}
629637

630638
@Override

0 commit comments

Comments
 (0)