瀏覽代碼

HADOOP-3056. Fix distcp when the target is an empty directory by
making sure the directory is created first. Contributed by cdouglas and
acmurthy.


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

Owen O'Malley 17 年之前
父節點
當前提交
660428df1c
共有 2 個文件被更改,包括 13 次插入1 次删除
  1. 4 0
      CHANGES.txt
  2. 9 1
      src/java/org/apache/hadoop/util/CopyFiles.java

+ 4 - 0
CHANGES.txt

@@ -403,6 +403,10 @@ Release 0.16.2 - Unreleased
     HADOOP-3027. Fixes a problem to do with adding a shutdown hook in
     HADOOP-3027. Fixes a problem to do with adding a shutdown hook in
     FileSystem.  (Amareshwari Sriramadasu via ddas)
     FileSystem.  (Amareshwari Sriramadasu via ddas)
 
 
+    HADOOP-3056. Fix distcp when the target is an empty directory by
+    making sure the directory is created first. (cdouglas and acmurthy 
+    via omalley)
+
 Release 0.16.1 - 2008-03-13
 Release 0.16.1 - 2008-03-13
 
 
   INCOMPATIBLE CHANGES
   INCOMPATIBLE CHANGES

+ 9 - 1
src/java/org/apache/hadoop/util/CopyFiles.java

@@ -142,6 +142,9 @@ public class CopyFiles implements Tool {
       input.write(out);
       input.write(out);
       Text.writeString(out, output.toString());
       Text.writeString(out, output.toString());
     }
     }
+    public String toString() {
+      return input.toString() + " : " + output.toString();
+    }
   }
   }
 
 
   /**
   /**
@@ -344,6 +347,9 @@ public class CopyFiles implements Tool {
             destFileSys.getFileStatus(absdst).isDir()) {
             destFileSys.getFileStatus(absdst).isDir()) {
           throw new IOException(absdst + " is a directory");
           throw new IOException(absdst + " is a directory");
         }
         }
+        if (!destFileSys.mkdirs(absdst.getParent())) {
+          throw new IOException("Failed to craete parent dir: " + absdst.getParent());
+        }
         rename(destFileSys, tmpfile, absdst);
         rename(destFileSys, tmpfile, absdst);
       }
       }
 
 
@@ -360,7 +366,9 @@ public class CopyFiles implements Tool {
         if (fs.exists(dst)) {
         if (fs.exists(dst)) {
           fs.delete(dst, true);
           fs.delete(dst, true);
         }
         }
-        fs.rename(tmp, dst);
+        if (!fs.rename(tmp, dst)) {
+          throw new IOException();
+        }
       }
       }
       catch(IOException cause) {
       catch(IOException cause) {
         IOException ioe = new IOException("Fail to rename tmp file (=" + tmp 
         IOException ioe = new IOException("Fail to rename tmp file (=" + tmp