@Test public void testMoveToTrash() throws IOException { TrashTestBase trash = new TrashTestBase(new Properties()); Path pathToDelete = new Path("/path/to/delete"); final List<Pair<Path, Path>> movedPaths = Lists.newArrayList(); when(trash.fs.exists(any(Path.class))).thenReturn(false); when(trash.fs.rename(any(Path.class), any(Path.class))).thenAnswer(new Answer<Boolean>() { @Override public Boolean answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); movedPaths.add(new Pair<Path, Path>((Path) args[0], (Path) args[1])); return true; } }); Assert.assertTrue(trash.trash.moveToTrash(pathToDelete)); verify(trash.fs, times(1)).mkdirs(any(Path.class)); Assert.assertEquals(movedPaths.size(), 1); Assert.assertTrue(movedPaths.get(0).first().equals(pathToDelete)); Assert.assertTrue(movedPaths.get(0).second().toString().endsWith(pathToDelete.toString())); Assert.assertTrue(movedPaths.get(0).second().getParent().getParent().getParent().equals(trash.trash.getTrashLocation())); }
@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; }