From e3b587e56f46a269fc9a7b3115b9ade35945e7cd Mon Sep 17 00:00:00 2001 From: Tsz-wo Sze Date: Mon, 14 Mar 2011 22:42:53 +0000 Subject: [PATCH] HADOOP-7175. Add isEnabled() to Trash. Contributed by Daryn Sharp git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1081598 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 2 ++ src/java/org/apache/hadoop/fs/Trash.java | 9 ++++++++- src/test/core/org/apache/hadoop/fs/TestTrash.java | 8 +++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 7a795cba91..80bb290260 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -79,6 +79,8 @@ Trunk (unreleased changes) HADOOP-7167. Amend previous commit under this JIRA to fix issue on cygwin. (todd) + HADOOP-7175. Add isEnabled() to Trash. (Daryn Sharp via szetszwo) + OPTIMIZATIONS BUG FIXES diff --git a/src/java/org/apache/hadoop/fs/Trash.java b/src/java/org/apache/hadoop/fs/Trash.java index 537c65bc70..1362934556 100644 --- a/src/java/org/apache/hadoop/fs/Trash.java +++ b/src/java/org/apache/hadoop/fs/Trash.java @@ -102,11 +102,18 @@ private Path makeTrashRelativePath(Path basePath, Path rmFilePath) { return new Path(basePath + rmFilePath.toUri().getPath()); } + /** + * Returns whether the trash is enabled for this filesystem + */ + public boolean isEnabled() { + return (deletionInterval != 0); + } + /** Move a file or directory to the current trash directory. * @return false if the item is already in the trash or trash is disabled */ public boolean moveToTrash(Path path) throws IOException { - if (deletionInterval == 0) + if (!isEnabled()) return false; if (!path.isAbsolute()) // make path absolute diff --git a/src/test/core/org/apache/hadoop/fs/TestTrash.java b/src/test/core/org/apache/hadoop/fs/TestTrash.java index b324902c01..5b128120de 100644 --- a/src/test/core/org/apache/hadoop/fs/TestTrash.java +++ b/src/test/core/org/apache/hadoop/fs/TestTrash.java @@ -93,8 +93,14 @@ static void checkNotInTrash(FileSystem fs, Path trashRoot, String pathname) protected static void trashShell(final FileSystem fs, final Path base) throws IOException { Configuration conf = new Configuration(); - conf.set(FS_TRASH_INTERVAL_KEY, "10"); // 10 minute conf.set("fs.default.name", fs.getUri().toString()); + + conf.set(FS_TRASH_INTERVAL_KEY, "0"); // disabled + assertFalse(new Trash(conf).isEnabled()); + + conf.set(FS_TRASH_INTERVAL_KEY, "10"); // 10 minute + assertTrue(new Trash(conf).isEnabled()); + FsShell shell = new FsShell(); shell.setConf(conf); Path trashRoot = null;