Browse Source

HADOOP-2938. A few fs commands did not glob paths. (Tsz Wo (Nicholas), SZE via dhruba)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/trunk@634500 13f79535-47bb-0310-9956-ffa450edef68
Raghu Angadi 17 years ago
parent
commit
51c2eb37ac

+ 3 - 0
CHANGES.txt

@@ -149,6 +149,9 @@ Trunk (unreleased changes)
     HADOOP-2934. The namenode was encountreing a NPE while loading
     leases from the fsimage. Fixed. (dhruba)
 
+    HADOOP-2938. Some fs commands did not glob paths.
+    (Tsz Wo (Nicholas), SZE via rangadi)
+    
 Release 0.16.1 - Unreleased
 
   INCOMPATIBLE CHANGES

+ 4 - 4
src/java/org/apache/hadoop/fs/FsShell.java

@@ -339,7 +339,7 @@ public class FsShell extends Configured implements Tool {
         }
         printToStdout(srcFs.open(p));
       }
-    }.process(srcPattern, getSrcFileSystem(srcPattern, verifyChecksum));
+    }.globAndProcess(srcPattern, getSrcFileSystem(srcPattern, verifyChecksum));
   }
 
   private class TextRecordInputStream extends InputStream {
@@ -407,7 +407,7 @@ public class FsShell extends Configured implements Tool {
         }
         printToStdout(forMagic(p, srcFs));
       }
-    }.process(srcPattern, srcPattern.getFileSystem(getConf()));
+    }.globAndProcess(srcPattern, srcPattern.getFileSystem(getConf()));
   }
 
   /**
@@ -1033,7 +1033,7 @@ public class FsShell extends Configured implements Tool {
       void process(Path p, FileSystem srcFs) throws IOException {
         delete(p, srcFs, recursive);
       }
-    }.process(srcPattern, srcPattern.getFileSystem(getConf()));
+    }.globAndProcess(srcPattern, srcPattern.getFileSystem(getConf()));
   }
     
   /* delete a file */
@@ -1843,7 +1843,7 @@ public class FsShell extends Configured implements Tool {
   private abstract class DelayedExceptionThrowing {
     abstract void process(Path p, FileSystem srcFs) throws IOException;
 
-    final void processSrc(Path srcPattern, FileSystem srcFs
+    final void globAndProcess(Path srcPattern, FileSystem srcFs
         ) throws IOException {
       List<IOException> exceptions = new ArrayList<IOException>();
       for(Path p : srcFs.globPaths(srcPattern))

+ 23 - 0
src/test/org/apache/hadoop/dfs/TestDFSShell.java

@@ -737,6 +737,29 @@ public class TestDFSShell extends TestCase {
       writeFile(fileSys, myFile2);
       assertTrue(fileSys.exists(myFile2));
 
+      // Verify that rm with a pattern
+      {
+        String[] args = new String[2];
+        args[0] = "-rm";
+        args[1] = "/test/mkdirs/myFile*";
+        int val = -1;
+        try {
+          val = shell.run(args);
+        } catch (Exception e) {
+          System.err.println("Exception raised from DFSShell.run " +
+                             e.getLocalizedMessage()); 
+        }
+        assertTrue(val == 0);
+        assertFalse(fileSys.exists(myFile));
+        assertFalse(fileSys.exists(myFile2));
+
+        //re-create the files for other tests
+        writeFile(fileSys, myFile);
+        assertTrue(fileSys.exists(myFile));
+        writeFile(fileSys, myFile2);
+        assertTrue(fileSys.exists(myFile2));
+      }
+
       // Verify that we can read the file
       {
         String[] args = new String[3];