HADOOP-7361. Provide an option, -overwrite/-f, in put and copyFromLocal shell commands. Contributed by Uma Maheswara Rao G

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1144858 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Tsz-wo Sze 2011-07-10 13:28:01 +00:00
parent 6ec9b178c6
commit e8eed98feb
3 changed files with 15 additions and 5 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -94,15 +94,16 @@ static class Cp extends CommandWithDestination {
@Override
protected void processOptions(LinkedList<String> 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<String> 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<PathData> 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. */