You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by sz...@apache.org on 2011/03/24 18:23:14 UTC

svn commit: r1085043 - in /hadoop/common/trunk: CHANGES.txt src/java/org/apache/hadoop/fs/FsShell.java src/test/core/org/apache/hadoop/fs/TestFsShellReturnCode.java

Author: szetszwo
Date: Thu Mar 24 17:23:13 2011
New Revision: 1085043

URL: http://svn.apache.org/viewvc?rev=1085043&view=rev
Log:
HADOOP-7174. Null is displayed in the "fs -copyToLocal" command.  Contributed by Uma Maheswara Rao G 

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

Modified: hadoop/common/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/CHANGES.txt?rev=1085043&r1=1085042&r2=1085043&view=diff
==============================================================================
--- hadoop/common/trunk/CHANGES.txt (original)
+++ hadoop/common/trunk/CHANGES.txt Thu Mar 24 17:23:13 2011
@@ -601,6 +601,9 @@ Release 0.21.1 - Unreleased
     HADOOP-7193. Correct the "fs -touchz" command help message.
     (Uma Maheswara Rao G via szetszwo)
 
+    HADOOP-7174. Null is displayed in the "fs -copyToLocal" command.
+    (Uma Maheswara Rao G via szetszwo)
+
 Release 0.21.0 - 2010-08-13
 
   INCOMPATIBLE CHANGES

Modified: hadoop/common/trunk/src/java/org/apache/hadoop/fs/FsShell.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/fs/FsShell.java?rev=1085043&r1=1085042&r2=1085043&view=diff
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/fs/FsShell.java (original)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/fs/FsShell.java Thu Mar 24 17:23:13 2011
@@ -195,6 +195,9 @@ public class FsShell extends Configured 
         copyCrc = false;
       }
       FileStatus[] srcs = srcFS.globStatus(srcpath);
+      if (null == srcs) {
+	throw new IOException(srcpath + ": No such file or directory");
+      }
       boolean dstIsDir = dst.isDirectory(); 
       if (srcs.length > 1 && !dstIsDir) {
         throw new IOException("When copying multiple files, "

Modified: hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestFsShellReturnCode.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestFsShellReturnCode.java?rev=1085043&r1=1085042&r2=1085043&view=diff
==============================================================================
--- hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestFsShellReturnCode.java (original)
+++ hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestFsShellReturnCode.java Thu Mar 24 17:23:13 2011
@@ -18,11 +18,15 @@
 
 package org.apache.hadoop.fs;
 
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
 
 import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.io.IOUtils;
 
 import org.junit.Test;
 import org.junit.Assert;
@@ -237,4 +241,36 @@ public class TestFsShellReturnCode {
     verify(fs, "-chgrp", argv4, 1, fsShell, 0);
 
   }
+  
+  @Test
+  public void testGetWithInvalidSourcePathShouldNotDisplayNullInConsole()
+      throws Exception {
+    Configuration conf = new Configuration();
+    FsShell shell = new FsShell();
+    shell.setConf(conf);
+    final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+    final PrintStream out = new PrintStream(bytes);
+    final PrintStream oldErr = System.err;
+    System.setErr(out);
+    final String results;
+    try {
+      FileSystem fileSys = FileSystem.getLocal(conf);
+      String[] args = new String[3];
+      args[0] = "-get";
+      args[1] = "/invalidPath";
+      args[2] = "/test/tmp";
+      assertTrue("file exists", !fileSys.exists(new Path(args[1])));
+      int run = shell.run(args);
+      results = bytes.toString();
+      assertTrue("Return code should be -1", run == -1);
+      assertTrue(" Null is coming when source path is invalid. ",!results.contains("get: null"));
+      assertTrue(" Not displaying the intended message ",results.contains("get: "+args[1]+": No such file or directory"));
+    } finally {
+      IOUtils.closeStream(out);
+      System.setErr(oldErr);
+    }
+  }
+  
+  
+  
 }
\ No newline at end of file