Don't crash when the cache is cleared and Clover is running.

Check if the dir exists each time get() is called.
captchafix
Florens Douwes 11 years ago
parent 5a3ff3b517
commit 87d3006908
  1. 18
      Clover/app/src/main/java/org/floens/chan/utils/FileCache.java

@ -24,14 +24,12 @@ public class FileCache {
this.directory = directory;
this.maxSize = maxSize;
if (!directory.exists() && !directory.mkdirs()) {
Logger.e(TAG, "Unable to create file cache dir " + directory.getAbsolutePath());
}
calculateSize();
makeDir();
}
public File get(String key) {
makeDir();
return new File(directory, Integer.toString(key.hashCode()));
}
@ -101,6 +99,16 @@ public class FileCache {
}
}
private void makeDir() {
if (!directory.exists()) {
calculateSize();
if (!directory.mkdirs()) {
Logger.e(TAG, "Unable to create file cache dir " + directory.getAbsolutePath());
}
}
}
private void trim() {
int tries = 0;
while (size > maxSize && tries++ < 10) {

Loading…
Cancel
Save