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
This commit is contained in:
parent
a02641cfa5
commit
e3b587e56f
|
@ -79,6 +79,8 @@ Trunk (unreleased changes)
|
||||||
HADOOP-7167. Amend previous commit under this JIRA to fix issue on
|
HADOOP-7167. Amend previous commit under this JIRA to fix issue on
|
||||||
cygwin. (todd)
|
cygwin. (todd)
|
||||||
|
|
||||||
|
HADOOP-7175. Add isEnabled() to Trash. (Daryn Sharp via szetszwo)
|
||||||
|
|
||||||
OPTIMIZATIONS
|
OPTIMIZATIONS
|
||||||
|
|
||||||
BUG FIXES
|
BUG FIXES
|
||||||
|
|
|
@ -102,11 +102,18 @@ public class Trash extends Configured {
|
||||||
return new Path(basePath + rmFilePath.toUri().getPath());
|
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.
|
/** Move a file or directory to the current trash directory.
|
||||||
* @return false if the item is already in the trash or trash is disabled
|
* @return false if the item is already in the trash or trash is disabled
|
||||||
*/
|
*/
|
||||||
public boolean moveToTrash(Path path) throws IOException {
|
public boolean moveToTrash(Path path) throws IOException {
|
||||||
if (deletionInterval == 0)
|
if (!isEnabled())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!path.isAbsolute()) // make path absolute
|
if (!path.isAbsolute()) // make path absolute
|
||||||
|
|
|
@ -93,8 +93,14 @@ public class TestTrash extends TestCase {
|
||||||
protected static void trashShell(final FileSystem fs, final Path base)
|
protected static void trashShell(final FileSystem fs, final Path base)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
Configuration conf = new Configuration();
|
Configuration conf = new Configuration();
|
||||||
conf.set(FS_TRASH_INTERVAL_KEY, "10"); // 10 minute
|
|
||||||
conf.set("fs.default.name", fs.getUri().toString());
|
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();
|
FsShell shell = new FsShell();
|
||||||
shell.setConf(conf);
|
shell.setConf(conf);
|
||||||
Path trashRoot = null;
|
Path trashRoot = null;
|
||||||
|
|
Loading…
Reference in New Issue