Commit 68f49694 authored by Bryan C. Mills's avatar Bryan C. Mills

cmd/go/internal/cache: write shared mutable files atomically

Updates #26794

Change-Id: I2a50e3b756ff6a2bbaee4737ca7ed053b01c8d0e
Reviewed-on: https://go-review.googlesource.com/c/146378Reviewed-by: default avatarRuss Cox <rsc@golang.org>
parent 75a7675e
...@@ -18,6 +18,8 @@ import ( ...@@ -18,6 +18,8 @@ import (
"strconv" "strconv"
"strings" "strings"
"time" "time"
"cmd/go/internal/renameio"
) )
// An ActionID is a cache action key, the hash of a complete description of a // An ActionID is a cache action key, the hash of a complete description of a
...@@ -283,7 +285,9 @@ func (c *Cache) Trim() { ...@@ -283,7 +285,9 @@ func (c *Cache) Trim() {
c.trimSubdir(subdir, cutoff) c.trimSubdir(subdir, cutoff)
} }
ioutil.WriteFile(filepath.Join(c.dir, "trim.txt"), []byte(fmt.Sprintf("%d", now.Unix())), 0666) // Ignore errors from here: if we don't write the complete timestamp, the
// cache will appear older than it is, and we'll trim it again next time.
renameio.WriteFile(filepath.Join(c.dir, "trim.txt"), []byte(fmt.Sprintf("%d", now.Unix())))
} }
// trimSubdir trims a single cache subdirectory. // trimSubdir trims a single cache subdirectory.
...@@ -338,6 +342,8 @@ func (c *Cache) putIndexEntry(id ActionID, out OutputID, size int64, allowVerify ...@@ -338,6 +342,8 @@ func (c *Cache) putIndexEntry(id ActionID, out OutputID, size int64, allowVerify
} }
file := c.fileName(id, "a") file := c.fileName(id, "a")
if err := ioutil.WriteFile(file, entry, 0666); err != nil { if err := ioutil.WriteFile(file, entry, 0666); err != nil {
// TODO(bcmills): This Remove potentially races with another go command writing to file.
// Can we eliminate it?
os.Remove(file) os.Remove(file)
return err return err
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment