/** * Delete the specified directory, using the trash as available. * * @param conf configuration object * @param path path to delete * * @throws IOException if there's an error deleting the directory. */ public static void deleteDirectory(Configuration conf, Path path) throws IOException { Trash trash = new Trash(path.getFileSystem(conf), conf); try { if (!trash.isEnabled()) { LOG.debug("Trash is not enabled for " + path + " so deleting instead"); FileSystem fs = path.getFileSystem(conf); fs.delete(path, true); } else { boolean removed = trash.moveToTrash(path); if (removed) { LOG.debug("Moved to trash: " + path); } else { LOG.error("Item already in trash: " + path); } } } catch (FileNotFoundException e) { LOG.debug("Attempting to delete non-existent directory " + path); return; } }
/** * Delete the specified directory, using the trash as available. * * @param conf configuration object * @param path path to delete * * @throws IOException if there's an error deleting the directory. */ public static void deleteDirectory(Configuration conf, Path path) throws IOException { Trash trash = new Trash(path.getFileSystem(conf), conf); try { if (!trash.isEnabled()) { LOG.debug("Trash is not enabled for " + path + " so deleting instead"); FileSystem fs = path.getFileSystem(conf); fs.delete(path, true); } else { boolean removed = trash.moveToTrash(path); if (removed) { LOG.debug("Moved to trash: " + path); } else { LOG.error("Item already in trash: " + path); } } } catch (FileNotFoundException e) { LOG.debug("Attempting to delete non-existent directory " + path); return; } }
assertTrue(userTrash.isEnabled()); userTrash.moveToTrash(user1Dir); fail("User2 should not be allowed to move"