hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cdoug...@apache.org
Subject svn commit: r668482 - in /hadoop/core/branches/branch-0.18: CHANGES.txt src/core/org/apache/hadoop/fs/Trash.java src/test/org/apache/hadoop/dfs/TestTrash.java
Date Tue, 17 Jun 2008 07:31:17 GMT
Author: cdouglas
Date: Tue Jun 17 00:31:16 2008
New Revision: 668482

URL: http://svn.apache.org/viewvc?rev=668482&view=rev
Log:
HADOOP-3561. Prevent the trash from deleting its parent directories.


Modified:
    hadoop/core/branches/branch-0.18/CHANGES.txt
    hadoop/core/branches/branch-0.18/src/core/org/apache/hadoop/fs/Trash.java
    hadoop/core/branches/branch-0.18/src/test/org/apache/hadoop/dfs/TestTrash.java

Modified: hadoop/core/branches/branch-0.18/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/core/branches/branch-0.18/CHANGES.txt?rev=668482&r1=668481&r2=668482&view=diff
==============================================================================
--- hadoop/core/branches/branch-0.18/CHANGES.txt (original)
+++ hadoop/core/branches/branch-0.18/CHANGES.txt Tue Jun 17 00:31:16 2008
@@ -596,6 +596,9 @@
     HADOOP-3545. Fixes a overflow problem in archives.
     (Mahadev Konar via ddas)
 
+    HADOOP-3561. Prevent the trash from deleting its parent directories.
+    (cdouglas)
+
 Release 0.17.0 - 2008-05-18
 
   INCOMPATIBLE CHANGES

Modified: hadoop/core/branches/branch-0.18/src/core/org/apache/hadoop/fs/Trash.java
URL: http://svn.apache.org/viewvc/hadoop/core/branches/branch-0.18/src/core/org/apache/hadoop/fs/Trash.java?rev=668482&r1=668481&r2=668482&view=diff
==============================================================================
--- hadoop/core/branches/branch-0.18/src/core/org/apache/hadoop/fs/Trash.java (original)
+++ hadoop/core/branches/branch-0.18/src/core/org/apache/hadoop/fs/Trash.java Tue Jun 17 00:31:16
2008
@@ -84,10 +84,17 @@
     if (!fs.exists(path))                         // check that path exists
       throw new FileNotFoundException(path.toString());
 
-    if (path.makeQualified(fs).toString().startsWith(trash.toString())) {
+    String qpath = path.makeQualified(fs).toString();
+
+    if (qpath.startsWith(trash.toString())) {
       return false;                               // already in trash
     }
 
+    if (trash.getParent().toString().startsWith(qpath)) {
+      throw new IOException("Cannot move \"" + path +
+                            "\" to the trash, as it contains the trash");
+    }
+
     Path trashPath = new Path(current, path.getName());
 
     IOException cause = null;

Modified: hadoop/core/branches/branch-0.18/src/test/org/apache/hadoop/dfs/TestTrash.java
URL: http://svn.apache.org/viewvc/hadoop/core/branches/branch-0.18/src/test/org/apache/hadoop/dfs/TestTrash.java?rev=668482&r1=668481&r2=668482&view=diff
==============================================================================
--- hadoop/core/branches/branch-0.18/src/test/org/apache/hadoop/dfs/TestTrash.java (original)
+++ hadoop/core/branches/branch-0.18/src/test/org/apache/hadoop/dfs/TestTrash.java Tue Jun
17 00:31:16 2008
@@ -239,6 +239,22 @@
         assertTrue(val == 0);
         checkTrash(fs, trashRoot, args[1]);
       }
+
+      // attempt to remove parent of trash
+      {
+        String[] args = new String[2];
+        args[0] = "-rmr";
+        args[1] = trashRoot.getParent().getParent().toString();
+        int val = -1;
+        try {
+          val = shell.run(args);
+        } catch (Exception e) {
+          System.err.println("Exception raised from Trash.run " +
+                             e.getLocalizedMessage()); 
+        }
+        assertTrue(val == -1);
+        assertTrue(fs.exists(trashRoot));
+      }
     } finally {
       try {
         fs.close();



Mime
View raw message