hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dhr...@apache.org
Subject svn commit: r594270 - in /lucene/hadoop/trunk: CHANGES.txt src/java/org/apache/hadoop/fs/FileSystem.java src/test/org/apache/hadoop/fs/TestGlobPaths.java
Date Mon, 12 Nov 2007 19:41:35 GMT
Author: dhruba
Date: Mon Nov 12 11:41:34 2007
New Revision: 594270

URL: http://svn.apache.org/viewvc?rev=594270&view=rev
Log:
HADOOP-2151. FileSystem.globPaths validates the list of Paths that
it returns.  (Lohit Vijayarenu via dhruba)


Modified:
    lucene/hadoop/trunk/CHANGES.txt
    lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/FileSystem.java
    lucene/hadoop/trunk/src/test/org/apache/hadoop/fs/TestGlobPaths.java

Modified: lucene/hadoop/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/CHANGES.txt?rev=594270&r1=594269&r2=594270&view=diff
==============================================================================
--- lucene/hadoop/trunk/CHANGES.txt (original)
+++ lucene/hadoop/trunk/CHANGES.txt Mon Nov 12 11:41:34 2007
@@ -88,6 +88,9 @@
     Now invalid options are caught, logged and jobs are failed early. (Lohit
     Vijayarenu via acmurthy)
 
+    HADOOP-2151. FileSyste.globPaths validates the list of Paths that
+    it returns.  (Lohit Vijayarenu via dhruba)
+
 Release 0.15.1 -
 
   BUG FIXES

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/FileSystem.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/FileSystem.java?rev=594270&r1=594269&r2=594270&view=diff
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/FileSystem.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/FileSystem.java Mon Nov 12 11:41:34
2007
@@ -616,24 +616,34 @@
       parents[0] = new Path(Path.CUR_DIR);
     }
       
-    Path[] results = globPathsLevel(parents, components, level, filter);
+    Path[] results = globPathsLevel(parents, components, level, filter, false);
     Arrays.sort(results);
     return results;
   }
     
-  private Path[] globPathsLevel(Path[] parents,
-                                String [] filePattern, int level, PathFilter filter) throws
IOException {
+  private Path[] globPathsLevel(Path[] parents, String [] filePattern, 
+            int level, PathFilter filter, boolean hasGlob) throws IOException {
     if (level == filePattern.length)
       return parents;
     GlobFilter fp = new GlobFilter(filePattern[level], filter);
     if (fp.hasPattern()) {
       parents = listPaths(parents, fp);
+       hasGlob = true;
     } else {
+      int goodPathCount = 0;
       for(int i=0; i<parents.length; i++) {
-        parents[i] = new Path(parents[i], filePattern[level]);
+        Path tmpPath = new Path(parents[i], filePattern[level]);
+        if (!hasGlob || exists(tmpPath)) {
+          parents[goodPathCount++] = tmpPath;
+        }
+      }
+      if (goodPathCount != parents.length) {
+        Path [] goodParents = new Path[goodPathCount];
+        System.arraycopy(parents, 0, goodParents, 0, goodPathCount);
+        parents = goodParents;
       }
     }
-    return globPathsLevel(parents, filePattern, level+1, filter);      
+    return globPathsLevel(parents, filePattern, level+1, filter, hasGlob);
   }
  
   private static class GlobFilter implements PathFilter {

Modified: lucene/hadoop/trunk/src/test/org/apache/hadoop/fs/TestGlobPaths.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/test/org/apache/hadoop/fs/TestGlobPaths.java?rev=594270&r1=594269&r2=594270&view=diff
==============================================================================
--- lucene/hadoop/trunk/src/test/org/apache/hadoop/fs/TestGlobPaths.java (original)
+++ lucene/hadoop/trunk/src/test/org/apache/hadoop/fs/TestGlobPaths.java Mon Nov 12 11:41:34
2007
@@ -102,6 +102,8 @@
     pTestClosure1();
     pTestClosure2();
     pTestClosure3();
+    pTestClosure4();
+    pTestClosure5();
   }
   
   private void pTestClosure1() throws IOException {
@@ -145,7 +147,33 @@
       cleanupDFS();
     } 
   }
+
+  private void pTestClosure4() throws IOException {
+    try {
+      String [] files = new String[] {USER_DIR+"/dir1/file1", 
+                                      USER_DIR+"/dir2/file2", 
+                                       USER_DIR+"/dir3/file1"};
+      Path[] matchedPath = prepareTesting(USER_DIR+"/*/file1", files);
+      assertEquals(matchedPath.length, 2);
+      assertEquals(matchedPath[0], path[0]);
+      assertEquals(matchedPath[1], path[2]);
+    } finally {
+      cleanupDFS();
+    }
+  }
   
+  private void pTestClosure5() throws IOException {
+    try {
+      String [] files = new String[] {USER_DIR+"/dir1/file1", 
+                                      USER_DIR+"/file1"};
+      Path[] matchedPath = prepareTesting(USER_DIR+"/*/file1", files);
+      assertEquals(matchedPath.length, 1);
+      assertEquals(matchedPath[0], path[0]);
+    } finally {
+      cleanupDFS();
+    }
+  }
+
   private void pTestSet() throws IOException {
     try {    
       String [] files = new String[] {USER_DIR+"/a.c", USER_DIR+"/a.cpp",



Mime
View raw message