From b6dce3834d7d95ed1d6ba52680ebce4d7bbe6d14 Mon Sep 17 00:00:00 2001 From: Vinayakumar B Date: Mon, 19 Oct 2015 12:15:02 +0530 Subject: [PATCH] HADOOP-12460. Add overwrite option for 'get' shell command (Contributed by Jagadesh Kiran N) (cherry picked from commit 7f0e1eb43d3fb173e3c7932739ef20095e28ed7b) --- .../hadoop-common/CHANGES.txt | 3 +++ .../apache/hadoop/fs/shell/CopyCommands.java | 6 +++-- .../src/site/markdown/FileSystemShell.md | 4 ++++ .../src/test/resources/testConf.xml | 22 +++++++++++++------ 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index a19c4b8abe4..a61e3cde492 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -306,6 +306,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 2f4b0ed1f3e..5aefd495541 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 714f6c69909..f92d4361496 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