Author: cutting Date: Mon Jun 18 15:54:01 2007 New Revision: 548520 URL: http://svn.apache.org/viewvc?view=rev&rev=548520 Log: HADOOP-1207. Fix FsShell's 'rm' command to not stop when one of the named files does not exist. Contributed by Tsz Wo Sze.
Modified: lucene/hadoop/trunk/CHANGES.txt lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/FsShell.java Modified: lucene/hadoop/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/CHANGES.txt?view=diff&rev=548520&r1=548519&r2=548520 ============================================================================== --- lucene/hadoop/trunk/CHANGES.txt (original) +++ lucene/hadoop/trunk/CHANGES.txt Mon Jun 18 15:54:01 2007 @@ -179,6 +179,9 @@ 55. HADOOP-1444. Fix HDFS block id generation to check pending blocks for duplicates. (Dhruba Borthakur via cutting) + 56. HADOOP-1207. Fix FsShell's 'rm' command to not stop when one of + the named files does not exist. (Tsz Wo Sze via cutting) + Release 0.13.0 - 2007-06-08 Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/FsShell.java URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/FsShell.java?view=diff&rev=548520&r1=548519&r2=548520 ============================================================================== --- lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/FsShell.java (original) +++ lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/FsShell.java Mon Jun 18 15:54:01 2007 @@ -18,7 +18,7 @@ package org.apache.hadoop.fs; import java.io.*; -import java.text.*; +import java.util.*; import org.apache.hadoop.conf.*; import org.apache.hadoop.dfs.DistributedFileSystem; @@ -206,10 +206,19 @@ * @see org.apache.hadoop.fs.FileSystem.globPaths */ void cat(String srcf) throws IOException { - Path [] srcs = fs.globPaths(new Path(srcf)); - for(int i=0; i<srcs.length; i++) { - printToStdout(srcs[i]); - } + //cat behavior in Linux + // [~/1207]$ ls ?.txt + // x.txt z.txt + // [~/1207]$ cat x.txt y.txt z.txt + // xxx + // cat: y.txt: No such file or directory + // zzz + + new DelayedExceptionThrowing() { + void process(Path p) throws IOException { + printToStdout(p); + } + }.process(srcf); } /** @@ -571,11 +580,18 @@ * @throws IOException * @see org.apache.hadoop.fs.FileSystem#globPaths(Path) */ - public void delete(String srcf, boolean recursive) throws IOException { - Path [] srcs = fs.globPaths(new Path(srcf)); - for(int i=0; i<srcs.length; i++) { - delete(srcs[i], recursive); - } + public void delete(String srcf, final boolean recursive) 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 + + new DelayedExceptionThrowing() { + void process(Path p) throws IOException { + delete(p, recursive); + } + }.process(srcf); } /* delete a file */ @@ -1091,5 +1107,26 @@ public static void main(String argv[]) throws Exception { int res = new FsShell().doMain(new Configuration(), argv); System.exit(res); + } + + /* + * Accumulate exceptions if there is any. Throw them at last. + */ + private abstract class DelayedExceptionThrowing { + abstract void process(Path p) throws IOException; + + void process(String srcf) throws IOException { + List<IOException> exceptions = new ArrayList<IOException>(); + + for(Path p : fs.globPaths(new Path(srcf))) + try { process(p); } + catch(IOException ioe) { exceptions.add(ioe); } + + if (!exceptions.isEmpty()) + if (exceptions.size() == 1) + throw exceptions.get(0); + else + throw new IOException("Multiple IOExceptions: " + exceptions); + } } }