hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s..@apache.org
Subject svn commit: r789878 - in /hadoop/common/branches/branch-0.20: CHANGES.txt src/core/org/apache/hadoop/fs/FsShell.java src/docs/src/documentation/content/xdocs/hdfs_shell.xml src/test/org/apache/hadoop/fs/TestTrash.java
Date Tue, 30 Jun 2009 19:00:52 GMT
Author: shv
Date: Tue Jun 30 19:00:51 2009
New Revision: 789878

URL: http://svn.apache.org/viewvc?rev=789878&view=rev
Log:
HADOOP-6080. Merge -r 789874:789875 from trunk to branch 0.20.

Modified:
    hadoop/common/branches/branch-0.20/CHANGES.txt
    hadoop/common/branches/branch-0.20/src/core/org/apache/hadoop/fs/FsShell.java
    hadoop/common/branches/branch-0.20/src/docs/src/documentation/content/xdocs/hdfs_shell.xml
    hadoop/common/branches/branch-0.20/src/test/org/apache/hadoop/fs/TestTrash.java

Modified: hadoop/common/branches/branch-0.20/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20/CHANGES.txt?rev=789878&r1=789877&r2=789878&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20/CHANGES.txt (original)
+++ hadoop/common/branches/branch-0.20/CHANGES.txt Tue Jun 30 19:00:51 2009
@@ -12,6 +12,9 @@
 
   NEW FEATURES
 
+    HADOOP-6080. Introduce -skipTrash option to rm and rmr.
+    (Jakob Homan via shv)
+
   IMPROVEMENTS
 
     HADOOP-5711. Change Namenode file close log to info. (szetszwo)

Modified: hadoop/common/branches/branch-0.20/src/core/org/apache/hadoop/fs/FsShell.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20/src/core/org/apache/hadoop/fs/FsShell.java?rev=789878&r1=789877&r2=789878&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20/src/core/org/apache/hadoop/fs/FsShell.java (original)
+++ hadoop/common/branches/branch-0.20/src/core/org/apache/hadoop/fs/FsShell.java Tue Jun
30 19:00:51 2009
@@ -1021,10 +1021,12 @@
    * Delete all files that match the file pattern <i>srcf</i>.
    * @param srcf a file pattern specifying source files
    * @param recursive if need to delete subdirs
+   * @param skipTrash Should we skip the trash, if it's enabled?
    * @throws IOException  
    * @see org.apache.hadoop.fs.FileSystem#globStatus(Path)
    */
-  void delete(String srcf, final boolean recursive) throws IOException {
+  void delete(String srcf, final boolean recursive, final boolean skipTrash) 
+                                                            throws IOException {
     //rm behavior in Linux
     //  [~/1207]$ ls ?.txt
     //  x.txt  z.txt
@@ -1035,22 +1037,27 @@
     new DelayedExceptionThrowing() {
       @Override
       void process(Path p, FileSystem srcFs) throws IOException {
-        delete(p, srcFs, recursive);
+        delete(p, srcFs, recursive, skipTrash);
       }
     }.globAndProcess(srcPattern, srcPattern.getFileSystem(getConf()));
   }
     
   /* delete a file */
-  private void delete(Path src, FileSystem srcFs, boolean recursive) throws IOException {
+  private void delete(Path src, FileSystem srcFs, boolean recursive, 
+                      boolean skipTrash) throws IOException {
     if (srcFs.isDirectory(src) && !recursive) {
       throw new IOException("Cannot remove directory \"" + src +
                             "\", use -rmr instead");
     }
-    Trash trashTmp = new Trash(srcFs, getConf());
-    if (trashTmp.moveToTrash(src)) {
-      System.out.println("Moved to trash: " + src);
-      return;
+    
+    if(!skipTrash) {
+      Trash trashTmp = new Trash(srcFs, getConf());
+      if (trashTmp.moveToTrash(src)) {
+        System.out.println("Moved to trash: " + src);
+        return;
+      }
     }
+    
     if (srcFs.delete(src, true)) {
       System.out.println("Deleted " + src);
     } else {
@@ -1061,7 +1068,6 @@
       throw new IOException("Delete failed " + src);
     }
   }
-
   private void expunge() throws IOException {
     trash.expunge();
     trash.checkpoint();
@@ -1243,8 +1249,8 @@
       "The full syntax is: \n\n" +
       "hadoop fs [-fs <local | file system URI>] [-conf <configuration file>]\n\t"
+
       "[-D <property=value>] [-ls <path>] [-lsr <path>] [-du <path>]\n\t"
+ 
-      "[-dus <path>] [-mv <src> <dst>] [-cp <src> <dst>] [-rm
<src>]\n\t" + 
-      "[-rmr <src>] [-put <localsrc> ... <dst>] [-copyFromLocal <localsrc>
... <dst>]\n\t" +
+      "[-dus <path>] [-mv <src> <dst>] [-cp <src> <dst>] [-rm
[-skipTrash] <src>]\n\t" + 
+      "[-rmr [-skipTrash] <src>] [-put <localsrc> ... <dst>] [-copyFromLocal
<localsrc> ... <dst>]\n\t" +
       "[-moveFromLocal <localsrc> ... <dst>] [" + 
       GET_SHORT_USAGE + "\n\t" +
       "[-getmerge <src> <localdst> [addnl]] [-cat <src>]\n\t" +
@@ -1308,11 +1314,15 @@
       "\t\tdestination.  When copying multiple files, the destination\n" +
       "\t\tmust be a directory. \n";
 
-    String rm = "-rm <src>: \tDelete all files that match the specified file pattern.\n"
+
-      "\t\tEquivlent to the Unix command \"rm <src>\"\n";
-
-    String rmr = "-rmr <src>: \tRemove all directories which match the specified file
\n" +
-      "\t\tpattern. Equivlent to the Unix command \"rm -rf <src>\"\n";
+    String rm = "-rm [-skipTrash] <src>: \tDelete all files that match the specified
file pattern.\n" +
+      "\t\tEquivalent to the Unix command \"rm <src>\"\n" +
+      "\t\t-skipTrash option bypasses trash, if enabled, and immediately\n" +
+      "deletes <src>";
+
+    String rmr = "-rmr [-skipTrash] <src>: \tRemove all directories which match the
specified file \n" +
+      "\t\tpattern. Equivalent to the Unix command \"rm -rf <src>\"\n" +
+      "\t\t-skipTrash option bypasses trash, if enabled, and immediately\n" +
+      "deletes <src>";
 
     String put = "-put <localsrc> ... <dst>: \tCopy files " + 
     "from the local file system \n\t\tinto fs. \n";
@@ -1507,6 +1517,15 @@
   private int doall(String cmd, String argv[], int startindex) {
     int exitCode = 0;
     int i = startindex;
+    boolean rmSkipTrash = false;
+    
+    // Check for -skipTrash option in rm/rmr
+    if(("-rm".equals(cmd) || "-rmr".equals(cmd)) 
+        && "-skipTrash".equals(argv[i])) {
+      rmSkipTrash = true;
+      i++;
+    }
+
     //
     // for each source file, issue the command
     //
@@ -1520,9 +1539,9 @@
         } else if ("-mkdir".equals(cmd)) {
           mkdir(argv[i]);
         } else if ("-rm".equals(cmd)) {
-          delete(argv[i], false);
+          delete(argv[i], false, rmSkipTrash);
         } else if ("-rmr".equals(cmd)) {
-          delete(argv[i], true);
+          delete(argv[i], true, rmSkipTrash);
         } else if ("-du".equals(cmd)) {
           du(argv[i]);
         } else if ("-dus".equals(cmd)) {
@@ -1629,8 +1648,8 @@
       System.err.println("           [" + Count.USAGE + "]");
       System.err.println("           [-mv <src> <dst>]");
       System.err.println("           [-cp <src> <dst>]");
-      System.err.println("           [-rm <path>]");
-      System.err.println("           [-rmr <path>]");
+      System.err.println("           [-rm [-skipTrash] <path>]");
+      System.err.println("           [-rmr [-skipTrash] <path>]");
       System.err.println("           [-expunge]");
       System.err.println("           [-put <localsrc> ... <dst>]");
       System.err.println("           [-copyFromLocal <localsrc> ... <dst>]");

Modified: hadoop/common/branches/branch-0.20/src/docs/src/documentation/content/xdocs/hdfs_shell.xml
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20/src/docs/src/documentation/content/xdocs/hdfs_shell.xml?rev=789878&r1=789877&r2=789878&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20/src/docs/src/documentation/content/xdocs/hdfs_shell.xml
(original)
+++ hadoop/common/branches/branch-0.20/src/docs/src/documentation/content/xdocs/hdfs_shell.xml
Tue Jun 30 19:00:51 2009
@@ -324,10 +324,13 @@
 		<section>
 			<title> rm </title>
 			<p>
-				<code>Usage: hadoop fs -rm URI [URI &#x2026;] </code>
+				<code>Usage: hadoop fs -rm [-skipTrash] URI [URI &#x2026;] </code>
 			</p>
 			<p>
-	   Delete files specified as args. Only deletes non empty directory and files. Refer to
rmr for recursive deletes.<br/>
+	   Delete files specified as args. Only deletes non empty directory and files. If the <code>-skipTrash</code>
option
+	   is specified, the trash, if enabled, will be bypassed and the specified file(s) deleted
immediately.  	This can be
+	   useful when it is necessary to delete files from an over-quota directory.
+	   Refer to rmr for recursive deletes.<br/>
 	   Example:
 	   </p>
 			<ul>
@@ -343,9 +346,12 @@
 		<section>
 			<title> rmr </title>
 			<p>
-				<code>Usage: hadoop fs -rmr URI [URI &#x2026;]</code>
+				<code>Usage: hadoop fs -rmr [-skipTrash] URI [URI &#x2026;]</code>
 			</p>
-			<p>Recursive version of delete.<br/>
+			<p>Recursive version of delete. If the <code>-skipTrash</code> option
+		   is specified, the trash, if enabled, will be bypassed and the specified file(s) deleted
immediately. This can be
+		   useful when it is necessary to delete files from an over-quota directory.<br/>
+
 	   Example:
 	   </p>
 			<ul>

Modified: hadoop/common/branches/branch-0.20/src/test/org/apache/hadoop/fs/TestTrash.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20/src/test/org/apache/hadoop/fs/TestTrash.java?rev=789878&r1=789877&r2=789878&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20/src/test/org/apache/hadoop/fs/TestTrash.java (original)
+++ hadoop/common/branches/branch-0.20/src/test/org/apache/hadoop/fs/TestTrash.java Tue Jun
30 19:00:51 2009
@@ -256,6 +256,64 @@
       assertTrue(val == -1);
       assertTrue(fs.exists(trashRoot));
     }
+    
+    // Verify skip trash option really works
+    
+    // recreate directory and file
+    mkdir(fs, myPath);
+    writeFile(fs, myFile);
+    
+    // Verify that skip trash option really skips the trash for files (rm)
+    {
+      String[] args = new String[3];
+      args[0] = "-rm";
+      args[1] = "-skipTrash";
+      args[2] = myFile.toString();
+      int val = -1;
+      try {
+        // Clear out trash
+        assertEquals(0, shell.run(new String [] { "-expunge" } ));
+
+        val = shell.run(args);
+        
+      }catch (Exception e) {
+        System.err.println("Exception raised from Trash.run " +
+            e.getLocalizedMessage());
+      }
+      
+      assertFalse(fs.exists(trashRoot)); // No new Current should be created
+      assertFalse(fs.exists(myFile));
+      assertTrue(val == 0);
+    }
+    
+    // recreate directory and file
+    mkdir(fs, myPath);
+    writeFile(fs, myFile);
+    
+    // Verify that skip trash option really skips the trash for rmr
+    {
+      String[] args = new String[3];
+      args[0] = "-rmr";
+      args[1] = "-skipTrash";
+      args[2] = myPath.toString();
+
+      int val = -1;
+      try {
+        // Clear out trash
+        assertEquals(0, shell.run(new String [] { "-expunge" } ));
+        
+        val = shell.run(args);
+        
+      }catch (Exception e) {
+        System.err.println("Exception raised from Trash.run " +
+            e.getLocalizedMessage());
+      }
+
+      assertFalse(fs.exists(trashRoot)); // No new Current should be created
+      assertFalse(fs.exists(myPath));
+      assertFalse(fs.exists(myFile));
+      assertTrue(val == 0);
+    }
   }
 
   public static void trashNonDefaultFS(Configuration conf) throws IOException {



Mime
View raw message