Browse Source

HADOOP-2192. Error messages from "dfs mv" command improved.
(Mahadev Konar via dhruba)



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

Dhruba Borthakur 17 năm trước cách đây
mục cha
commit
174bd27604

+ 3 - 0
CHANGES.txt

@@ -10,6 +10,9 @@ Trunk (unreleased changes)
     HADOOP-2345.  New HDFS transactions to support appending 
     to files.  Disk layout version changed from -11 to -12. (dhruba)
 
+    HADOOP-2192. Error messages from "dfs mv" command improved.
+    (Mahadev Konar via dhruba)
+
   NEW FEATURES
 
     HADOOP-1398.  Add HBase in-memory block cache.  (tomwhite)

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

@@ -39,6 +39,7 @@ import org.apache.hadoop.io.WritableComparable;
 import org.apache.hadoop.ipc.RPC;
 import org.apache.hadoop.ipc.RemoteException;
 import org.apache.hadoop.util.ReflectionUtils;
+import org.apache.hadoop.util.StringUtils;
 import org.apache.hadoop.util.Tool;
 import org.apache.hadoop.util.ToolRunner;
 
@@ -816,10 +817,26 @@ public class FsShell extends Configured implements Tool {
                             + "destination should be a directory.");
     }
     for(int i=0; i<srcs.length; i++) {
-      if (srcFs.rename(srcs[i], dst)) {
-        System.out.println("Renamed " + srcs[i] + " to " + dstf);
-      } else {
-        throw new IOException("Rename failed " + srcs[i]);
+      if (!srcFs.rename(srcs[i], dst)) {
+        FileStatus srcFstatus = null;
+        FileStatus dstFstatus = null;
+        try {
+          srcFstatus = srcFs.getFileStatus(srcs[i]);
+        } catch(FileNotFoundException e) {
+          throw new FileNotFoundException(srcs[i] + 
+          ": No such file or directory");
+        }
+        try {
+          dstFstatus = dstFs.getFileStatus(dst);
+        } catch(IOException e) {
+          //hide this
+        }
+        if((srcFstatus!= null) && (dstFstatus!= null)) {
+          if (srcFstatus.isDir()  && !dstFstatus.isDir()) {
+            throw new IOException("cannot overwrite non directory "
+                + dst + " with directory " + srcs[i]);
+          }
+        }
       }
     }
   }

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

@@ -175,7 +175,7 @@ public class TestDFSShell extends TestCase {
   }
 
 
-  /** check if we have any exceptions in cat command output */
+  /** check command error outputs and exit statuses. */
   public void testErrOutPut() throws Exception {
     Configuration conf = new Configuration();
     MiniDFSCluster cluster = null;
@@ -276,6 +276,22 @@ public class TestDFSShell extends TestCase {
       assertTrue(" -mkdir returned this is a file ",
           (returned.lastIndexOf("not a directory") != -1));
       out.reset();
+      argv = new String[3];
+      argv[0] = "-mv";
+      argv[1] = "/testfile";
+      argv[2] = "/testfiletest";
+      ret = ToolRunner.run(shell, argv);
+      returned = out.toString();
+      assertTrue("no output from rename", 
+          (returned.lastIndexOf("Renamed") == -1));
+      out.reset();
+      argv[0] = "-mv";
+      argv[1] = "/testfile";
+      argv[2] = "/testfiletmp";
+      ret = ToolRunner.run(shell, argv);
+      returned = out.toString();
+      assertTrue(" unix like output",
+          (returned.lastIndexOf("No such file or") != -1));
     } finally {
       if (bak != null) {
         System.setErr(bak);