Forráskód Böngészése

HADOOP-2732. Fix bug in path globbing. Contributed by Hairong Kuang.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/trunk@616660 13f79535-47bb-0310-9956-ffa450edef68
Nigel Daley 17 éve
szülő
commit
8b69a487d7

+ 2 - 0
CHANGES.txt

@@ -611,6 +611,8 @@ Trunk (unreleased changes)
 
     HADOOP-2641. Added Apache license headers to 95 files. (nigel)
 
+    HADOOP-2732. Fix bug in path globbing.  (Hairong Kuang via nigel)
+
 Release 0.15.3 - 2008-01-18
 
   BUG FIXES

+ 0 - 7
src/java/org/apache/hadoop/fs/FileSystem.java

@@ -888,7 +888,6 @@ public abstract class FileSystem extends Configured {
       int setOpen;
       int curlyOpen;
       boolean setRange;
-      boolean expectGroup;
 
       StringBuilder fileRegex = new StringBuilder();
 
@@ -900,7 +899,6 @@ public abstract class FileSystem extends Configured {
       setOpen = 0;
       setRange = false;
       curlyOpen = 0;
-      expectGroup = false;
 
       for (int i = 0; i < len; i++) {
         char pCh;
@@ -929,11 +927,8 @@ public abstract class FileSystem extends Configured {
         } else if (pCh == ',' && curlyOpen > 0) {
           fileRegex.append(")|");
           pCh = '(';
-          expectGroup = true;
         } else if (pCh == '}' && curlyOpen > 0) {
           // End of a group
-          if (expectGroup)
-            error("Unexpected end of a group", filePattern, i);
           curlyOpen--;
           fileRegex.append(")");
           pCh = ')';
@@ -956,8 +951,6 @@ public abstract class FileSystem extends Configured {
           // Normal character, or the end of a character set range
           setOpen++;
           setRange = false;
-        } else if (curlyOpen > 0) {
-          expectGroup = false;
         }
         fileRegex.append(pCh);
       }

+ 23 - 9
src/test/org/apache/hadoop/fs/TestGlobPaths.java

@@ -268,7 +268,7 @@ public class TestGlobPaths extends TestCase {
     }
     try {
       // test standalone }
-      files = new String[] {USER_DIR+"/}bc"};
+      files = new String[] {USER_DIR+"/}bc", USER_DIR+"/}c"};
       matchedPath = prepareTesting(USER_DIR+"/}{a,b}c", files);
       assertEquals(matchedPath.length, 1);
       assertEquals(matchedPath[0], path[0]);
@@ -281,16 +281,30 @@ public class TestGlobPaths extends TestCase {
       assertEquals(matchedPath.length, 1);
       assertEquals(matchedPath[0], path[0]);
 
+      // test {,}
+      matchedPath = prepareTesting(USER_DIR+"/}{,}bc", files);
+      assertEquals(matchedPath.length, 1);
+      assertEquals(matchedPath[0], path[0]);
+
+      // test {b,}
+      matchedPath = prepareTesting(USER_DIR+"/}{b,}c", files);
+      assertEquals(matchedPath.length, 2);
+      assertEquals(matchedPath[0], path[0]);
+      assertEquals(matchedPath[1], path[1]);
+
+      // test {,b}
+      matchedPath = prepareTesting(USER_DIR+"/}{,b}c", files);
+      assertEquals(matchedPath.length, 2);
+      assertEquals(matchedPath[0], path[0]);
+      assertEquals(matchedPath[1], path[1]);
+
+      // test a combination of {} and ?
+      matchedPath = prepareTesting(USER_DIR+"/}{ac,?}", files);
+      assertEquals(matchedPath.length, 1);
+      assertEquals(matchedPath[0], path[1]);
+      
       // test ill-formed curly
       boolean hasException = false;
-      try {
-        prepareTesting(USER_DIR+"}{b,}c", files);
-      } catch (IOException e) {
-        assertTrue(e.getMessage().startsWith("Illegal file pattern:") );
-        hasException = true;
-      }
-      assertTrue(hasException);
-      hasException = false;
       try {
         prepareTesting(USER_DIR+"}{bc", files);
       } catch (IOException e) {