diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index c9bf4f04c0d..1db02d266dc 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -894,6 +894,9 @@ Release 2.8.0 - UNRELEASED HADOOP-12481. JWTRedirectAuthenticationHandler doesn't Retain Original Query String (Larry McCay via cnauroth) + HADOOP-12460. Add overwrite option for 'get' shell command + (Jagadesh Kiran N via vinayakumarb) + OPTIMIZATIONS HADOOP-11785. Reduce the number of listStatus operation in distcp diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CopyCommands.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CopyCommands.java index d16d27ef549..c4e42c94b93 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CopyCommands.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CopyCommands.java @@ -191,11 +191,12 @@ class CopyCommands { public static class Get extends CommandWithDestination { public static final String NAME = "get"; public static final String USAGE = - "[-p] [-ignoreCrc] [-crc] ... "; + "[-f] [-p] [-ignoreCrc] [-crc] ... "; public static final String DESCRIPTION = "Copy files that match the file pattern " + "to the local name. is kept. When copying multiple " + "files, the destination must be a directory. Passing " + + "-f overwrites the destination if it already exists and " + "-p preserves access and modification times, " + "ownership and the mode.\n"; @@ -203,11 +204,12 @@ class CopyCommands { protected void processOptions(LinkedList args) throws IOException { CommandFormat cf = new CommandFormat( - 1, Integer.MAX_VALUE, "crc", "ignoreCrc", "p"); + 1, Integer.MAX_VALUE, "crc", "ignoreCrc", "p", "f"); cf.parse(args); setWriteChecksum(cf.getOpt("crc")); setVerifyChecksum(!cf.getOpt("ignoreCrc")); setPreserve(cf.getOpt("p")); + setOverwrite(cf.getOpt("f")); setRecursive(true); getLocalDestination(args); } diff --git a/hadoop-common-project/hadoop-common/src/site/markdown/FileSystemShell.md b/hadoop-common-project/hadoop-common/src/site/markdown/FileSystemShell.md index 2ea5abafd6a..e243deafbbe 100644 --- a/hadoop-common-project/hadoop-common/src/site/markdown/FileSystemShell.md +++ b/hadoop-common-project/hadoop-common/src/site/markdown/FileSystemShell.md @@ -320,6 +320,10 @@ Exit Code: Returns 0 on success and -1 on error. +Options: + +The -f option will overwrite the destination if it already exists. + getfacl ------- diff --git a/hadoop-common-project/hadoop-common/src/test/resources/testConf.xml b/hadoop-common-project/hadoop-common/src/test/resources/testConf.xml index 75138439979..fd71034a040 100644 --- a/hadoop-common-project/hadoop-common/src/test/resources/testConf.xml +++ b/hadoop-common-project/hadoop-common/src/test/resources/testConf.xml @@ -165,7 +165,7 @@ RegexpComparator - ^-get( )*\[-p\]( )*\[-ignoreCrc\]( )*\[-crc\]( )*<src> \.\.\. <localdst> :\s* + ^-get( )*\[-f\]( )*\[-p\]( )*\[-ignoreCrc\]( )*\[-crc\]( )*<src> \.\.\. <localdst> :\s* RegexpComparator @@ -173,11 +173,15 @@ RegexpComparator - \s*When copying multiple files, the destination must be a directory. Passing -p\s* + ^( |\t)*When copying multiple files, the destination must be a directory. Passing -f( )* RegexpComparator - ^( |\t)*preserves access and modification times, ownership and the mode.* + ^( |\t)*overwrites the destination if it already exists and -p preserves access and( )* + + + RegexpComparator + ^( |\t)*modification times, ownership and the mode.* @@ -566,7 +570,7 @@ RegexpComparator - ^-get( )*\[-p\]( )*\[-ignoreCrc\]( )*\[-crc\]( )*<src> \.\.\. <localdst> :\s* + ^-get( )*\[-f\]( )*\[-p\]( )*\[-ignoreCrc\]( )*\[-crc\]( )*<src> \.\.\. <localdst> :\s* RegexpComparator @@ -574,11 +578,15 @@ RegexpComparator - ^( |\t)*When copying multiple files, the destination must be a directory. Passing -p( )* + ^( |\t)*When copying multiple files, the destination must be a directory. Passing -f( )* RegexpComparator - ^( |\t)*preserves access and modification times, ownership and the mode.( )* + ^( |\t)*overwrites the destination if it already exists and -p preserves access and( )* + + + RegexpComparator + ^( |\t)*modification times, ownership and the mode.* @@ -680,7 +688,7 @@ RegexpComparator - ^-copyToLocal \[-p\] \[-ignoreCrc\] \[-crc\] <src> \.\.\. <localdst> :\s* + ^-copyToLocal \[-f\] \[-p\] \[-ignoreCrc\] \[-crc\] <src> \.\.\. <localdst> :\s* RegexpComparator