add an extra check to avoid removing valid files

This commit is contained in:
tibbi 2018-01-28 17:29:15 +01:00
parent 95e5480d03
commit 4e15f047c5

View file

@ -43,8 +43,11 @@ class MediaFetcher(val context: Context) {
Thread { Thread {
val ONE_WEEK = 7 * 24 * 60 * 60 * 1000 val ONE_WEEK = 7 * 24 * 60 * 60 * 1000
if (System.currentTimeMillis() - context.config.lastFileCleanup > ONE_WEEK) { if (System.currentTimeMillis() - context.config.lastFileCleanup > ONE_WEEK) {
media.filter { !File(it.path).exists() }.forEach { media.forEach {
context.deleteFromMediaStore(File(it.path)) val file = File(it.path)
if (!it.path.contains("/.thumbnails") && !file.exists() && file.length() == 0L) {
context.deleteFromMediaStore(file)
}
} }
context.config.lastFileCleanup = System.currentTimeMillis() context.config.lastFileCleanup = System.currentTimeMillis()
} }