HADOOP-16685: FileSystem#listStatusIterator does not check if given path exists (#1695)
(cherry picked from commit 3161813482
)
This commit is contained in:
parent
298cda22a3
commit
c47d4d9c3f
|
@ -2103,24 +2103,19 @@ public abstract class FileSystem extends Configured
|
||||||
private DirectoryEntries entries;
|
private DirectoryEntries entries;
|
||||||
private int i = 0;
|
private int i = 0;
|
||||||
|
|
||||||
DirListingIterator(Path path) {
|
DirListingIterator(Path path) throws IOException {
|
||||||
this.path = path;
|
this.path = path;
|
||||||
|
this.entries = listStatusBatch(path, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasNext() throws IOException {
|
public boolean hasNext() throws IOException {
|
||||||
if (entries == null) {
|
|
||||||
fetchMore();
|
|
||||||
}
|
|
||||||
return i < entries.getEntries().length ||
|
return i < entries.getEntries().length ||
|
||||||
entries.hasMore();
|
entries.hasMore();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fetchMore() throws IOException {
|
private void fetchMore() throws IOException {
|
||||||
byte[] token = null;
|
byte[] token = entries.getToken();
|
||||||
if (entries != null) {
|
|
||||||
token = entries.getToken();
|
|
||||||
}
|
|
||||||
entries = listStatusBatch(path, token);
|
entries = listStatusBatch(path, token);
|
||||||
i = 0;
|
i = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -273,6 +273,14 @@ public abstract class AbstractContractGetFileStatusTest extends
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testListStatusIteratorNoDir() throws Throwable {
|
||||||
|
describe("test the listStatusIterator call on a path which is not " +
|
||||||
|
"present");
|
||||||
|
intercept(FileNotFoundException.class,
|
||||||
|
() -> getFileSystem().listStatusIterator(path("missing")));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLocatedStatusNoDir() throws Throwable {
|
public void testLocatedStatusNoDir() throws Throwable {
|
||||||
describe("test the LocatedStatus call on a path which is not present");
|
describe("test the LocatedStatus call on a path which is not present");
|
||||||
|
|
Loading…
Reference in New Issue