Skip to content
Browse files

Updated OnDiskCompressedFile.clearFileCache(..) method to go recursiv…

…ely through sub-directories
  • Loading branch information...
1 parent 3dd8bec commit 3d8439a79c71b403ddc6bad1a2c0eab2ea94c765 Pyry-Samuli Lahti committed Apr 12, 2012
Showing with 22 additions and 6 deletions.
  1. +22 −6 app/press/io/OnDiskCompressedFile.java
View
28 app/press/io/OnDiskCompressedFile.java
@@ -160,18 +160,34 @@ public static int clearFileCache(String compressedDir, String extension) {
return 0;
}
- // Get a list of all compressed files, and delete them
+ int[] deletedCounter = {0};
+ deletePressFilesRecursively(dir.getRealFile(), extension, deletedCounter);
+
+ PressLogger.trace("Deleted %d cached files", deletedCounter[0]);
+ return deletedCounter[0];
+ }
+
+
+ private static void deletePressFilesRecursively(File directory, String extension, int[] deletedCounter) {
+ // First delete compressed Press-files
FileFilter compressedFileFilter = new PressFileFilter(extension);
- File[] files = dir.getRealFile().listFiles(compressedFileFilter);
- int deleted = 0;
+ File[] files = directory.listFiles(compressedFileFilter);
for (File file : files) {
if (file.delete()) {
- deleted++;
+ deletedCounter[0]++;
}
}
- PressLogger.trace("Deleted %d cached files", deleted);
- return deleted;
+ // Second, recursively go through sub-directories
+ FileFilter directoryFilter = new FileFilter() {
+ public boolean accept(File file) {
+ return file.isDirectory();
+ }
+ };
+ File[] subDirectories = directory.listFiles(directoryFilter);
+ for (File subDir : subDirectories) {
+ deletePressFilesRecursively(subDir, extension, deletedCounter);
+ }
}
@Override

0 comments on commit 3d8439a

Please sign in to comment.
Something went wrong with that request. Please try again.