You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by sz...@apache.org on 2011/05/24 23:05:15 UTC

svn commit: r1127289 - in /hadoop/common/branches/yahoo-merge: ./ src/contrib/ec2/ src/docs/ src/java/ src/java/org/apache/hadoop/fs/ src/java/org/apache/hadoop/fs/shell/ src/test/core/ src/test/core/org/apache/hadoop/cli/ src/test/core/org/apache/hado...

Author: szetszwo
Date: Tue May 24 21:05:15 2011
New Revision: 1127289

URL: http://svn.apache.org/viewvc?rev=1127289&view=rev
Log:
svn merge -c 1102093 from trunk for HADOOP-7267.

Added:
    hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/fs/shell/Delete.java
      - copied unchanged from r1102093, hadoop/common/trunk/src/java/org/apache/hadoop/fs/shell/Delete.java
Modified:
    hadoop/common/branches/yahoo-merge/   (props changed)
    hadoop/common/branches/yahoo-merge/CHANGES.txt   (contents, props changed)
    hadoop/common/branches/yahoo-merge/src/contrib/ec2/   (props changed)
    hadoop/common/branches/yahoo-merge/src/docs/   (props changed)
    hadoop/common/branches/yahoo-merge/src/java/   (props changed)
    hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/fs/FsShell.java
    hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/fs/shell/FsCommand.java
    hadoop/common/branches/yahoo-merge/src/test/core/   (props changed)
    hadoop/common/branches/yahoo-merge/src/test/core/org/apache/hadoop/cli/testConf.xml
    hadoop/common/branches/yahoo-merge/src/test/core/org/apache/hadoop/fs/TestTrash.java

Propchange: hadoop/common/branches/yahoo-merge/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue May 24 21:05:15 2011
@@ -1,2 +1,2 @@
-/hadoop/common/trunk:1043117,1076296,1078148,1080396,1081598,1082329,1082787-1082788,1084415,1084769,1085043,1085122,1086309,1087159,1087844,1090039,1090485,1091618,1091902,1091970,1092519,1092565,1094750,1095121,1095761,1096522,1096988,1099612,1099633,1100026,1100356,1100369,1100400,1101132,1101199,1101653,1102012,1102068
+/hadoop/common/trunk:1043117,1076296,1078148,1080396,1081598,1082329,1082787-1082788,1084415,1084769,1085043,1085122,1086309,1087159,1087844,1090039,1090485,1091618,1091902,1091970,1092519,1092565,1094750,1095121,1095761,1096522,1096988,1099612,1099633,1100026,1100356,1100369,1100400,1101132,1101199,1101653,1102012,1102068,1102093
 /hadoop/core/branches/branch-0.19/core:713112

Modified: hadoop/common/branches/yahoo-merge/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/yahoo-merge/CHANGES.txt?rev=1127289&r1=1127288&r2=1127289&view=diff
==============================================================================
--- hadoop/common/branches/yahoo-merge/CHANGES.txt (original)
+++ hadoop/common/branches/yahoo-merge/CHANGES.txt Tue May 24 21:05:15 2011
@@ -62,12 +62,15 @@ Trunk (unreleased changes)
     HADOOP-7271. Standardize shell command error messages.  (Daryn Sharp
     via szetszwo)
 
-    HADOOP-7275. Refactor the stat commands to conform to new FsCommand
+    HADOOP-7275. Refactor the stat command to conform to new FsCommand
     class.  (Daryn Sharp via szetszwo)
 
-    HADOOP-7237. Refactor the touchz commands to conform to new FsCommand
+    HADOOP-7237. Refactor the touchz command to conform to new FsCommand
     class.  (Daryn Sharp via szetszwo)
 
+    HADOOP-7267. Refactor the rm/rmr/expunge commands to conform to new
+    FsCommand class.  (Daryn Sharp via szetszwo)
+
   OPTIMIZATIONS
 
   BUG FIXES

Propchange: hadoop/common/branches/yahoo-merge/CHANGES.txt
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue May 24 21:05:15 2011
@@ -1,4 +1,4 @@
-/hadoop/common/trunk/CHANGES.txt:1043117,1076296,1078148,1080396,1081598,1082329,1082787-1082788,1084415,1084769,1085043,1085122,1086309,1087159,1087844,1090039,1090485,1091618,1091902,1091970,1092519,1092565,1092832,1094750,1095121,1095761,1096522,1096988,1099612,1099633,1100026,1100356,1100369,1100400,1101132,1101199,1101653,1102012,1102068
+/hadoop/common/trunk/CHANGES.txt:1043117,1076296,1078148,1080396,1081598,1082329,1082787-1082788,1084415,1084769,1085043,1085122,1086309,1087159,1087844,1090039,1090485,1091618,1091902,1091970,1092519,1092565,1092832,1094750,1095121,1095761,1096522,1096988,1099612,1099633,1100026,1100356,1100369,1100400,1101132,1101199,1101653,1102012,1102068,1102093
 /hadoop/core/branches/branch-0.18/CHANGES.txt:727226
 /hadoop/core/branches/branch-0.19/CHANGES.txt:713112
 /hadoop/core/trunk/CHANGES.txt:776175-785643,785929-786278

Propchange: hadoop/common/branches/yahoo-merge/src/contrib/ec2/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue May 24 21:05:15 2011
@@ -1,3 +1,3 @@
-/hadoop/common/trunk/src/contrib/ec2:1043117,1076296,1078148,1081598,1082329,1082787-1082788,1084415,1084769,1085043,1085122,1086309,1087159,1087844,1090039,1090485,1091618,1091902,1091970,1092519,1092565,1094750,1095121,1095761,1096522,1096988,1099612,1099633,1100026,1100356,1100369,1100400,1101132,1101199,1101653,1102012,1102068
+/hadoop/common/trunk/src/contrib/ec2:1043117,1076296,1078148,1081598,1082329,1082787-1082788,1084415,1084769,1085043,1085122,1086309,1087159,1087844,1090039,1090485,1091618,1091902,1091970,1092519,1092565,1094750,1095121,1095761,1096522,1096988,1099612,1099633,1100026,1100356,1100369,1100400,1101132,1101199,1101653,1102012,1102068,1102093
 /hadoop/core/branches/branch-0.19/core/src/contrib/ec2:713112
 /hadoop/core/trunk/src/contrib/ec2:776175-784663

Propchange: hadoop/common/branches/yahoo-merge/src/docs/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue May 24 21:05:15 2011
@@ -1,2 +1,2 @@
-/hadoop/common/trunk/src/docs:1043117,1076296,1078148,1080396,1081598,1082329,1082787-1082788,1084415,1084769,1085043,1085122,1086309,1087159,1087844,1090039,1090485,1091618,1091902,1091970,1092519,1092565,1094750,1095121,1095761,1096522,1096988,1099612,1099633,1100026,1100356,1100369,1100400,1101132,1101199,1101653,1102012,1102068
+/hadoop/common/trunk/src/docs:1043117,1076296,1078148,1080396,1081598,1082329,1082787-1082788,1084415,1084769,1085043,1085122,1086309,1087159,1087844,1090039,1090485,1091618,1091902,1091970,1092519,1092565,1094750,1095121,1095761,1096522,1096988,1099612,1099633,1100026,1100356,1100369,1100400,1101132,1101199,1101653,1102012,1102068,1102093
 /hadoop/core/branches/branch-0.19/src/docs:713112

Propchange: hadoop/common/branches/yahoo-merge/src/java/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue May 24 21:05:15 2011
@@ -1,3 +1,3 @@
-/hadoop/common/trunk/src/java:1043117,1076296,1078148,1080396,1081598,1082329,1082787-1082788,1084415,1084769,1085043,1085122,1086309,1087159,1087844,1090039,1090485,1091618,1091902,1091970,1092519,1092565,1094750,1095121,1095761,1096522,1096988,1099612,1099633,1100026,1100356,1100369,1100400,1101132,1101199,1101653,1102012,1102068
+/hadoop/common/trunk/src/java:1043117,1076296,1078148,1080396,1081598,1082329,1082787-1082788,1084415,1084769,1085043,1085122,1086309,1087159,1087844,1090039,1090485,1091618,1091902,1091970,1092519,1092565,1094750,1095121,1095761,1096522,1096988,1099612,1099633,1100026,1100356,1100369,1100400,1101132,1101199,1101653,1102012,1102068,1102093
 /hadoop/core/branches/branch-0.19/core/src/java:713112
 /hadoop/core/trunk/src/core:776175-785643,785929-786278

Modified: hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/fs/FsShell.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/fs/FsShell.java?rev=1127289&r1=1127288&r2=1127289&view=diff
==============================================================================
--- hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/fs/FsShell.java (original)
+++ hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/fs/FsShell.java Tue May 24 21:05:15 2011
@@ -637,77 +637,6 @@ public class FsShell extends Configured 
   }
 
   /**
-   * 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, final boolean skipTrash) 
-                                                            throws IOException {
-    //rm behavior in Linux
-    //  [~/1207]$ ls ?.txt
-    //  x.txt  z.txt
-    //  [~/1207]$ rm x.txt y.txt z.txt 
-    //  rm: cannot remove `y.txt': No such file or directory
-
-    Path srcPattern = new Path(srcf);
-    new DelayedExceptionThrowing() {
-      @Override
-      void process(Path p, FileSystem srcFs) throws IOException {
-        delete(p, srcFs, recursive, skipTrash);
-      }
-    }.globAndProcess(srcPattern, srcPattern.getFileSystem(getConf()));
-  }
-    
-  /* delete a file */
-  private void delete(Path src, FileSystem srcFs, boolean recursive, 
-                      boolean skipTrash) throws IOException {
-    FileStatus fs = null;
-    try {
-      fs = srcFs.getFileStatus(src);
-    } catch (FileNotFoundException fnfe) {
-      // Have to re-throw so that console output is as expected
-      throw new PathNotFoundException(src.toString());
-    }
-    
-    if (fs.isDirectory() && !recursive) {
-      throw new IOException("Cannot remove directory \"" + src +
-                            "\", use -rmr instead");
-    }
-    
-    if(!skipTrash) {
-      try {
-        if (Trash.moveToAppropriateTrash(srcFs, src, getConf())) {
-          System.out.println("Moved to trash: " + src);
-          return;
-        }
-      } catch (IOException e) {
-        LOG.debug("Error with trash", e);
-        Exception cause = (Exception) e.getCause();
-        String msg = "";
-        if(cause != null) {
-          msg = cause.getLocalizedMessage();
-        }
-        System.err.println("Problem with Trash." + msg +". Consider using -skipTrash option");        
-        throw e;
-      }
-    }
-    
-    if (srcFs.delete(src, true)) {
-      System.out.println("Deleted " + src);
-    } else {
-      throw new IOException("Delete failed " + src);
-    }
-  }
-
-  private void expunge() throws IOException {
-    getTrash().expunge();
-    getTrash().checkpoint();
-  }
-
-  /**
    * Returns the Trash object associated with this shell.
    */
   public Path getCurrentTrashDir() throws IOException {
@@ -736,8 +665,8 @@ public class FsShell extends Configured 
       "The full syntax is: \n\n" +
       "hadoop fs [-fs <local | file system URI>] [-conf <configuration file>]\n\t" +
       "[-D <property=value>] [-df [<path>]] [-du [-s] [-h] <path>]\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" +
+      "[-dus <path>] [-mv <src> <dst>] [-cp <src> <dst>]\n\t" + 
+      "[-put <localsrc> ... <dst>] [-copyFromLocal <localsrc> ... <dst>]\n\t" +
       "[-moveFromLocal <localsrc> ... <dst>] [" + 
       GET_SHORT_USAGE + "\n\t" +
       "[" + COPYTOLOCAL_SHORT_USAGE + "] [-moveToLocal <src> <localdst>]\n\t" +
@@ -786,16 +715,6 @@ public class FsShell extends Configured 
       "\t\tdestination.  When copying multiple files, the destination\n" +
       "\t\tmust be a directory. \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";
 
@@ -818,8 +737,6 @@ public class FsShell extends Configured 
     String test = "-test -[ezd] <path>: If file { exists, has zero length, is a directory\n" +
       "\t\tthen return 0, else return 1.\n";
 
-    String expunge = "-expunge: Empty the Trash.\n";
-    
     String help = "-help [cmd]: \tDisplays help for given command or all commands if none\n" +
       "\t\tis specified.\n";
 
@@ -838,12 +755,6 @@ public class FsShell extends Configured 
       System.out.println(du);
     } else if ("dus".equals(cmd)) {
       System.out.println(dus);
-    } else if ("rm".equals(cmd)) {
-      System.out.println(rm);
-    } else if ("expunge".equals(cmd)) {
-      System.out.println(expunge);
-    } else if ("rmr".equals(cmd)) {
-      System.out.println(rmr);
     } else if ("mv".equals(cmd)) {
       System.out.println(mv);
     } else if ("cp".equals(cmd)) {
@@ -880,8 +791,6 @@ public class FsShell extends Configured 
       System.out.println(dus);
       System.out.println(mv);
       System.out.println(cp);
-      System.out.println(rm);
-      System.out.println(rmr);
       System.out.println(put);
       System.out.println(copyFromLocal);
       System.out.println(moveFromLocal);
@@ -921,14 +830,6 @@ public class FsShell extends Configured 
   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
@@ -938,11 +839,7 @@ public class FsShell extends Configured 
         //
         // issue the command to the fs
         //
-        if ("-rm".equals(cmd)) {
-          delete(argv[i], false, rmSkipTrash);
-        } else if ("-rmr".equals(cmd)) {
-          delete(argv[i], true, rmSkipTrash);
-        } else if ("-df".equals(cmd)) {
+        if ("-df".equals(cmd)) {
           df(argv[i]);
         }
       } catch (IOException e) {
@@ -979,9 +876,6 @@ public class FsShell extends Configured 
     } else if ("-df".equals(cmd) ) {
       System.err.println("Usage: java FsShell" +
                          " [" + cmd + " [<path>]]");
-    } else if ("-rm".equals(cmd) || "-rmr".equals(cmd)) {
-      System.err.println("Usage: java FsShell [" + cmd + 
-                           " [-skipTrash] <src>]");
     } else if ("-mv".equals(cmd) || "-cp".equals(cmd)) {
       System.err.println("Usage: java FsShell" + 
                          " [" + cmd + " <src> <dst>]");
@@ -1006,9 +900,6 @@ public class FsShell extends Configured 
       System.err.println("           [-dus <path>]");
       System.err.println("           [-mv <src> <dst>]");
       System.err.println("           [-cp <src> <dst>]");
-      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>]");
       System.err.println("           [-moveFromLocal <localsrc> ... <dst>]");
@@ -1064,11 +955,6 @@ public class FsShell extends Configured 
         printUsage(cmd);
         return exitCode;
       }
-    } else if ("-rm".equals(cmd) || "-rmr".equals(cmd)) {
-      if (argv.length < 2) {
-        printUsage(cmd);
-        return exitCode;
-      }
     }
     // initialize FsShell
     try {
@@ -1117,12 +1003,6 @@ public class FsShell extends Configured 
         exitCode = rename(argv, getConf());
       } else if ("-cp".equals(cmd)) {
         exitCode = copy(argv, getConf());
-      } else if ("-rm".equals(cmd)) {
-        exitCode = doall(cmd, argv, i);
-      } else if ("-rmr".equals(cmd)) {
-        exitCode = doall(cmd, argv, i);
-      } else if ("-expunge".equals(cmd)) {
-        expunge();
       } else if ("-df".equals(cmd)) {
         if (argv.length-1 > 0) {
           exitCode = doall(cmd, argv, i);

Modified: hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/fs/shell/FsCommand.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/fs/shell/FsCommand.java?rev=1127289&r1=1127288&r2=1127289&view=diff
==============================================================================
--- hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/fs/shell/FsCommand.java (original)
+++ hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/fs/shell/FsCommand.java Tue May 24 21:05:15 2011
@@ -45,6 +45,7 @@ abstract public class FsCommand extends 
   public static void registerCommands(CommandFactory factory) {
     factory.registerCommands(Copy.class);
     factory.registerCommands(Count.class);
+    factory.registerCommands(Delete.class);
     factory.registerCommands(Display.class);
     factory.registerCommands(FsShellPermissions.class);
     factory.registerCommands(Ls.class);

Propchange: hadoop/common/branches/yahoo-merge/src/test/core/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue May 24 21:05:15 2011
@@ -1,3 +1,3 @@
-/hadoop/common/trunk/src/test/core:1043117,1076296,1078148,1080396,1081598,1082329,1082787-1082788,1084415,1084769,1085043,1085122,1086309,1087159,1087844,1090039,1090485,1091618,1091902,1091970,1092519,1092565,1094750,1095121,1095761,1096522,1096988,1099612,1099633,1100026,1100356,1100369,1100400,1101132,1101199,1101653,1102012,1102068
+/hadoop/common/trunk/src/test/core:1043117,1076296,1078148,1080396,1081598,1082329,1082787-1082788,1084415,1084769,1085043,1085122,1086309,1087159,1087844,1090039,1090485,1091618,1091902,1091970,1092519,1092565,1094750,1095121,1095761,1096522,1096988,1099612,1099633,1100026,1100356,1100369,1100400,1101132,1101199,1101653,1102012,1102068,1102093
 /hadoop/core/branches/branch-0.19/core/src/test/core:713112
 /hadoop/core/trunk/src/test/core:776175-785643,785929-786278

Modified: hadoop/common/branches/yahoo-merge/src/test/core/org/apache/hadoop/cli/testConf.xml
URL: http://svn.apache.org/viewvc/hadoop/common/branches/yahoo-merge/src/test/core/org/apache/hadoop/cli/testConf.xml?rev=1127289&r1=1127288&r2=1127289&view=diff
==============================================================================
--- hadoop/common/branches/yahoo-merge/src/test/core/org/apache/hadoop/cli/testConf.xml (original)
+++ hadoop/common/branches/yahoo-merge/src/test/core/org/apache/hadoop/cli/testConf.xml Tue May 24 21:05:15 2011
@@ -299,7 +299,7 @@
       <comparators>
         <comparator>
           <type>RegexpComparator</type>
-          <expected-output>^-rm \[-skipTrash\] &lt;src&gt;:( |\t)*Delete all files that match the specified file pattern.( )*</expected-output>
+          <expected-output>^-rm \[-skipTrash\] &lt;src&gt; \.\.\.:( |\t)*Delete all files that match the specified file pattern.( )*</expected-output>
         </comparator>
         <comparator>
           <type>RegexpComparator</type>
@@ -326,7 +326,7 @@
       <comparators>
         <comparator>
           <type>RegexpComparator</type>
-          <expected-output>^-rmr \[-skipTrash\] &lt;src&gt;:( |\t)*Remove all directories which match the specified file( )*</expected-output>
+          <expected-output>^-rmr \[-skipTrash\] &lt;src&gt; \.\.\.:( |\t)*Remove all directories which match the specified file( )*</expected-output>
         </comparator>
         <comparator>
           <type>RegexpComparator</type>

Modified: hadoop/common/branches/yahoo-merge/src/test/core/org/apache/hadoop/fs/TestTrash.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/yahoo-merge/src/test/core/org/apache/hadoop/fs/TestTrash.java?rev=1127289&r1=1127288&r2=1127289&view=diff
==============================================================================
--- hadoop/common/branches/yahoo-merge/src/test/core/org/apache/hadoop/fs/TestTrash.java (original)
+++ hadoop/common/branches/yahoo-merge/src/test/core/org/apache/hadoop/fs/TestTrash.java Tue May 24 21:05:15 2011
@@ -280,7 +280,7 @@ public class TestTrash extends TestCase 
         System.err.println("Exception raised from Trash.run " +
                            e.getLocalizedMessage());
       }
-      assertTrue(val == -1);
+      assertEquals("exit code", 1, val);
       assertTrue(fs.exists(trashRoot));
     }