[download-cache] Fixed init logic to skip when cache file is missing ()

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 

(cherry picked from commit 7292dadd5fbbf9b394f047f2207f4de13c8229d0)
This commit is contained in:
Caleb Morris 2024-01-11 16:23:18 -07:00 committed by Jobobby04
parent f6407805d3
commit 09a18be5b9

@ -103,12 +103,15 @@ class DownloadCache(
scope.launch { scope.launch {
rootDownloadsDirLock.withLock { rootDownloadsDirLock.withLock {
try { try {
if (diskCacheFile.exists()) {
val diskCache = diskCacheFile.inputStream().use { val diskCache = diskCacheFile.inputStream().use {
ProtoBuf.decodeFromByteArray<RootDirectory>(it.readBytes()) ProtoBuf.decodeFromByteArray<RootDirectory>(it.readBytes())
} }
rootDownloadsDir = diskCache rootDownloadsDir = diskCache
lastRenew = System.currentTimeMillis() lastRenew = System.currentTimeMillis()
}
} catch (e: Throwable) { } catch (e: Throwable) {
logcat(LogPriority.ERROR, e) { "Failed to initialize disk cache" }
diskCacheFile.delete() diskCacheFile.delete()
} }
} }