Author: cdouglas
Date: Fri Jan 18 19:36:35 2008
New Revision: 613359

URL: http://svn.apache.org/viewvc?rev=613359&view=rev
Log:
HADOOP-2582. Prevent 'bin/hadoop fs -copyToLocal' from creating zero-length
files when the src does not exist. Contributed by Lohit Vijayarenu.



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

Modified: lucene/hadoop/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/lucene/hadoop/trunk/CHANGES.txt?rev=613359&r1=613358&r2=613359&view=diff
==============================================================================
--- lucene/hadoop/trunk/CHANGES.txt (original)
+++ lucene/hadoop/trunk/CHANGES.txt Fri Jan 18 19:36:35 2008
@@ -510,6 +510,10 @@
     the filter parameter is not given in TaskLogServlet.  
     (Michael Bieniosek via enis)
 
+    HADOOP-2582. Prevent 'bin/hadoop fs -copyToLocal' from creating
+    zero-length files when the src does not exist.
+    (Lohit Vijayarenu via cdouglas)
+
 Release 0.15.3 - 2008-01-18
 
   BUG FIXES

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/FileUtil.java
URL: 
http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/FileUtil.java?rev=613359&r1=613358&r2=613359&view=diff
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/FileUtil.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/FileUtil.java Fri Jan 18 
19:36:35 2008
@@ -208,6 +208,9 @@
     } else if (src.isFile()) {
       InputStream in = new FileInputStream(src);
       IOUtils.copyBytes(in, dstFS.create(dst), conf);
+    } else {
+      throw new IOException(src.toString() + 
+                            ": No such file or directory");
     }
     if (deleteSource) {
       return FileUtil.fullyDelete(src);
@@ -232,6 +235,9 @@
     } else if (srcFS.isFile(src)) {
       InputStream in = srcFS.open(src);
       IOUtils.copyBytes(in, new FileOutputStream(dst), conf);
+    } else {
+      throw new IOException(src.toString() + 
+                            ": No such file or directory");
     }
     if (deleteSource) {
       return srcFS.delete(src);

Modified: lucene/hadoop/trunk/src/test/org/apache/hadoop/dfs/TestDFSShell.java
URL: 
http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/test/org/apache/hadoop/dfs/TestDFSShell.java?rev=613359&r1=613358&r2=613359&view=diff
==============================================================================
--- lucene/hadoop/trunk/src/test/org/apache/hadoop/dfs/TestDFSShell.java 
(original)
+++ lucene/hadoop/trunk/src/test/org/apache/hadoop/dfs/TestDFSShell.java Fri 
Jan 18 19:36:35 2008
@@ -292,6 +292,19 @@
         f5.delete();
         sub.delete();
       }
+      // Verify copying non existing sources do not create zero byte
+      // destination files
+      {
+        String[] args = {"-copyToLocal", "nosuchfile", TEST_ROOT_DIR};
+        try {   
+          assertEquals(-1, shell.run(args));
+        } catch (Exception e) {
+          System.err.println("Exception raised from DFSShell.run " +
+                            e.getLocalizedMessage());
+        }                            
+        File f6 = new File(TEST_ROOT_DIR, "nosuchfile");
+        assertTrue(!f6.exists());
+      }
     } finally {
       try {
         dfs.close();


Reply via email to