diff --git a/CHANGELOG.md b/CHANGELOG.md index 801f162a0..865170a01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,9 +10,16 @@ Translations: [简体中文](CHANGELOG_zh.md) # new +core: + +* fix: Fixed a bug that caused REMOVE records to be lost due to disk cache being killed, and + re-initialization did not verify whether the file existed, causing size() + exceptions. [#219](https://github.com/panpf/sketch/issues/219) + animated: -fix: Fixed the bug that the dependency of sketch-animated-heif accidentally included the local test +* fix: Fixed the bug that the dependency of sketch-animated-heif accidentally included the local + test module. [#220](https://github.com/panpf/sketch/issues/220) # 4.0.0-beta01 diff --git a/CHANGELOG_zh.md b/CHANGELOG_zh.md index 517b2541d..9eecf2f2f 100644 --- a/CHANGELOG_zh.md +++ b/CHANGELOG_zh.md @@ -8,9 +8,14 @@ # new +core: + +* fix: 修复磁盘缓存因被杀导致 REMOVE 记录丢失,重新初始化未校验文件是否存在导致 size() 异常的 + bug [#219](https://github.com/panpf/sketch/issues/219) + animated: -fix: 修复 sketch-animated-heif 的依赖中意外的包含了本地测试 module 的 +* fix: 修复 sketch-animated-heif 的依赖中意外的包含了本地测试 module 的 bug [#220](https://github.com/panpf/sketch/issues/220) # 4.0.0-beta01 diff --git a/sketch-core/src/commonMain/kotlin/com/github/panpf/sketch/cache/internal/DiskLruCache.kt b/sketch-core/src/commonMain/kotlin/com/github/panpf/sketch/cache/internal/DiskLruCache.kt index 05f22ea68..abcb3bb03 100644 --- a/sketch-core/src/commonMain/kotlin/com/github/panpf/sketch/cache/internal/DiskLruCache.kt +++ b/sketch-core/src/commonMain/kotlin/com/github/panpf/sketch/cache/internal/DiskLruCache.kt @@ -186,6 +186,7 @@ internal class DiskLruCache( try { readJournal() processJournal() + filterFileNotExistEntry() initialized = true return } catch (_: IOException) { @@ -206,6 +207,17 @@ internal class DiskLruCache( initialized = true } + private fun filterFileNotExistEntry() { + for (entry in lruEntries.values.toTypedArray()) { + if (entry.readable && entry.currentEditor == null && !entry.zombie) { + val allExist = entry.cleanFiles.all { fileSystem.exists(it) } + if (!allExist) { + removeEntry(entry) + } + } + } + } + /** * Reads the journal and initializes [lruEntries]. */