From faf8747e3e12e52e82e0f19e3d618da18f2122f0 Mon Sep 17 00:00:00 2001 From: Matthew Foley Date: Wed, 13 Jul 2011 00:35:56 +0000 Subject: [PATCH] HADOOP-7430. Improve error message when moving to trash fails due to quota issue. Contributed by Ravi Prakash. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1145832 13f79535-47bb-0310-9956-ffa450edef68 --- common/CHANGES.txt | 3 +++ .../org/apache/hadoop/fs/shell/Delete.java | 9 ++++++- .../core/org/apache/hadoop/fs/TestTrash.java | 26 +++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/common/CHANGES.txt b/common/CHANGES.txt index 5ff0d025a01..3b9b4355fdb 100644 --- a/common/CHANGES.txt +++ b/common/CHANGES.txt @@ -253,6 +253,9 @@ Trunk (unreleased changes) HADOOP-7361. Provide an option, -overwrite/-f, in put and copyFromLocal shell commands. (Uma Maheswara Rao G via szetszwo) + HADOOP-7430. Improve error message when moving to trash fails due to + quota issue. (Ravi Prakash via mattf) + OPTIMIZATIONS HADOOP-7333. Performance improvement in PureJavaCrc32. (Eric Caspole diff --git a/common/src/java/org/apache/hadoop/fs/shell/Delete.java b/common/src/java/org/apache/hadoop/fs/shell/Delete.java index 8b34afecdf0..5dc849e29be 100644 --- a/common/src/java/org/apache/hadoop/fs/shell/Delete.java +++ b/common/src/java/org/apache/hadoop/fs/shell/Delete.java @@ -18,6 +18,7 @@ package org.apache.hadoop.fs.shell; +import java.io.FileNotFoundException; import java.io.IOException; import java.util.LinkedList; @@ -85,7 +86,13 @@ class Delete extends FsCommand { private boolean moveToTrash(PathData item) throws IOException { boolean success = false; if (!skipTrash) { - success = Trash.moveToAppropriateTrash(item.fs, item.path, getConf()); + try { + success = Trash.moveToAppropriateTrash(item.fs, item.path, getConf()); + } catch(FileNotFoundException fnfe) { + throw fnfe; + } catch (IOException ioe) { + throw new IOException(ioe.getMessage() + ". Consider using -skipTrash option", ioe); + } } return success; } diff --git a/common/src/test/core/org/apache/hadoop/fs/TestTrash.java b/common/src/test/core/org/apache/hadoop/fs/TestTrash.java index 039139d86d5..3f8c645c4fb 100644 --- a/common/src/test/core/org/apache/hadoop/fs/TestTrash.java +++ b/common/src/test/core/org/apache/hadoop/fs/TestTrash.java @@ -20,9 +20,11 @@ package org.apache.hadoop.fs; import static org.apache.hadoop.fs.CommonConfigurationKeys.*; +import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.File; import java.io.IOException; +import java.io.PrintStream; import java.net.URI; import java.util.HashSet; import java.util.Set; @@ -413,6 +415,30 @@ public class TestTrash extends TestCase { assertTrue(count==num_runs); } + //Verify skipTrash option is suggested when rm fails due to its absence + { + String[] args = new String[2]; + args[0] = "-rmr"; + args[1] = "/"; //This always contains trash directory + PrintStream stdout = System.out; + PrintStream stderr = System.err; + ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); + PrintStream newOut = new PrintStream(byteStream); + System.setOut(newOut); + System.setErr(newOut); + try { + shell.run(args); + } catch (Exception e) { + System.err.println("Exception raised from Trash.run " + + e.getLocalizedMessage()); + } + String output = byteStream.toString(); + System.setOut(stdout); + System.setErr(stderr); + assertTrue("skipTrash wasn't suggested as remedy to failed rm command", + output.indexOf(("Consider using -skipTrash option")) != -1 ); + } + } public static void trashNonDefaultFS(Configuration conf) throws IOException {