Skip to content

Commit

Permalink
[download-cache] Fixed init logic to skip when cache file is missing …
Browse files Browse the repository at this point in the history
…(#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
  • Loading branch information
CalebMorris authored Jan 11, 2024
1 parent b1067b9 commit 7292dad
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,15 @@ class DownloadCache(
scope.launch {
rootDownloadsDirLock.withLock {
try {
val diskCache = diskCacheFile.inputStream().use {
ProtoBuf.decodeFromByteArray<RootDirectory>(it.readBytes())
if (diskCacheFile.exists()) {
val diskCache = diskCacheFile.inputStream().use {
ProtoBuf.decodeFromByteArray<RootDirectory>(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()
}
}
Expand Down

0 comments on commit 7292dad

Please sign in to comment.