Quellcode durchsuchen

HADOOP-3792. Make FsShell -test consistent with unix semantics, returning
zero for true and non-zero for false. Contributed by Ben Slusky.


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

Christopher Douglas vor 17 Jahren
Ursprung
Commit
63d7cdd0a8

+ 3 - 0
CHANGES.txt

@@ -34,6 +34,9 @@ Trunk (unreleased changes)
 
     HADOOP-1700.  Support appending to file in HDFS. (dhruba)
 
+    HADOOP-3792. Make FsShell -test consistent with unix semantics, returning
+    zero for true and non-zero for false. (Ben Slusky via cdouglas)
+
   NEW FEATURES
 
     HADOOP-3341. Allow streaming jobs to specify the field separator for map

+ 1 - 1
src/ant/org/apache/hadoop/ant/DfsTask.java

@@ -158,7 +158,7 @@ public class DfsTask extends Task {
 
   // in case DfsTask is overridden
   protected int postCmd(int exit_code) {
-    if ("-test".equals(cmd) && exit_code == 0)
+    if ("-test".equals(cmd) && exit_code != 0)
       outprop = null;
     return exit_code;
   }

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

@@ -746,11 +746,11 @@ public class FsShell extends Configured implements Tool {
     FileSystem srcFs = f.getFileSystem(getConf());
     switch(flag) {
       case 'e':
-        return srcFs.exists(f) ? 1 : 0;
+        return srcFs.exists(f) ? 0 : 1;
       case 'z':
-        return srcFs.getFileStatus(f).getLen() == 0 ? 1 : 0;
+        return srcFs.getFileStatus(f).getLen() == 0 ? 0 : 1;
       case 'd':
-        return srcFs.getFileStatus(f).isDir() ? 1 : 0;
+        return srcFs.getFileStatus(f).isDir() ? 0 : 1;
       default:
         throw new IOException("Unknown flag: " + flag);
     }
@@ -1356,7 +1356,7 @@ public class FsShell extends Configured implements Tool {
       "\t\tin a file at <path>. An error is returned if the file exists with non-zero length\n";
 
     String test = "-test -[ezd] <path>: If file { exists, has zero length, is a directory\n" +
-      "\t\tthen return 1, else return 0.\n";
+      "\t\tthen return 0, else return 1.\n";
 
     String stat = "-stat [format] <path>: Print statistics about the file/directory at <path>\n" +
       "\t\tin the specified format. Format accepts filesize in blocks (%b), filename (%n),\n" +

+ 5 - 1
src/test/org/apache/hadoop/hdfs/TestDFSShell.java

@@ -1017,9 +1017,13 @@ public class TestDFSShell extends TestCase {
         }
         assertTrue(val == 0);
 
+        args = new String[3];
         args[0] = "-test";
-        args[1] = "-e " + args[1];
+        args[1] = "-e";
+        args[2] = "/test/mkdirs/noFileHere";
+        val = -1;
         try {
+          val = shell.run(args);
         } catch (Exception e) {
           System.err.println("Exception raised from DFSShell.run " +
                              e.getLocalizedMessage());