Skip to content

Commit

Permalink
fix: Fixed a bug that caused REMOVE records to be lost due to disk ca…
Browse files Browse the repository at this point in the history
…che being killed, and re-initialization did not verify whether the file existed, causing size() exceptions. (#219)
  • Loading branch information
panpf committed Nov 11, 2024
1 parent f456c77 commit fed4ec1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion CHANGELOG_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ internal class DiskLruCache(
try {
readJournal()
processJournal()
filterFileNotExistEntry()
initialized = true
return
} catch (_: IOException) {
Expand All @@ -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].
*/
Expand Down

0 comments on commit fed4ec1

Please sign in to comment.