Author: dhruba
Date: Wed Jan 28 20:15:44 2009
New Revision: 738602
URL: http://svn.apache.org/viewvc?rev=738602&view=rev
Log:
HADOOP-4970. The full path name of a file is preserved inside Trash.
(Prasad Chakka via dhruba)
Modified:
hadoop/core/trunk/CHANGES.txt
hadoop/core/trunk/src/core/org/apache/hadoop/fs/Trash.java
hadoop/core/trunk/src/test/org/apache/hadoop/fs/TestTrash.java
Modified: hadoop/core/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/hadoop/core/trunk/CHANGES.txt?rev=738602&r1=738601&r2=738602&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Wed Jan 28 20:15:44 2009
@@ -130,6 +130,9 @@
HADOOP-4874. Remove LZO codec because of licensing issues. (omalley)
+ HADOOP-4970. The full path name of a file is preserved inside Trash.
+ (Prasad Chakka via dhruba)
+
NEW FEATURES
HADOOP-4575. Add a proxy service for relaying HsftpFileSystem requests.
Modified: hadoop/core/trunk/src/core/org/apache/hadoop/fs/Trash.java
URL:
http://svn.apache.org/viewvc/hadoop/core/trunk/src/core/org/apache/hadoop/fs/Trash.java?rev=738602&r1=738601&r2=738602&view=diff
==============================================================================
--- hadoop/core/trunk/src/core/org/apache/hadoop/fs/Trash.java (original)
+++ hadoop/core/trunk/src/core/org/apache/hadoop/fs/Trash.java Wed Jan 28
20:15:44 2009
@@ -80,6 +80,10 @@
this.current = new Path(trash, CURRENT);
this.interval = conf.getLong("fs.trash.interval", 60) * MSECS_PER_MINUTE;
}
+
+ private Path makeTrashRelativePath(Path basePath, Path rmFilePath) {
+ return new Path(basePath + rmFilePath.toUri().getPath());
+ }
/** Move a file or directory to the current trash directory.
* @return false if the item is already in the trash or trash is disabled
@@ -105,19 +109,20 @@
"\" to the trash, as it contains the trash");
}
- Path trashPath = new Path(current, path.getName());
-
+ Path trashPath = makeTrashRelativePath(current, path);
+ Path baseTrashPath = makeTrashRelativePath(current, path.getParent());
+
IOException cause = null;
// try twice, in case checkpoint between the mkdirs() & rename()
for (int i = 0; i < 2; i++) {
try {
- if (!fs.mkdirs(current, PERMISSION)) { // create current
- LOG.warn("Can't create trash directory: "+current);
+ if (!fs.mkdirs(baseTrashPath, PERMISSION)) { // create current
+ LOG.warn("Can't create trash directory: "+baseTrashPath);
return false;
}
} catch (IOException e) {
- LOG.warn("Can't create trash directory: "+current);
+ LOG.warn("Can't create trash directory: "+baseTrashPath);
return false;
}
try {
Modified: hadoop/core/trunk/src/test/org/apache/hadoop/fs/TestTrash.java
URL:
http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/fs/TestTrash.java?rev=738602&r1=738601&r2=738602&view=diff
==============================================================================
--- hadoop/core/trunk/src/test/org/apache/hadoop/fs/TestTrash.java (original)
+++ hadoop/core/trunk/src/test/org/apache/hadoop/fs/TestTrash.java Wed Jan 28
20:15:44 2009
@@ -57,8 +57,8 @@
// check that the specified file is in Trash
protected static void checkTrash(FileSystem fs, Path trashRoot,
- String pathname) throws IOException {
- Path p = new Path(trashRoot+"/"+new Path(pathname).getName());
+ Path path) throws IOException {
+ Path p = new Path(trashRoot+"/"+ path.toUri().getPath());
assertTrue(fs.exists(p));
}
@@ -106,7 +106,7 @@
{
String[] args = new String[2];
args[0] = "-rm";
- args[1] = new Path(base, "test/mkdirs/myFile").toString();
+ args[1] = myFile.toString();
int val = -1;
try {
val = shell.run(args);
@@ -117,7 +117,7 @@
assertTrue(val == 0);
trashRoot = shell.getCurrentTrashDir();
- checkTrash(fs, trashRoot, args[1]);
+ checkTrash(fs, trashRoot, myFile);
}
// Verify that we can recreate the file
@@ -216,7 +216,7 @@
{
String[] args = new String[2];
args[0] = "-rm";
- args[1] = new Path(base, "test/mkdirs/myFile").toString();
+ args[1] = myFile.toString();
int val = -1;
try {
val = shell.run(args);
@@ -225,11 +225,11 @@
e.getLocalizedMessage());
}
assertTrue(val == 0);
- checkTrash(fs, trashRoot, args[1]);
+ checkTrash(fs, trashRoot, myFile);
args = new String[2];
args[0] = "-rmr";
- args[1] = new Path(base, "test/mkdirs").toString();
+ args[1] = myPath.toString();
val = -1;
try {
val = shell.run(args);
@@ -238,7 +238,7 @@
e.getLocalizedMessage());
}
assertTrue(val == 0);
- checkTrash(fs, trashRoot, args[1]);
+ checkTrash(fs, trashRoot, myPath);
}
// attempt to remove parent of trash
@@ -272,10 +272,10 @@
f = writeFile(lfs, f);
FileSystem.closeAll();
- Trash lTrash =
- new Trash(FileSystem.get(URI.create("file:///"), conf), conf);
+ FileSystem localFs = FileSystem.get(URI.create("file:///"), conf);
+ Trash lTrash = new Trash(localFs, conf);
lTrash.moveToTrash(f.getParent());
- assertTrue(lfs.exists(new Path(lTrash.getCurrentTrashDir(),
"foo/bar")));
+ checkTrash(localFs, lTrash.getCurrentTrashDir(), f);
} finally {
if (lfs.exists(p)) {
lfs.delete(p, true);