From 5d1ce327e0972853dabe87b88c0ac5b1f9cb875c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 7 Oct 2025 09:14:14 +0530 Subject: [PATCH] Ensure adds to disk cache are atomic --- tools/disk_cache/implementation.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/disk_cache/implementation.go b/tools/disk_cache/implementation.go index 0fb7e26c2..910c6b647 100644 --- a/tools/disk_cache/implementation.go +++ b/tools/disk_cache/implementation.go @@ -296,6 +296,9 @@ func (dc *DiskCache) add(key string, items map[string][]byte) (err error) { } changed -= before } else { + // unlink the file so that writing to it does not change a + // previously linked copy created by get() + _ = os.Remove(p) if err = os.WriteFile(p, data, 0o700); err != nil { return }