/** * Deletes the corresponding objects in repository. */ public void delete(String dirName, String name) throws IOException { if (dirName == null) { if (! new File(dir, name).delete()) baddeleted += 1; } else { File parentDir = new File(dir, dirName); if (! new File(parentDir, name).delete()) baddeleted += 1; deleteDir(parentDir); } nbdeleted += 1; }
/** * Deletes the corresponding objects in repository. */ public void delete(String dirName, String name) throws IOException { if (dirName == null) { if (! new File(dir, name).delete()) baddeleted += 1; } else { File parentDir = new File(dir, dirName); if (! new File(parentDir, name).delete()) baddeleted += 1; deleteDir(parentDir); } nbdeleted += 1; }
/** * Delete the specified directory if it is empty. * Also recursively delete the parent directories if they are empty. */ private final void deleteDir(File dir) { // Check the disk state. It may be false according to the transaction // log but it doesn't matter because directories are lazily created. String[] children = dir.list(); // children may be null if dir doesn't exist any more. if (children != null && children.length == 0) { dir.delete(); if (dir.getAbsolutePath().length() > this.dir.getAbsolutePath().length()) { deleteDir(dir.getParentFile()); } } }
/** * Delete the specified directory if it is empty. * Also recursively delete the parent directories if they are empty. */ private final void deleteDir(File dir) { // Check the disk state. It may be false according to the transaction // log but it doesn't matter because directories are lazily created. String[] children = dir.list(); // children may be null if dir doesn't exist any more. if (children != null && children.length == 0) { dir.delete(); if (dir.getAbsolutePath().length() > this.dir.getAbsolutePath().length()) { deleteDir(dir.getParentFile()); } } }