/** * Delete inactive contents. */ public void deleteInactiveContent() throws PatchingException { List<File> dirs = getInactiveHistory(); if (!dirs.isEmpty()) { for (File dir : dirs) { deleteDir(dir, ALL); } } dirs = getInactiveOverlays(); if (!dirs.isEmpty()) { for (File dir : dirs) { deleteDir(dir, ALL); } } }
/** * Delete inactive contents. */ public void deleteInactiveContent() throws PatchingException { List<File> dirs = getInactiveHistory(); if (!dirs.isEmpty()) { for (File dir : dirs) { deleteDir(dir, ALL); } } dirs = getInactiveOverlays(); if (!dirs.isEmpty()) { for (File dir : dirs) { deleteDir(dir, ALL); } } }
protected static boolean deleteDir(File dir, FilenameFilter filter) { boolean success = true; final File[] files = dir.listFiles(filter); if (files != null) { for (int i = 0; i < files.length; i++) { File f = files[i]; if (f.isDirectory()) { // delete the directory and all of its contents. if (!deleteDir(f, filter)) { success = false; log.debugf("Failed to delete dir: %s", f.getAbsolutePath()); } } // delete each file in the directory else if (!f.delete()) { success = false; log.debugf("Failed to delete file: %s", f.getAbsolutePath()); } } } // finally delete the directory if (!dir.delete()) { success = false; log.debugf("Failed to delete dir: %s", dir.getAbsolutePath()); } return success; }
protected static boolean deleteDir(File dir, FilenameFilter filter) { boolean success = true; final File[] files = dir.listFiles(filter); if (files != null) { for (int i = 0; i < files.length; i++) { File f = files[i]; if (f.isDirectory()) { // delete the directory and all of its contents. if (!deleteDir(f, filter)) { success = false; log.debugf("Failed to delete dir: %s", f.getAbsolutePath()); } } // delete each file in the directory else if (!f.delete()) { success = false; log.debugf("Failed to delete file: %s", f.getAbsolutePath()); } } } // finally delete the directory if (!dir.delete()) { success = false; log.debugf("Failed to delete dir: %s", dir.getAbsolutePath()); } return success; }