Repository: hadoop Updated Branches: refs/heads/branch-2.8 4b1ee3685 -> 72d908acd
HADOOP-15637. LocalFs#listLocatedStatus does not filter out hidden .crc files. Contributed by Erik Krogen. Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/72d908ac Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/72d908ac Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/72d908ac Branch: refs/heads/branch-2.8 Commit: 72d908acdb112722fc1f3fea773e71838982e196 Parents: 4b1ee36 Author: Chen Liang <[email protected]> Authored: Mon Jul 30 10:44:22 2018 -0700 Committer: Chen Liang <[email protected]> Committed: Mon Jul 30 10:44:22 2018 -0700 ---------------------------------------------------------------------- .../java/org/apache/hadoop/fs/ChecksumFs.java | 37 +++++++++++++++++++ .../fs/FileContextMainOperationsBaseTest.java | 38 ++++++++++++++++++++ 2 files changed, 75 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/72d908ac/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ChecksumFs.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ChecksumFs.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ChecksumFs.java index 384b32c..5c54554 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ChecksumFs.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ChecksumFs.java @@ -26,6 +26,7 @@ import java.nio.channels.ClosedChannelException; import java.util.ArrayList; import java.util.Arrays; import java.util.EnumSet; +import java.util.NoSuchElementException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -33,6 +34,7 @@ import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.fs.Options.ChecksumOpt; import org.apache.hadoop.fs.permission.FsPermission; +import org.apache.hadoop.security.AccessControlException; import org.apache.hadoop.util.DataChecksum; import org.apache.hadoop.util.Progressable; @@ -526,4 +528,39 @@ public abstract class ChecksumFs extends FilterFs { } return results.toArray(new FileStatus[results.size()]); } + + @Override + public RemoteIterator<LocatedFileStatus> listLocatedStatus(final Path f) + throws AccessControlException, FileNotFoundException, + UnresolvedLinkException, IOException { + final RemoteIterator<LocatedFileStatus> iter = + getMyFs().listLocatedStatus(f); + return new RemoteIterator<LocatedFileStatus>() { + + private LocatedFileStatus next = null; + + @Override + public boolean hasNext() throws IOException { + while (next == null && iter.hasNext()) { + LocatedFileStatus unfilteredNext = iter.next(); + if (!isChecksumFile(unfilteredNext.getPath())) { + next = unfilteredNext; + } + } + return next != null; + } + + @Override + public LocatedFileStatus next() throws IOException { + if (!hasNext()) { + throw new NoSuchElementException(); + } + LocatedFileStatus tmp = next; + next = null; + return tmp; + } + + }; + } + } http://git-wip-us.apache.org/repos/asf/hadoop/blob/72d908ac/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FileContextMainOperationsBaseTest.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FileContextMainOperationsBaseTest.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FileContextMainOperationsBaseTest.java index c835076..ab93333 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FileContextMainOperationsBaseTest.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FileContextMainOperationsBaseTest.java @@ -368,6 +368,44 @@ public abstract class FileContextMainOperationsBaseTest { pathsIterator = fc.listStatus(getTestRootPath(fc, "test/hadoop/a")); Assert.assertFalse(pathsIterator.hasNext()); } + + @Test + public void testListFiles() throws Exception { + Path[] testDirs = { + getTestRootPath(fc, "test/dir1"), + getTestRootPath(fc, "test/dir1/dir1"), + getTestRootPath(fc, "test/dir2") + }; + Path[] testFiles = { + new Path(testDirs[0], "file1"), + new Path(testDirs[0], "file2"), + new Path(testDirs[1], "file2"), + new Path(testDirs[2], "file1") + }; + + for (Path path : testDirs) { + fc.mkdir(path, FsPermission.getDefault(), true); + } + for (Path p : testFiles) { + FSDataOutputStream out = fc.create(p).build(); + out.writeByte(0); + out.close(); + } + + RemoteIterator<LocatedFileStatus> filesIterator = + fc.util().listFiles(getTestRootPath(fc, "test"), true); + LocatedFileStatus[] fileStats = + new LocatedFileStatus[testFiles.length]; + for (int i = 0; i < fileStats.length; i++) { + assertTrue(filesIterator.hasNext()); + fileStats[i] = filesIterator.next(); + } + assertFalse(filesIterator.hasNext()); + + for (Path p : testFiles) { + assertTrue(containsPath(p, fileStats)); + } + } @Test public void testListStatusFilterWithNoMatches() throws Exception { --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
