mirror of https://github.com/golang/go.git
cmd/go/internal/cache: write shared mutable files atomically
Updates #26794 Change-Id: I2a50e3b756ff6a2bbaee4737ca7ed053b01c8d0e Reviewed-on: https://go-review.googlesource.com/c/146378 Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
parent
75a7675ed6
commit
68f496949b
|
|
@ -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() {
|
||||||
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
|
||||||
}
|
}
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue