From 7292dadd5fbbf9b394f047f2207f4de13c8229d0 Mon Sep 17 00:00:00 2001 From: Caleb Morris Date: Thu, 11 Jan 2024 16:23:18 -0700 Subject: [PATCH] [download-cache] Fixed init logic to skip when cache file is missing (#10362) There are several possible causes of the cache file to not exist, including user action. By skipping these couple steps during initialization when the file is missing, a renew action is allowed to start and the cache will rebuild and hopefully work as expected. Simple fix for #10360 --- .../kanade/tachiyomi/data/download/DownloadCache.kt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt index 604745279..b09cca3bc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt @@ -103,12 +103,15 @@ class DownloadCache( scope.launch { rootDownloadsDirLock.withLock { try { - val diskCache = diskCacheFile.inputStream().use { - ProtoBuf.decodeFromByteArray(it.readBytes()) + if (diskCacheFile.exists()) { + val diskCache = diskCacheFile.inputStream().use { + ProtoBuf.decodeFromByteArray(it.readBytes()) + } + rootDownloadsDir = diskCache + lastRenew = System.currentTimeMillis() } - rootDownloadsDir = diskCache - lastRenew = System.currentTimeMillis() } catch (e: Throwable) { + logcat(LogPriority.ERROR, e) { "Failed to initialize disk cache" } diskCacheFile.delete() } }