choose-files: Reject stale preview cache writes

Recheck the path key before updating the cache. Include the inode so a replacement with the same size and modification time gets a different key. Version the key to invalidate previously cached previews.

Retry once when a changed path still resolves to a regular file.
This commit is contained in:
Zhizhen He 2026-11-17 20:47:47 +08:00
parent 24fdd01944
commit bc7d4664d8
6 changed files with 132 additions and 20 deletions

View file

@ -104,11 +104,13 @@ func key_for_path(path, extra_key string) (key string, err error) {
return
}
s, err := os.Stat(resolved_path)
info, err := os.Stat(resolved_path)
if err != nil {
return
}
data := fmt.Sprintf("%s\x00%d\x00%d", resolved_path, s.Size(), s.ModTime().UnixNano())
s := get_file_state(info)
// Version the key so entries written with weaker source validation miss.
data := fmt.Sprintf("v2\x00%s\x00%d\x00%d\x00%d", resolved_path, s.Inode, s.Size, s.ModTime.UnixNano())
if extra_key != "" {
data += "\x00" + extra_key
}