@Test public void test() throws IOException { FileSystem fs = mock(FileSystem.class); TestTrash trash = new TestTrash(fs, new Properties(), "user"); Path path1 = new Path("/some/path"); Path path2 = new Path("/some/other/path"); Assert.assertTrue(trash.moveToTrash(path1)); Assert.assertTrue(trash.moveToTrashAsOwner(path2)); System.out.println(Arrays.toString(trash.getDeleteOperations().toArray())); Assert.assertEquals(trash.getDeleteOperations().size(), 2); Assert.assertTrue(trash.getDeleteOperations().get(0).getPath().equals(path1)); Assert.assertNull(trash.getDeleteOperations().get(0).getUser()); Assert.assertTrue(trash.getDeleteOperations().get(1).getPath().equals(path2)); Assert.assertTrue(trash.getDeleteOperations().get(1).getUser().equals("user")); }
@Override public boolean moveToTrash(Path path) throws IOException { Path fullyResolvedPath = path.isAbsolute() ? path : new Path(this.fs.getWorkingDirectory(), path); Path targetPathInTrash = PathUtils.mergePaths(this.trashLocation, fullyResolvedPath); if (!this.fs.exists(targetPathInTrash.getParent())) { this.fs.mkdirs(targetPathInTrash.getParent()); } else if (this.fs.exists(targetPathInTrash)) { targetPathInTrash = targetPathInTrash.suffix("_" + System.currentTimeMillis()); } return this.fs.rename(fullyResolvedPath, targetPathInTrash); }
Trash implements GobblinTrash { @Override public boolean moveToTrash(Path path) throws IOException { Path fullyResolvedPath = path.isAbsolute() ? path : new Path(this.fs.getWorkingDirectory(), path); Path targetPathInTrash = PathUtils.mergePaths(this.trashLocation, fullyResolvedPath); if (!this.fs.exists(targetPathInTrash.getParent())) { this.fs.mkdirs(targetPathInTrash.getParent()); } else if (this.fs.exists(targetPathInTrash)) { targetPathInTrash = targetPathInTrash.suffix("_" + System.currentTimeMillis()); } return this.fs.rename(fullyResolvedPath, targetPathInTrash); } }
Trash implements GobblinTrash { @Override public boolean moveToTrash(Path path) throws IOException { Path fullyResolvedPath = path.isAbsolute() ? path : new Path(this.fs.getWorkingDirectory(), path); Path targetPathInTrash = PathUtils.mergePaths(this.trashLocation, fullyResolvedPath); if (!this.fs.exists(targetPathInTrash.getParent())) { this.fs.mkdirs(targetPathInTrash.getParent()); } else if (this.fs.exists(targetPathInTrash)) { targetPathInTrash = targetPathInTrash.suffix("_" + System.currentTimeMillis()); } return this.fs.rename(fullyResolvedPath, targetPathInTrash); } @Deprecated  Trash(FileSystem fs); @Deprecated  Trash(FileSystem fs, Properties props); protected  Trash(FileSystem fs, Properties props, String user); }
Trash implements GobblinTrash { @Override public boolean moveToTrash(Path path) throws IOException { Path fullyResolvedPath = path.isAbsolute() ? path : new Path(this.fs.getWorkingDirectory(), path); Path targetPathInTrash = PathUtils.mergePaths(this.trashLocation, fullyResolvedPath); if (!this.fs.exists(targetPathInTrash.getParent())) { this.fs.mkdirs(targetPathInTrash.getParent()); } else if (this.fs.exists(targetPathInTrash)) { targetPathInTrash = targetPathInTrash.suffix("_" + System.currentTimeMillis()); } return this.fs.rename(fullyResolvedPath, targetPathInTrash); } @Deprecated  Trash(FileSystem fs); @Deprecated  Trash(FileSystem fs, Properties props); protected  Trash(FileSystem fs, Properties props, String user); Path getTrashLocation(); @Override boolean moveToTrash(Path path); void createTrashSnapshot(); void purgeTrashSnapshots(); }
Trash implements GobblinTrash { @Override public boolean moveToTrash(Path path) throws IOException { Path fullyResolvedPath = path.isAbsolute() ? path : new Path(this.fs.getWorkingDirectory(), path); Path targetPathInTrash = PathUtils.mergePaths(this.trashLocation, fullyResolvedPath); if (!this.fs.exists(targetPathInTrash.getParent())) { this.fs.mkdirs(targetPathInTrash.getParent()); } else if (this.fs.exists(targetPathInTrash)) { targetPathInTrash = targetPathInTrash.suffix("_" + System.currentTimeMillis()); } return this.fs.rename(fullyResolvedPath, targetPathInTrash); } @Deprecated  Trash(FileSystem fs); @Deprecated  Trash(FileSystem fs, Properties props); protected  Trash(FileSystem fs, Properties props, String user); Path getTrashLocation(); @Override boolean moveToTrash(Path path); void createTrashSnapshot(); void purgeTrashSnapshots(); static final String TRASH_LOCATION_KEY; static final String SNAPSHOT_CLEANUP_POLICY_CLASS_KEY; static final String TRASH_SNAPSHOT_PREFIX; static final String TRASH_IDENTIFIER_FILE; static final String DEFAULT_TRASH_DIRECTORY; static final DateTimeFormatter TRASH_SNAPSHOT_NAME_FORMATTER; static final PathFilter TRASH_SNAPSHOT_PATH_FILTER; static final PathFilter TRASH_NOT_SNAPSHOT_PATH_FILTER; }