Browse Source

HADOOP-6145. Fix FsShell rm/rmr error messages when there is a FNFE. Contributed by Jakob Homan

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@793987 13f79535-47bb-0310-9956-ffa450edef68
Tsz-wo Sze 16 years ago
parent
commit
466f93c8b6
2 changed files with 13 additions and 5 deletions
  1. 3 0
      CHANGES.txt
  2. 10 5
      src/java/org/apache/hadoop/fs/FsShell.java

+ 3 - 0
CHANGES.txt

@@ -1014,6 +1014,9 @@ Release 0.20.1 - Unreleased
     HADOOP-6139. Fix the FsShell help messages for rm and rmr.  (Jakob Homan
     via szetszwo)
 
+    HADOOP-6145. Fix FsShell rm/rmr error messages when there is a FNFE.
+    (Jakob Homan via szetszwo)
+
 Release 0.20.0 - 2009-04-15
 
   INCOMPATIBLE CHANGES

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

@@ -1110,7 +1110,16 @@ public class FsShell extends Configured implements Tool {
   /* delete a file */
   private void delete(Path src, FileSystem srcFs, boolean recursive, 
                       boolean skipTrash) throws IOException {
-    if (srcFs.isDirectory(src) && !recursive) {
+    FileStatus fs = null;
+    try {
+      fs = srcFs.getFileStatus(src);
+    } catch (FileNotFoundException fnfe) {
+      // Have to re-throw so that console output is as expected
+      throw new FileNotFoundException("cannot remove "
+          + src + ": No such file or directory.");
+    }
+    
+    if (fs.isDir() && !recursive) {
       throw new IOException("Cannot remove directory \"" + src +
                             "\", use -rmr instead");
     }
@@ -1126,10 +1135,6 @@ public class FsShell extends Configured implements Tool {
     if (srcFs.delete(src, true)) {
       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);
     }
   }