Return-Path: X-Original-To: apmail-hadoop-common-commits-archive@www.apache.org Delivered-To: apmail-hadoop-common-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 523D97444 for ; Tue, 26 Jul 2011 04:57:46 +0000 (UTC) Received: (qmail 15987 invoked by uid 500); 26 Jul 2011 04:57:46 -0000 Delivered-To: apmail-hadoop-common-commits-archive@hadoop.apache.org Received: (qmail 15674 invoked by uid 500); 26 Jul 2011 04:57:37 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: common-dev@hadoop.apache.org Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 15667 invoked by uid 99); 26 Jul 2011 04:57:35 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 26 Jul 2011 04:57:35 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 26 Jul 2011 04:57:32 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id CC77D238890D; Tue, 26 Jul 2011 04:57:10 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1150987 - in /hadoop/common/trunk/common: CHANGES.txt src/java/org/apache/hadoop/fs/shell/Delete.java src/java/org/apache/hadoop/fs/shell/PathExceptions.java src/test/core/org/apache/hadoop/cli/testConf.xml Date: Tue, 26 Jul 2011 04:57:10 -0000 To: common-commits@hadoop.apache.org From: mattf@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110726045710.CC77D238890D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mattf Date: Tue Jul 26 04:57:09 2011 New Revision: 1150987 URL: http://svn.apache.org/viewvc?rev=1150987&view=rev Log: HADOOP-6385. dfs should support -rmdir (was HDFS-639). Contributed by Daryn Sharp. Modified: hadoop/common/trunk/common/CHANGES.txt hadoop/common/trunk/common/src/java/org/apache/hadoop/fs/shell/Delete.java hadoop/common/trunk/common/src/java/org/apache/hadoop/fs/shell/PathExceptions.java hadoop/common/trunk/common/src/test/core/org/apache/hadoop/cli/testConf.xml Modified: hadoop/common/trunk/common/CHANGES.txt URL: http://svn.apache.org/viewvc/hadoop/common/trunk/common/CHANGES.txt?rev=1150987&r1=1150986&r2=1150987&view=diff ============================================================================== --- hadoop/common/trunk/common/CHANGES.txt (original) +++ hadoop/common/trunk/common/CHANGES.txt Tue Jul 26 04:57:09 2011 @@ -60,6 +60,9 @@ Trunk (unreleased changes) HADOOP-7460. Support pluggable trash policies. (Usman Masoon via suresh) + HADOOP-6385. dfs should support -rmdir (was HDFS-639). (Daryn Sharp + via mattf) + IMPROVEMENTS HADOOP-7042. Updates to test-patch.sh to include failed test names and Modified: hadoop/common/trunk/common/src/java/org/apache/hadoop/fs/shell/Delete.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/common/src/java/org/apache/hadoop/fs/shell/Delete.java?rev=1150987&r1=1150986&r2=1150987&view=diff ============================================================================== --- hadoop/common/trunk/common/src/java/org/apache/hadoop/fs/shell/Delete.java (original) +++ hadoop/common/trunk/common/src/java/org/apache/hadoop/fs/shell/Delete.java Tue Jul 26 04:57:09 2011 @@ -27,6 +27,8 @@ import org.apache.hadoop.classification. import org.apache.hadoop.fs.Trash; import org.apache.hadoop.fs.shell.PathExceptions.PathIOException; import org.apache.hadoop.fs.shell.PathExceptions.PathIsDirectoryException; +import org.apache.hadoop.fs.shell.PathExceptions.PathIsNotDirectoryException; +import org.apache.hadoop.fs.shell.PathExceptions.PathIsNotEmptyDirectoryException; /** * Classes that delete paths @@ -34,9 +36,10 @@ import org.apache.hadoop.fs.shell.PathEx @InterfaceAudience.Private @InterfaceStability.Evolving -class Delete extends FsCommand { +class Delete { public static void registerCommands(CommandFactory factory) { factory.addClass(Rm.class, "-rm"); + factory.addClass(Rmdir.class, "-rmdir"); factory.addClass(Rmr.class, "-rmr"); factory.addClass(Expunge.class, "-expunge"); } @@ -44,26 +47,35 @@ class Delete extends FsCommand { /** remove non-directory paths */ public static class Rm extends FsCommand { public static final String NAME = "rm"; - public static final String USAGE = "[-r|-R] [-skipTrash] ..."; + public static final String USAGE = "[-f] [-r|-R] [-skipTrash] ..."; public static final String DESCRIPTION = "Delete all files that match the specified file pattern.\n" + "Equivalent to the Unix command \"rm \"\n" + "-skipTrash option bypasses trash, if enabled, and immediately\n" + "deletes \n" + + " -f If the file does not exist, do not display a diagnostic\n" + + " message or modify the exit status to reflect an error.\n" + " -[rR] Recursively deletes directories"; private boolean skipTrash = false; private boolean deleteDirs = false; + private boolean ignoreFNF = false; @Override protected void processOptions(LinkedList args) throws IOException { CommandFormat cf = new CommandFormat( - 1, Integer.MAX_VALUE, "r", "R", "skipTrash"); + 1, Integer.MAX_VALUE, "f", "r", "R", "skipTrash"); cf.parse(args); + ignoreFNF = cf.getOpt("f"); deleteDirs = cf.getOpt("r") || cf.getOpt("R"); skipTrash = cf.getOpt("skipTrash"); } - + + @Override + protected void processNonexistentPath(PathData item) throws IOException { + if (!ignoreFNF) super.processNonexistentPath(item); + } + @Override protected void processPath(PathData item) throws IOException { if (item.stat.isDirectory() && !deleteDirs) { @@ -112,7 +124,40 @@ class Delete extends FsCommand { return "rm -r"; } } - + + /** remove only empty directories */ + static class Rmdir extends FsCommand { + public static final String NAME = "rmdir"; + public static final String USAGE = + "[--ignore-fail-on-non-empty] ..."; + public static final String DESCRIPTION = + "Removes the directory entry specified by each directory argument,\n" + + "provided it is empty.\n"; + + private boolean ignoreNonEmpty = false; + + protected void processOptions(LinkedList args) throws IOException { + CommandFormat cf = new CommandFormat( + 1, Integer.MAX_VALUE, "-ignore-fail-on-non-empty"); + cf.parse(args); + ignoreNonEmpty = cf.getOpt("-ignore-fail-on-non-empty"); + } + + @Override + protected void processPath(PathData item) throws IOException { + if (!item.stat.isDirectory()) { + throw new PathIsNotDirectoryException(item.toString()); + } + if (item.fs.listStatus(item.path).length == 0) { + if (!item.fs.delete(item.path, false)) { + throw new PathIOException(item.toString()); + } + } else if (!ignoreNonEmpty) { + throw new PathIsNotEmptyDirectoryException(item.toString()); + } + } + } + /** empty the trash */ static class Expunge extends FsCommand { public static final String NAME = "expunge"; Modified: hadoop/common/trunk/common/src/java/org/apache/hadoop/fs/shell/PathExceptions.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/common/src/java/org/apache/hadoop/fs/shell/PathExceptions.java?rev=1150987&r1=1150986&r2=1150987&view=diff ============================================================================== --- hadoop/common/trunk/common/src/java/org/apache/hadoop/fs/shell/PathExceptions.java (original) +++ hadoop/common/trunk/common/src/java/org/apache/hadoop/fs/shell/PathExceptions.java Tue Jul 26 04:57:09 2011 @@ -31,6 +31,7 @@ import org.apache.hadoop.fs.Path; @InterfaceAudience.Private @InterfaceStability.Unstable +@SuppressWarnings("serial") public class PathExceptions { /** EIO */ @@ -165,6 +166,14 @@ public class PathExceptions { } } + /** Generated by rm commands */ + public static class PathIsNotEmptyDirectoryException extends PathExistsException { + /** @param path for the exception */ + public PathIsNotEmptyDirectoryException(String path) { + super(path, "Directory is not empty"); + } + } + /** EACCES */ public static class PathAccessDeniedException extends PathIOException { static final long serialVersionUID = 0L; Modified: hadoop/common/trunk/common/src/test/core/org/apache/hadoop/cli/testConf.xml URL: http://svn.apache.org/viewvc/hadoop/common/trunk/common/src/test/core/org/apache/hadoop/cli/testConf.xml?rev=1150987&r1=1150986&r2=1150987&view=diff ============================================================================== --- hadoop/common/trunk/common/src/test/core/org/apache/hadoop/cli/testConf.xml (original) +++ hadoop/common/trunk/common/src/test/core/org/apache/hadoop/cli/testConf.xml Tue Jul 26 04:57:09 2011 @@ -283,7 +283,7 @@ RegexpComparator - ^-rm \[-r\|-R\] \[-skipTrash\] <src> \.\.\.:( |\t)*Delete all files that match the specified file pattern.( )* + ^-rm \[-f\] \[-r\|-R\] \[-skipTrash\] <src> \.\.\.:( |\t)*Delete all files that match the specified file pattern.( )* RegexpComparator @@ -297,6 +297,37 @@ RegexpComparator ^( |\t)*deletes <src>( )* + + RegexpComparator + ^\s+-f\s+If the file does not exist, do not display a diagnostic + + + RegexpComparator + ^\s+message or modify the exit status to reflect an error\. + + + RegexpComparator + ^\s+-\[rR\]\s+Recursively deletes directories + + + + + + help: help for rmdir + + -help rmdir + + + + + + RegexpComparator + ^-rmdir \[--ignore-fail-on-non-empty\] <dir> \.\.\.:\s+Removes the directory entry specified by each directory argument, + + + RegexpComparator + \s+provided it is empty. +