hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rang...@apache.org
Subject svn commit: r627593 - in /hadoop/core/trunk: CHANGES.txt src/java/org/apache/hadoop/fs/FsShell.java src/test/org/apache/hadoop/dfs/TestDFSShell.java
Date Wed, 13 Feb 2008 21:14:17 GMT
Author: rangadi
Date: Wed Feb 13 13:14:11 2008
New Revision: 627593

URL: http://svn.apache.org/viewvc?rev=627593&view=rev
Log:
HADOOP-2190. bring behaviour '-ls' and '-du' closer to Linux shell 
             commands in case of errors. (Mahadev Konar via rangadi)

Modified:
    hadoop/core/trunk/CHANGES.txt
    hadoop/core/trunk/src/java/org/apache/hadoop/fs/FsShell.java
    hadoop/core/trunk/src/test/org/apache/hadoop/dfs/TestDFSShell.java

Modified: hadoop/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/CHANGES.txt?rev=627593&r1=627592&r2=627593&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Wed Feb 13 13:14:11 2008
@@ -15,6 +15,9 @@
 
   BUG FIXES
 
+    HADOOP-2190. bring behaviour '-ls' and '-du' closer to Linux shell 
+                 commands in case of errors. (Mahadev Konar via rangadi)
+    
     HADOOP-2193. 'fs -rm' and 'fs -rmr' show error message when the target
     file does not exist. (Mahadev Konar via rangadi)
             

Modified: hadoop/core/trunk/src/java/org/apache/hadoop/fs/FsShell.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/java/org/apache/hadoop/fs/FsShell.java?rev=627593&r1=627592&r2=627593&view=diff
==============================================================================
--- hadoop/core/trunk/src/java/org/apache/hadoop/fs/FsShell.java (original)
+++ hadoop/core/trunk/src/java/org/apache/hadoop/fs/FsShell.java Wed Feb 13 13:14:11 2008
@@ -568,10 +568,15 @@
   void ls(String srcf, boolean recursive) throws IOException {
     Path srcPath = new Path(srcf);
     FileSystem srcFs = srcPath.getFileSystem(this.getConf());
-    Path[] srcs = srcFs.globPaths(srcPath);
+    FileStatus[] srcs = srcFs.globStatus(srcPath);
+    if (srcs==null || srcs.length==0) {
+      throw new FileNotFoundException("Cannot access " + srcf + 
+          ": No such file or directory.");
+    }
+ 
     boolean printHeader = (srcs.length == 1) ? true: false;
     for(int i=0; i<srcs.length; i++) {
-      ls(srcs[i], srcFs, recursive, printHeader);
+      ls(srcs[i].getPath(), srcFs, recursive, printHeader);
     }
   }
 
@@ -580,11 +585,14 @@
    */
   private void ls(Path src, FileSystem srcFs, boolean recursive, boolean printHeader) throws
IOException {
     FileStatus items[] = srcFs.listStatus(src);
-    if (items == null) {
-      throw new IOException("Could not get listing for " + src);
+    if ((items == null) || ((items.length == 0) 
+        && (!srcFs.exists(src)))) {
+      throw new FileNotFoundException(src + ": No such file or directory.");
     } else {
       if (!recursive && printHeader) {
-        System.out.println("Found " + items.length + " items");
+        if (items.length != 0) {
+          System.out.println("Found " + items.length + " items");
+        }
       }
       for (int i = 0; i < items.length; i++) {
         FileStatus stat = items[i];

Modified: hadoop/core/trunk/src/test/org/apache/hadoop/dfs/TestDFSShell.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/dfs/TestDFSShell.java?rev=627593&r1=627592&r2=627593&view=diff
==============================================================================
--- hadoop/core/trunk/src/test/org/apache/hadoop/dfs/TestDFSShell.java (original)
+++ hadoop/core/trunk/src/test/org/apache/hadoop/dfs/TestDFSShell.java Wed Feb 13 13:14:11
2008
@@ -182,6 +182,7 @@
     PrintStream bak = null;
     try {
       cluster = new MiniDFSCluster(conf, 2, true, null);
+      FileSystem srcFs = cluster.getFileSystem();
       Path root = new Path("/nonexistentfile");
       bak = System.err;
       ByteArrayOutputStream out = new ByteArrayOutputStream();
@@ -228,6 +229,32 @@
       assertTrue(" -dus prints reasonable error",
           (returned.lastIndexOf("No such file or directory") != -1));
       out.reset();
+      argv[0] = "-ls";
+      argv[1] = "/nonexistenfile";
+      ret = ToolRunner.run(shell, argv);
+      returned = out.toString();
+      assertTrue(" -ls does not return Found 0 items",
+          (returned.lastIndexOf("Found 0") == -1));
+      out.reset();
+      argv[0] = "-ls";
+      argv[1] = "/nonexistentfile";
+      ret = ToolRunner.run(shell, argv);
+      assertTrue(" -lsr should fail ",
+          (ret < 0));
+      out.reset();
+      srcFs.mkdirs(new Path("/testdir"));
+      argv[0] = "-ls";
+      argv[1] = "/testdir";
+      ret = ToolRunner.run(shell, argv);
+      returned = out.toString();
+      assertTrue(" -ls does not print out anything ",
+          (returned.lastIndexOf("Found 0") == -1));
+      out.reset();
+      argv[0] = "-ls";
+      argv[1] = "/user/nonxistant/*";
+      ret = ToolRunner.run(shell, argv);
+      assertTrue(" -ls on nonexistent glob returns -1",
+          (ret < 0));
     } finally {
       if (bak != null) {
         System.setErr(bak);



Mime
View raw message