Skip to content

Commit fa847a1

Browse files
authored
hash: do not salt with Go runtime version (#292)
Currently the cache code, taken directly from the Go internal code, salts every hash with the current Go runtime version. This is appropriate for Go itself but not for here where the cache package is intended for more general use. People that need the hashes to depend on the Go runtime version can explicitly include it as part of the hash.
1 parent 9ee3698 commit fa847a1

File tree

2 files changed

+0
-24
lines changed

2 files changed

+0
-24
lines changed

cache/hash.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"hash"
1212
"io"
1313
"os"
14-
"runtime"
1514
"strings"
1615
"sync"
1716
)
@@ -29,22 +28,6 @@ type Hash struct {
2928
buf *bytes.Buffer // for verify
3029
}
3130

32-
// hashSalt is a salt string added to the beginning of every hash
33-
// created by NewHash. Using the Go version makes sure that different
34-
// versions of the go command (or even different Git commits during
35-
// work on the development branch) do not address the same cache
36-
// entries, so that a bug in one version does not affect the execution
37-
// of other versions. This salt will result in additional ActionID files
38-
// in the cache, but not additional copies of the large output files,
39-
// which are still addressed by unsalted SHA256.
40-
//
41-
// We strip any GOEXPERIMENTs the go tool was built with from this
42-
// version string on the assumption that they shouldn't affect go tool
43-
// execution. This allows bootstrapping to converge faster: dist builds
44-
// go_bootstrap without any experiments, so by stripping experiments
45-
// go_bootstrap and the final go binary will use the same salt.
46-
var hashSalt = []byte(stripExperiment(runtime.Version()))
47-
4831
// stripExperiment strips any GOEXPERIMENT configuration from the Go
4932
// version string.
5033
func stripExperiment(version string) string {
@@ -81,7 +64,6 @@ func NewHash(name string) *Hash {
8164
if debugHash {
8265
fmt.Fprintf(os.Stderr, "HASH[%s]\n", h.name)
8366
}
84-
h.Write(hashSalt)
8567
if verify {
8668
h.buf = new(bytes.Buffer)
8769
}

cache/hash_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@ import (
1111
)
1212

1313
func TestHash(t *testing.T) {
14-
oldSalt := hashSalt
15-
hashSalt = nil
16-
defer func() {
17-
hashSalt = oldSalt
18-
}()
19-
2014
h := NewHash("alice")
2115
h.Write([]byte("hello world"))
2216
sum := fmt.Sprintf("%x", h.Sum())

0 commit comments

Comments
 (0)