diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 2cc443f19a2..ce17de4ec89 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -966,6 +966,9 @@ Release 0.23.3 - UNRELEASED HADOOP-8225. DistCp fails when invoked by Oozie (daryn via bobby) + HADOOP-8709. globStatus changed behavior from 0.20/1.x (Jason Lowe via + bobby) + Release 0.23.2 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileContext.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileContext.java index e7591c710de..4e5057a4e9b 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileContext.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileContext.java @@ -2014,7 +2014,11 @@ private FileStatus[] globStatusInternal(final URI uri, new GlobFilter(components[components.length - 1], filter); if (fp.hasPattern()) { // last component has a pattern // list parent directories and then glob the results - results = listStatus(parentPaths, fp); + try { + results = listStatus(parentPaths, fp); + } catch (FileNotFoundException e) { + results = null; + } hasGlob[0] = true; } else { // last component does not have a pattern // get all the path names @@ -2065,7 +2069,11 @@ private Path[] globPathsLevel(Path[] parents, String[] filePattern, } GlobFilter fp = new GlobFilter(filePattern[level]); if (fp.hasPattern()) { - parents = FileUtil.stat2Paths(listStatus(parents, fp)); + try { + parents = FileUtil.stat2Paths(listStatus(parents, fp)); + } catch (FileNotFoundException e) { + parents = null; + } hasGlob[0] = true; } else { for (int i = 0; i < parents.length; i++) { diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java index dd848ada5ff..31b59439a96 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java @@ -1619,7 +1619,11 @@ private FileStatus[] globStatusInternal(Path pathPattern, PathFilter filter) GlobFilter fp = new GlobFilter(components[components.length - 1], filter); if (fp.hasPattern()) { // last component has a pattern // list parent directories and then glob the results - results = listStatus(parentPaths, fp); + try { + results = listStatus(parentPaths, fp); + } catch (FileNotFoundException e) { + results = null; + } hasGlob[0] = true; } else { // last component does not have a pattern // remove the quoting of metachars in a non-regexp expansion @@ -1668,7 +1672,11 @@ private Path[] globPathsLevel(Path[] parents, String[] filePattern, } GlobFilter fp = new GlobFilter(filePattern[level]); if (fp.hasPattern()) { - parents = FileUtil.stat2Paths(listStatus(parents, fp)); + try { + parents = FileUtil.stat2Paths(listStatus(parents, fp)); + } catch (FileNotFoundException e) { + parents = null; + } hasGlob[0] = true; } else { // the component does not have a pattern // remove the quoting of metachars in a non-regexp expansion diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FSMainOperationsBaseTest.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FSMainOperationsBaseTest.java index f51884627e4..6c501009012 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FSMainOperationsBaseTest.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FSMainOperationsBaseTest.java @@ -364,15 +364,17 @@ public void testListStatusFilterWithSomeMatches() throws Exception { } @Test - public void testGlobStatusThrowsExceptionForNonExistentFile() throws Exception { - try { - // This should throw a FileNotFoundException - fSys.globStatus( - getTestRootPath(fSys, "test/hadoopfsdf/?")); - Assert.fail("Should throw FileNotFoundException"); - } catch (FileNotFoundException fnfe) { - // expected - } + public void testGlobStatusNonExistentFile() throws Exception { + FileStatus[] paths = fSys.globStatus( + getTestRootPath(fSys, "test/hadoopfsdf")); + Assert.assertNull(paths); + + paths = fSys.globStatus( + getTestRootPath(fSys, "test/hadoopfsdf/?")); + Assert.assertEquals(0, paths.length); + paths = fSys.globStatus( + getTestRootPath(fSys, "test/hadoopfsdf/xyz*/?")); + Assert.assertEquals(0, paths.length); } @Test 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 373cebd9be7..150b68e35d7 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 @@ -360,15 +360,17 @@ public void testListStatusFilterWithSomeMatches() throws Exception { } @Test - public void testGlobStatusThrowsExceptionForNonExistentFile() throws Exception { - try { - // This should throw a FileNotFoundException - fc.util().globStatus( - getTestRootPath(fc, "test/hadoopfsdf/?")); - Assert.fail("Should throw FileNotFoundException"); - } catch (FileNotFoundException fnfe) { - // expected - } + public void testGlobStatusNonExistentFile() throws Exception { + FileStatus[] paths = fc.util().globStatus( + getTestRootPath(fc, "test/hadoopfsdf")); + Assert.assertNull(paths); + + paths = fc.util().globStatus( + getTestRootPath(fc, "test/hadoopfsdf/?")); + Assert.assertEquals(0, paths.length); + paths = fc.util().globStatus( + getTestRootPath(fc, "test/hadoopfsdf/xyz*/?")); + Assert.assertEquals(0, paths.length); } @Test