Browse Source

HADOOP-2193. 'fs -rm' and 'fs -rmr' show error message when the target
file does not exist. (Mahadev Konar via rangadi)


git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/trunk@620708 13f79535-47bb-0310-9956-ffa450edef68

Raghu Angadi 17 years ago
parent
commit
928e50c48a

+ 3 - 0
CHANGES.txt

@@ -15,6 +15,9 @@ Trunk (unreleased changes)
 
   BUG FIXES
 
+    HADOOP-2193. 'fs -rm' and 'fs -rmr' show error message when the target
+    file does not exist. (Mahadev Konar via rangadi)
+            
     HADOOP-2738 Text is not subclassable because set(Text) and compareTo(Object)
     access the other instance's private members directly.
 

+ 5 - 0
src/java/org/apache/hadoop/fs/FsShell.java

@@ -18,6 +18,7 @@
 package org.apache.hadoop.fs;
 
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URI;
@@ -981,6 +982,10 @@ public class FsShell extends Configured implements Tool {
     if (srcFs.delete(src)) {
       System.out.println("Deleted " + src);
     } else {
+      if (!srcFs.exists(src)) {
+        throw new FileNotFoundException("cannot remove "
+            + src + ": No such file or directory.");
+        }
       throw new IOException("Delete failed " + src);
     }
   }

+ 19 - 1
src/test/org/apache/hadoop/dfs/TestDFSShell.java

@@ -176,7 +176,7 @@ public class TestDFSShell extends TestCase {
 
 
   /** check if we have any exceptions in cat command output */
-  public void testCatException() throws Exception {
+  public void testErrOutPut() throws Exception {
     Configuration conf = new Configuration();
     MiniDFSCluster cluster = null;
     PrintStream bak = null;
@@ -195,6 +195,24 @@ public class TestDFSShell extends TestCase {
       String returned = out.toString();
       assertTrue("cat does not print exceptions ",
           (returned.lastIndexOf("Exception") == -1));
+      out.reset();
+      argv[0] = "-rm";
+      argv[1] = root.toString();
+      FsShell shell = new FsShell();
+      shell.setConf(conf);
+      ret = ToolRunner.run(shell, argv);
+      assertTrue(" -rm returned -1 ", 0>=ret);
+      returned = out.toString();
+      out.reset();
+      assertTrue("rm prints reasonable error ",
+          (returned.lastIndexOf("No such file or directory") != -1));
+      argv[0] = "-rmr";
+      argv[1] = root.toString();
+      ret = ToolRunner.run(shell, argv);
+      assertTrue(" -rmr returned -1", 0>=ret);
+      returned = out.toString();
+      assertTrue("rmr prints reasonable error ",
+    		  (returned.lastIndexOf("No such file or directory") != -1));
     } finally {
       if (bak != null) {
         System.setErr(bak);