diff --git a/common/CHANGES.txt b/common/CHANGES.txt index 8dcd295c2c..c6dcc363de 100644 --- a/common/CHANGES.txt +++ b/common/CHANGES.txt @@ -248,6 +248,9 @@ Trunk (unreleased changes) to Data(In,Out)putBuffer for byte[]. Merge from yahoo-merge branch, -r 1079163. Fix missing Apache license headers. (Chris Douglas via mattf) + HADOOP-7361. Provide an option, -overwrite/-f, in put and copyFromLocal + shell commands. (Uma Maheswara Rao G via szetszwo) + OPTIMIZATIONS HADOOP-7333. Performance improvement in PureJavaCrc32. (Eric Caspole diff --git a/common/src/java/org/apache/hadoop/fs/shell/CommandWithDestination.java b/common/src/java/org/apache/hadoop/fs/shell/CommandWithDestination.java index c09bb37a7a..7a6251d3a7 100644 --- a/common/src/java/org/apache/hadoop/fs/shell/CommandWithDestination.java +++ b/common/src/java/org/apache/hadoop/fs/shell/CommandWithDestination.java @@ -38,7 +38,12 @@ abstract class CommandWithDestination extends FsCommand { protected PathData dst; protected boolean overwrite = false; - // TODO: commands should implement a -f to enable this + /** + * + * This method is used to enable the force(-f) option while copying the files. + * + * @param flag true/false + */ protected void setOverwrite(boolean flag) { overwrite = flag; } diff --git a/common/src/java/org/apache/hadoop/fs/shell/CopyCommands.java b/common/src/java/org/apache/hadoop/fs/shell/CopyCommands.java index 32c71c32b1..261a1a3015 100644 --- a/common/src/java/org/apache/hadoop/fs/shell/CopyCommands.java +++ b/common/src/java/org/apache/hadoop/fs/shell/CopyCommands.java @@ -94,15 +94,16 @@ static class Cp extends CommandWithDestination { @Override protected void processOptions(LinkedList args) throws IOException { - CommandFormat cf = new CommandFormat(2, Integer.MAX_VALUE); + CommandFormat cf = new CommandFormat(2, Integer.MAX_VALUE, "f"); cf.parse(args); + setOverwrite(cf.getOpt("f")); getRemoteDestination(args); } @Override protected void processPath(PathData src, PathData target) throws IOException { - if (!FileUtil.copy(src.fs, src.path, target.fs, target.path, false, getConf())) { + if (!FileUtil.copy(src.fs, src.path, target.fs, target.path, false, overwrite, getConf())) { // we have no idea what the error is... FileUtils masks it and in // some cases won't even report an error throw new PathIOException(src.toString()); @@ -216,8 +217,9 @@ public static class Put extends CommandWithDestination { @Override protected void processOptions(LinkedList args) throws IOException { - CommandFormat cf = new CommandFormat(1, Integer.MAX_VALUE); + CommandFormat cf = new CommandFormat(1, Integer.MAX_VALUE, "f"); cf.parse(args); + setOverwrite(cf.getOpt("f")); getRemoteDestination(args); } @@ -246,7 +248,7 @@ protected void processArguments(LinkedList args) @Override protected void processPath(PathData src, PathData target) throws IOException { - target.fs.copyFromLocalFile(false, false, src.path, target.path); + target.fs.copyFromLocalFile(false, overwrite, src.path, target.path); } /** Copies from stdin to the destination file. */