Selaa lähdekoodia

HADOOP-12460. Add overwrite option for 'get' shell command (Contributed by Jagadesh Kiran N)

Vinayakumar B 9 vuotta sitten
vanhempi
commit
7f0e1eb43d

+ 3 - 0
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

+ 4 - 2
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] <src> ... <localdst>";
+      "[-f] [-p] [-ignoreCrc] [-crc] <src> ... <localdst>";
     public static final String DESCRIPTION =
       "Copy files that match the file pattern <src> " +
       "to the local name.  <src> 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<String> 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);
     }

+ 4 - 0
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
 -------
 

+ 15 - 7
hadoop-common-project/hadoop-common/src/test/resources/testConf.xml

@@ -165,7 +165,7 @@
       <comparators>
         <comparator>
           <type>RegexpComparator</type>
-          <expected-output>^-get( )*\[-p\]( )*\[-ignoreCrc\]( )*\[-crc\]( )*&lt;src&gt; \.\.\. &lt;localdst&gt; :\s*</expected-output>
+          <expected-output>^-get( )*\[-f\]( )*\[-p\]( )*\[-ignoreCrc\]( )*\[-crc\]( )*&lt;src&gt; \.\.\. &lt;localdst&gt; :\s*</expected-output>
         </comparator>
         <comparator>
           <type>RegexpComparator</type>
@@ -173,11 +173,15 @@
         </comparator>
         <comparator>
           <type>RegexpComparator</type>
-          <expected-output>\s*When copying multiple files, the destination must be a directory. Passing -p\s*</expected-output>
+           <expected-output>^( |\t)*When copying multiple files, the destination must be a directory. Passing -f( )*</expected-output>
         </comparator>
         <comparator>
           <type>RegexpComparator</type>
-          <expected-output>^( |\t)*preserves access and modification times, ownership and the mode.*</expected-output>
+          <expected-output>^( |\t)*overwrites the destination if it already exists and -p preserves access and( )*</expected-output>
+        </comparator>
+        <comparator>
+          <type>RegexpComparator</type>
+         <expected-output>^( |\t)*modification times, ownership and the mode.*</expected-output>
         </comparator>
       </comparators>
     </test>
@@ -566,7 +570,7 @@
       <comparators>
         <comparator>
           <type>RegexpComparator</type>
-          <expected-output>^-get( )*\[-p\]( )*\[-ignoreCrc\]( )*\[-crc\]( )*&lt;src&gt; \.\.\. &lt;localdst&gt; :\s*</expected-output>
+          <expected-output>^-get( )*\[-f\]( )*\[-p\]( )*\[-ignoreCrc\]( )*\[-crc\]( )*&lt;src&gt; \.\.\. &lt;localdst&gt; :\s*</expected-output>
         </comparator>
         <comparator>
           <type>RegexpComparator</type>
@@ -574,11 +578,15 @@
         </comparator>
         <comparator>
           <type>RegexpComparator</type>
-          <expected-output>^( |\t)*When copying multiple files, the destination must be a directory. Passing -p( )*</expected-output>
+          <expected-output>^( |\t)*When copying multiple files, the destination must be a directory. Passing -f( )*</expected-output>
+        </comparator>
+        <comparator>
+          <type>RegexpComparator</type>
+          <expected-output>^( |\t)*overwrites the destination if it already exists and -p preserves access and( )*</expected-output>
         </comparator>
         <comparator>
           <type>RegexpComparator</type>
-          <expected-output>^( |\t)*preserves access and modification times, ownership and the mode.( )*</expected-output>
+         <expected-output>^( |\t)*modification times, ownership and the mode.*</expected-output>
         </comparator>
       </comparators>
     </test>
@@ -680,7 +688,7 @@
       <comparators>
         <comparator>
           <type>RegexpComparator</type>
-          <expected-output>^-copyToLocal \[-p\] \[-ignoreCrc\] \[-crc\] &lt;src&gt; \.\.\. &lt;localdst&gt; :\s*</expected-output>
+          <expected-output>^-copyToLocal \[-f\] \[-p\] \[-ignoreCrc\] \[-crc\] &lt;src&gt; \.\.\. &lt;localdst&gt; :\s*</expected-output>
         </comparator>
         <comparator>
           <type>RegexpComparator</type>