aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/github/daneren2005/dsub/util/CacheCleaner.java23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/github/daneren2005/dsub/util/CacheCleaner.java b/src/github/daneren2005/dsub/util/CacheCleaner.java
index 62204c76..102c1dc9 100644
--- a/src/github/daneren2005/dsub/util/CacheCleaner.java
+++ b/src/github/daneren2005/dsub/util/CacheCleaner.java
@@ -65,7 +65,7 @@ public class CacheCleaner {
}
}
- private long getMinimumDelete(List<File> files) {
+ private long getMinimumDelete(List<File> files, List<File> pinned) {
if(files.size() == 0) {
return 0L;
}
@@ -76,6 +76,9 @@ public class CacheCleaner {
for (File file : files) {
bytesUsedBySubsonic += file.length();
}
+ for (File file : pinned) {
+ bytesUsedBySubsonic += file.length();
+ }
// Ensure that file system is not more than 95% full.
StatFs stat = new StatFs(files.get(0).getPath());
@@ -118,17 +121,19 @@ public class CacheCleaner {
Log.i(TAG, "Deleted : " + Util.formatBytes(bytesDeleted));
}
- private void findCandidatesForDeletion(File file, List<File> files, List<File> dirs) {
+ private void findCandidatesForDeletion(File file, List<File> files, List<File> pinned, List<File> dirs) {
if (file.isFile()) {
String name = file.getName();
boolean isCacheFile = name.endsWith(".partial") || name.contains(".partial.") || name.endsWith(".complete") || name.contains(".complete.");
if (isCacheFile) {
files.add(file);
- }
+ } else {
+ pinned.add(file);
+ }
} else {
// Depth-first
for (File child : FileUtil.listFiles(file)) {
- findCandidatesForDeletion(child, files, dirs);
+ findCandidatesForDeletion(child, files, pinned, dirs);
}
dirs.add(file);
}
@@ -171,14 +176,15 @@ public class CacheCleaner {
try {
List<File> files = new ArrayList<File>();
+ List<File> pinned = new ArrayList<File>();
List<File> dirs = new ArrayList<File>();
- findCandidatesForDeletion(FileUtil.getMusicDirectory(context), files, dirs);
+ findCandidatesForDeletion(FileUtil.getMusicDirectory(context), files, pinned, dirs);
sortByAscendingModificationTime(files);
Set<File> undeletable = findUndeletableFiles();
- deleteFiles(files, undeletable, getMinimumDelete(files), true);
+ deleteFiles(files, undeletable, getMinimumDelete(files, pinned), true);
deleteEmptyDirs(dirs, undeletable);
} catch (RuntimeException x) {
Log.e(TAG, "Error in cache cleaning.", x);
@@ -198,10 +204,11 @@ public class CacheCleaner {
try {
List<File> files = new ArrayList<File>();
+ List<File> pinned = new ArrayList<File>();
List<File> dirs = new ArrayList<File>();
- findCandidatesForDeletion(FileUtil.getMusicDirectory(context), files, dirs);
+ findCandidatesForDeletion(FileUtil.getMusicDirectory(context), files, pinned, dirs);
- long bytesToDelete = getMinimumDelete(files);
+ long bytesToDelete = getMinimumDelete(files, pinned);
if(bytesToDelete > 0L) {
sortByAscendingModificationTime(files);
Set<File> undeletable = findUndeletableFiles();