fix: concurrent cache save uses unique temp files (#17)

Replace deterministic .index.tmp path with per-save unique temp files
via tempfile::Builder. Eliminates race condition where background
indexer thread and TUI main thread could collide on the same temp path,
causing data truncation or corrupt cache writes.

Changes:
- Add write_cache_atomically() helper using tempfile::Builder
- Refactor save_with_hash() and save() to use the helper
- Extract encode_cache() to deduplicate serialization logic
- Move tempfile from [dev-dependencies] to [dependencies]
- Add 2 concurrent tests validating no corruption under parallel writes

Fixes #17
This commit is contained in:
dailz
2026-06-09 16:13:39 +08:00
parent 0d88e933e6
commit 2cebbd94c4
2 changed files with 115 additions and 36 deletions

View File

@@ -18,7 +18,7 @@ directories.workspace = true
xxhash-rust.workspace = true
bincode.workspace = true
unicode-width.workspace = true
tempfile.workspace = true
[dev-dependencies]
insta.workspace = true
tempfile.workspace = true