diff options
author | Scott Jackson <daneren2005@gmail.com> | 2014-02-11 14:55:46 -0800 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2014-02-11 14:55:46 -0800 |
commit | 48885e5d506a4434b52c7f053e1edf540e573df0 (patch) | |
tree | 936c5ebb8b4d7227567fd8fb7c45187a53756d85 /src | |
parent | 04dea2ee1d7fddf143f6690ab95e71754628e346 (diff) | |
download | dsub-48885e5d506a4434b52c7f053e1edf540e573df0.tar.gz dsub-48885e5d506a4434b52c7f053e1edf540e573df0.tar.bz2 dsub-48885e5d506a4434b52c7f053e1edf540e573df0.zip |
#275 Fix CacheCleaner not using pinned music in used space calculation
Diffstat (limited to 'src')
-rw-r--r-- | src/github/daneren2005/dsub/util/CacheCleaner.java | 23 |
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(); |