Author: cdouglas
Date: Thu Feb 14 11:13:12 2008
New Revision: 627843
URL: http://svn.apache.org/viewvc?rev=627843&view=rev
Log:
HADOOP-2808. Minor fix to FileUtil::copy to mind the overwrite
formal. Contributed by Chris Douglas.
Modified:
hadoop/core/branches/branch-0.16/CHANGES.txt
hadoop/core/branches/branch-0.16/src/java/org/apache/hadoop/fs/FileUtil.java
hadoop/core/branches/branch-0.16/src/test/org/apache/hadoop/fs/TestLocalFileSystem.java
Modified: hadoop/core/branches/branch-0.16/CHANGES.txt
URL:
http://svn.apache.org/viewvc/hadoop/core/branches/branch-0.16/CHANGES.txt?rev=627843&r1=627842&r2=627843&view=diff
==============================================================================
--- hadoop/core/branches/branch-0.16/CHANGES.txt (original)
+++ hadoop/core/branches/branch-0.16/CHANGES.txt Thu Feb 14 11:13:12 2008
@@ -38,6 +38,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/branches/branch-0.16/src/java/org/apache/hadoop/fs/FileUtil.java
URL:
http://svn.apache.org/viewvc/hadoop/core/branches/branch-0.16/src/java/org/apache/hadoop/fs/FileUtil.java?rev=627843&r1=627842&r2=627843&view=diff
==============================================================================
---
hadoop/core/branches/branch-0.16/src/java/org/apache/hadoop/fs/FileUtil.java
(original)
+++
hadoop/core/branches/branch-0.16/src/java/org/apache/hadoop/fs/FileUtil.java
Thu Feb 14 11:13:12 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/branches/branch-0.16/src/test/org/apache/hadoop/fs/TestLocalFileSystem.java
URL:
http://svn.apache.org/viewvc/hadoop/core/branches/branch-0.16/src/test/org/apache/hadoop/fs/TestLocalFileSystem.java?rev=627843&r1=627842&r2=627843&view=diff
==============================================================================
---
hadoop/core/branches/branch-0.16/src/test/org/apache/hadoop/fs/TestLocalFileSystem.java
(original)
+++
hadoop/core/branches/branch-0.16/src/test/org/apache/hadoop/fs/TestLocalFileSystem.java
Thu Feb 14 11:13:12 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);