hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cdoug...@apache.org
Subject svn commit: r627844 - in /hadoop/core/trunk: CHANGES.txt src/java/org/apache/hadoop/fs/FileUtil.java src/test/org/apache/hadoop/fs/TestLocalFileSystem.java
Date Thu, 14 Feb 2008 19:13:43 GMT
Author: cdouglas
Date: Thu Feb 14 11:13:39 2008
New Revision: 627844

URL: http://svn.apache.org/viewvc?rev=627844&view=rev
Log:
HADOOP-2808. Minor fix to FileUtil::copy to mind the overwrite
formal. Contributed by Chris Douglas.


Modified:
    hadoop/core/trunk/CHANGES.txt
    hadoop/core/trunk/src/java/org/apache/hadoop/fs/FileUtil.java
    hadoop/core/trunk/src/test/org/apache/hadoop/fs/TestLocalFileSystem.java

Modified: hadoop/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/CHANGES.txt?rev=627844&r1=627843&r2=627844&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Thu Feb 14 11:13:39 2008
@@ -79,6 +79,9 @@
     HADOOP-2391. Cleanup job output directory before declaring a job as
     SUCCESSFUL. (Amareshwari Sri Ramadasu via ddas)
 
+    HADOOP-2808. Minor fix to FileUtil::copy to mind the overwrite
+    formal. (cdouglas)
+
 Release 0.16.0 - 2008-02-07
 
   INCOMPATIBLE CHANGES

Modified: hadoop/core/trunk/src/java/org/apache/hadoop/fs/FileUtil.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/java/org/apache/hadoop/fs/FileUtil.java?rev=627844&r1=627843&r2=627844&view=diff
==============================================================================
--- hadoop/core/trunk/src/java/org/apache/hadoop/fs/FileUtil.java (original)
+++ hadoop/core/trunk/src/java/org/apache/hadoop/fs/FileUtil.java Thu Feb 14 11:13:39 2008
@@ -139,7 +139,7 @@
                              boolean deleteSource,
                              boolean overwrite,
                              Configuration conf) throws IOException {
-    dst = checkDest(src.getName(), dstFS, dst);
+    dst = checkDest(src.getName(), dstFS, dst, overwrite);
 
     if (srcFS.isDirectory(src)) {
       checkDependencies(srcFS, src, dstFS, dst);
@@ -171,7 +171,7 @@
                                   FileSystem dstFS, Path dstFile, 
                                   boolean deleteSource,
                                   Configuration conf, String addString) throws IOException
{
-    dstFile = checkDest(srcDir.getName(), dstFS, dstFile);
+    dstFile = checkDest(srcDir.getName(), dstFS, dstFile, false);
 
     if (!srcFS.isDirectory(srcDir))
       return false;
@@ -210,7 +210,7 @@
                              FileSystem dstFS, Path dst,
                              boolean deleteSource,
                              Configuration conf) throws IOException {
-    dst = checkDest(src.getName(), dstFS, dst);
+    dst = checkDest(src.getName(), dstFS, dst, false);
 
     if (src.isDirectory()) {
       if (!dstFS.mkdirs(dst)) {
@@ -262,16 +262,17 @@
     }
   }
 
-  private static Path checkDest(String srcName, FileSystem dstFS, Path dst)
-    throws IOException {
+  private static Path checkDest(String srcName, FileSystem dstFS, Path dst,
+      boolean overwrite) throws IOException {
     if (dstFS.exists(dst)) {
-      if (!dstFS.isDirectory(dst)) {
-        throw new IOException("Target " + dst + " already exists");
-      } else {
-        dst = new Path(dst, srcName);
-        if (dstFS.exists(dst)) {
-          throw new IOException("Target " + dst + " already exists");
+      FileStatus sdst = dstFS.getFileStatus(dst);
+      if (sdst.isDir()) {
+        if (null == srcName) {
+          throw new IOException("Target " + dst + " is a directory");
         }
+        return checkDest(null, dstFS, new Path(dst, srcName), overwrite);
+      } else if (!overwrite) {
+        throw new IOException("Target " + dst + " already exists");
       }
     }
     return dst;

Modified: hadoop/core/trunk/src/test/org/apache/hadoop/fs/TestLocalFileSystem.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/fs/TestLocalFileSystem.java?rev=627844&r1=627843&r2=627844&view=diff
==============================================================================
--- hadoop/core/trunk/src/test/org/apache/hadoop/fs/TestLocalFileSystem.java (original)
+++ hadoop/core/trunk/src/test/org/apache/hadoop/fs/TestLocalFileSystem.java Thu Feb 14 11:13:39
2008
@@ -96,6 +96,31 @@
     }
   }
 
+  public void testCopy() throws IOException {
+    Configuration conf = new Configuration();
+    LocalFileSystem fs = FileSystem.getLocal(conf);
+    Path src = new Path(TEST_ROOT_DIR, "dingo");
+    Path dst = new Path(TEST_ROOT_DIR, "yak");
+    writeFile(fs, src);
+    assertTrue(FileUtil.copy(fs, src, fs, dst, true, false, conf));
+    assertTrue(!fs.exists(src) && fs.exists(dst));
+    assertTrue(FileUtil.copy(fs, dst, fs, src, false, false, conf));
+    assertTrue(fs.exists(src) && fs.exists(dst));
+    assertTrue(FileUtil.copy(fs, src, fs, dst, true, true, conf));
+    assertTrue(!fs.exists(src) && fs.exists(dst));
+    fs.mkdirs(src);
+    assertTrue(FileUtil.copy(fs, dst, fs, src, false, false, conf));
+    Path tmp = new Path(src, dst.getName());
+    assertTrue(fs.exists(tmp) && fs.exists(dst));
+    assertTrue(FileUtil.copy(fs, dst, fs, src, false, true, conf));
+    assertTrue(fs.delete(tmp));
+    fs.mkdirs(tmp);
+    try {
+      FileUtil.copy(fs, dst, fs, src, true, true, conf);
+      fail("Failed to detect existing dir");
+    } catch (IOException e) { }
+  }
+
   public void testHomeDirectory() throws IOException {
     Configuration conf = new Configuration();
     FileSystem fileSys = FileSystem.getLocal(conf);



Mime
View raw message