List of usage examples for org.apache.hadoop.fs TrashPolicy getCurrentTrashDir
public abstract Path getCurrentTrashDir();
From source file:org.apache.ambari.view.filebrowser.HdfsApi.java
License:Apache License
/** * Trash directory//from w ww.j a v a 2s.co m * @return trash directory * @throws Exception */ public Path getTrashDir() throws Exception { return ugi.doAs(new PrivilegedExceptionAction<Path>() { public Path run() throws IOException { TrashPolicy trashPolicy = TrashPolicy.getInstance(conf, fs, fs.getHomeDirectory()); return trashPolicy.getCurrentTrashDir().getParent(); } }); }
From source file:org.apache.ambari.view.utils.hdfs.HdfsApi.java
License:Apache License
/** * Trash directory//w w w. j a va 2s . co m * @return trash directory * @throws Exception */ public Path getTrashDir() throws Exception { return execute(new PrivilegedExceptionAction<Path>() { public Path run() throws IOException { TrashPolicy trashPolicy = TrashPolicy.getInstance(conf, fs, fs.getHomeDirectory()); return trashPolicy.getCurrentTrashDir().getParent(); } }); }
From source file:org.apache.gobblin.util.HadoopUtilsTest.java
License:Apache License
@Test public void testMoveToTrash() throws IOException { Path hadoopUtilsTestDir = new Path(Files.createTempDir().getAbsolutePath(), "HadoopUtilsTestDir"); Configuration conf = new Configuration(); // Set the time to keep it in trash to 10 minutes. // 0 means object will be deleted instantly. conf.set("fs.trash.interval", "10"); FileSystem fs = FileSystem.getLocal(conf); Trash trash = new Trash(fs, conf); TrashPolicy trashPolicy = TrashPolicy.getInstance(conf, fs, fs.getHomeDirectory()); Path trashPath = trashPolicy.getCurrentTrashDir(); fs.mkdirs(hadoopUtilsTestDir);//from w w w . j av a2 s .c o m Assert.assertTrue(fs.exists(hadoopUtilsTestDir)); trash.moveToTrash(hadoopUtilsTestDir.getParent()); Assert.assertFalse(fs.exists(hadoopUtilsTestDir)); Assert.assertTrue(fs.exists(trashPath)); }