Browse Source

HADOOP-2191. du and dus command on non-existent directory gives
appropriate error message. (Mahadev Konar via dhruba)



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

Dhruba Borthakur 17 years ago
parent
commit
fdf95ede8d

+ 3 - 0
CHANGES.txt

@@ -32,6 +32,9 @@ Trunk (unreleased changes)
     HADOOP-1593. FsShell works with paths in non-default FileSystem.
     (Mahadev Konar via dhruba)
 
+    HADOOP-2191. du and dus command on non-existent directory gives 
+    appropriate error message.  (Mahadev Konar via dhruba)
+
 Release 0.16.1 - Unrelease
 
   BUG FIXES

+ 13 - 9
src/java/org/apache/hadoop/fs/FsShell.java

@@ -616,8 +616,10 @@ public class FsShell extends Configured implements Tool {
     Path srcPath = new Path(src);
     FileSystem srcFs = srcPath.getFileSystem(getConf());
     Path items[] = srcFs.listPaths(srcFs.globPaths(srcPath));
-    if (items == null) {
-      throw new IOException("Could not get listing for " + src);
+    if ((items == null) || ((items.length == 0) && 
+        (!srcFs.exists(srcPath)))){
+      throw new FileNotFoundException("Cannot access " + src
+            + ": No such file or directory.");
     } else {
       System.out.println("Found " + items.length + " items");
       for (int i = 0; i < items.length; i++) {
@@ -637,18 +639,20 @@ public class FsShell extends Configured implements Tool {
   void dus(String src) throws IOException {
     Path srcPath = new Path(src);
     FileSystem srcFs = srcPath.getFileSystem(getConf());
-    Path paths[] = srcFs.globPaths(new Path(src));
-    if (paths==null || paths.length==0) {
-      throw new IOException("dus: No match: " + src);
+    FileStatus status[] = srcFs.globStatus(new Path(src));
+    if (status==null || status.length==0) {
+      throw new FileNotFoundException("Cannot access " + src + 
+          ": No such file or directory.");
     }
-    for(int i=0; i<paths.length; i++) {
-      Path items[] = srcFs.listPaths(paths[i]);
+    for(int i=0; i<status.length; i++) {
+      FileStatus items[] = srcFs.listStatus(status[i].getPath());
       if (items != null) {
         long totalSize=0;
         for(int j=0; j<items.length; j++) {
-          totalSize += srcFs.getContentLength(items[j]);
+          totalSize += srcFs.getContentLength(
+              items[j].getPath());
         }
-        String pathStr = paths[i].toString();
+        String pathStr = status[i].getPath().toString();
         System.out.println(
                            ("".equals(pathStr)?".":pathStr) + "\t" + totalSize);
       }

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

@@ -213,6 +213,21 @@ public class TestDFSShell extends TestCase {
       returned = out.toString();
       assertTrue("rmr prints reasonable error ",
     		  (returned.lastIndexOf("No such file or directory") != -1));
+      out.reset();
+      argv[0] = "-du";
+      argv[1] = "/nonexistentfile";
+      ret = ToolRunner.run(shell, argv);
+      returned = out.toString();
+      assertTrue(" -du prints reasonable error ",
+          (returned.lastIndexOf("No such file or directory") != -1));
+      out.reset();
+      argv[0] = "-dus";
+      argv[1] = "/nonexistentfile";
+      ret = ToolRunner.run(shell, argv);
+      returned = out.toString();
+      assertTrue(" -dus prints reasonable error",
+          (returned.lastIndexOf("No such file or directory") != -1));
+      out.reset();
     } finally {
       if (bak != null) {
         System.setErr(bak);