var goSum struct {
mu sync.Mutex
- m map[module.Version][]string // content of go.sum file (+ go.modverify if present)
+ m map[module.Version][]string // content of go.sum file
checked map[modSum]bool // sums actually checked during execution
dirty bool // whether we added any new sums to m
overwrite bool // if true, overwrite go.sum without incorporating its contents
enabled bool // whether to use go.sum at all
- modverify string // path to go.modverify, to be deleted
}
// initGoSum initializes the go.sum data.
goSum.enabled = true
readGoSum(goSum.m, GoSumFile, data)
- // Add old go.modverify file.
- // We'll delete go.modverify in WriteGoSum.
- alt := strings.TrimSuffix(GoSumFile, ".sum") + ".modverify"
- if data, err := renameio.ReadFile(alt); err == nil {
- migrate := make(map[module.Version][]string)
- readGoSum(migrate, alt, data)
- for mod, sums := range migrate {
- for _, sum := range sums {
- addModSumLocked(mod, sum)
- }
- }
- goSum.modverify = alt
- }
return true, nil
}
goSum.mu.Lock()
defer goSum.mu.Unlock()
- if !goSum.enabled {
- // If we haven't read the go.sum file yet, don't bother writing it: at best,
- // we could rename the go.modverify file if it isn't empty, but we haven't
- // needed to touch it so far — how important could it be?
- return
- }
- if !goSum.dirty {
- // Don't bother opening the go.sum file if we don't have anything to add.
+ if !goSum.enabled || !goSum.dirty {
+ // If we haven't read go.sum yet or if we don't have anything to add,
+ // don't bother opening it.
return
}
if cfg.BuildMod == "readonly" {
goSum.checked = make(map[modSum]bool)
goSum.dirty = false
goSum.overwrite = false
-
- if goSum.modverify != "" {
- os.Remove(goSum.modverify) // best effort
- }
}
// TrimGoSum trims go.sum to contain only the modules for which keep[m] is true.
! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.1.0.zip
# With bad go.sum, sync (which must download) fails.
-# Even if the bad sum is in the old legacy go.modverify file.
rm go.sum
-cp go.sum.bad go.modverify
+cp go.sum.bad go.sum
! go mod tidy
stderr 'checksum mismatch'
! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.1.0.zip
-# With good go.sum, sync works (and moves go.modverify to go.sum).
+# With good go.sum, sync works.
rm go.sum
-cp go.sum.good go.modverify
+cp go.sum.good go.sum
go mod tidy
exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.1.0.zip
exists $GOPATH/pkg/mod/rsc.io/quote@v1.1.0/quote.go
-! exists go.modverify
# go.sum should have the new checksum for go.mod
grep '^rsc.io/quote v1.1.0/go.mod ' go.sum