🟡 [M7] 并发缓存保存共享同一临时文件路径 #17
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
文件:
core/io/index_cache.rs:25-31分类: 并发 / 缓存
问题: 缓存保存使用固定临时路径
dest.with_extension("index.tmp"),并发保存会互相覆盖或竞争 rename。建议修复: 每个写入方使用唯一临时文件名,再 atomic rename。
修复方案
根因:
IndexCache::save_with_hash()和save()使用固定的.index.tmp临时路径,后台索引线程和 TUI 主线程并发调用时File::create截断对方数据。修复: 用
tempfile::Builder为每次 save 创建唯一临时文件,消除路径碰撞。改动: 新增
write_cache_atomically()辅助函数;两个 save 方法统一调用;tempfile移至[dependencies];新增 2 个并发测试。Commit:
2cebbd9