do not crash if there are no cache files to delete

java.lang.NullPointerException
at org.fdroid.fdroid.Utils.clearOldFiles(Utils.java:347)
at org.fdroid.fdroid.CleanCacheService.onHandleIntent(CleanCacheService.java:51)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:194)
at android.os.HandlerThread.run(HandlerThread.java:60)
This commit is contained in:
Hans-Christoph Steiner 2016-06-21 14:37:31 +02:00
parent 5340fd9350
commit 7f5db2c5b9

View File

@ -343,8 +343,12 @@ public final class Utils {
if (dir == null) {
return;
}
File[] files = dir.listFiles();
if (files == null) {
return;
}
long olderThan = System.currentTimeMillis() - (secondsAgo * 1000L);
for (File f : dir.listFiles()) {
for (File f : files) {
if (f.isDirectory()) {
clearOldFiles(f, olderThan);
f.delete();