فهرست منبع

svn merge -c 1081598 from trunk for HADOOP-7175.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/yahoo-merge@1125593 13f79535-47bb-0310-9956-ffa450edef68
Tsz-wo Sze 14 سال پیش
والد
کامیت
f32da758ed
3فایلهای تغییر یافته به همراه17 افزوده شده و 2 حذف شده
  1. 2 0
      CHANGES.txt
  2. 8 1
      src/java/org/apache/hadoop/fs/Trash.java
  3. 7 1
      src/test/core/org/apache/hadoop/fs/TestTrash.java

+ 2 - 0
CHANGES.txt

@@ -20,6 +20,8 @@ Trunk (unreleased changes)
     HADOOP-7054 Change NN LoadGenerator to use FileContext APIs
 	(Sanjay Radia)
 
+    HADOOP-7175. Add isEnabled() to Trash.  (Daryn Sharp via szetszwo)
+
   OPTIMIZATIONS
 
   BUG FIXES

+ 8 - 1
src/java/org/apache/hadoop/fs/Trash.java

@@ -121,11 +121,18 @@ public class Trash extends Configured {
     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

+ 7 - 1
src/test/core/org/apache/hadoop/fs/TestTrash.java

@@ -93,8 +93,14 @@ public class TestTrash extends TestCase {
   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;