@@ -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