diff options
author | Jay Conrod <jayconrod@google.com> | 2021-05-24 16:47:45 -0400 |
---|---|---|
committer | Jay Conrod <jayconrod@google.com> | 2021-05-27 20:38:20 +0000 |
commit | 0ece95a0feafe151cadf1346464952bb5c95fab3 (patch) | |
tree | 3d4e9b8e4ca958a4dbd62d202c641047b06f783b /src/cmd/go/internal/modload/init.go | |
parent | cdcd02842da7c004efd023881e3719105209c908 (diff) | |
download | go-0ece95a0feafe151cadf1346464952bb5c95fab3.tar.gz go-0ece95a0feafe151cadf1346464952bb5c95fab3.zip |
cmd/go: don't let 'go mod download' save sums for inconsistent requirements
'go mod download' calls modload.LoadModFile early to find the main
module path in order to validate arguments. LoadModFile may write
go.mod and go.sum to fix formatting and add a go directive. This calls
keepSums, which, in eager mode, loaded the complete module graph in
order to find out what sums are needed to load the complete module
graph. If go.mod requires a lower version of a module than will be
selected later, keepSums causes the sum for that version's go.mod to
be retained, even though it isn't needed later after a consistent
go.mod is written.
This CL fixes keepSums not to load the graph if it hasn't already been
loaded (whether eager or lazy), addressing comments from CL 318629.
For #45332
Change-Id: I20d4404004e4ad335450fd0fd753e7bc0060f702
Reviewed-on: https://go-review.googlesource.com/c/go/+/322369
Trust: Jay Conrod <jayconrod@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Diffstat (limited to 'src/cmd/go/internal/modload/init.go')
-rw-r--r-- | src/cmd/go/internal/modload/init.go | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/cmd/go/internal/modload/init.go b/src/cmd/go/internal/modload/init.go index 86c0db3fe4..ea404b9f78 100644 --- a/src/cmd/go/internal/modload/init.go +++ b/src/cmd/go/internal/modload/init.go @@ -1122,12 +1122,11 @@ func keepSums(ctx context.Context, ld *loader, rs *Requirements, which whichSums } } - if rs.depth == lazy && rs.graph.Load() == nil { - // The main module is lazy and we haven't needed to load the module graph so - // far. Don't incur the cost of loading it now — since we haven't loaded the - // graph, we probably don't have any checksums to contribute to the distant - // parts of the graph anyway. Instead, just request sums for the roots that - // we know about. + if rs.graph.Load() == nil { + // The module graph was not loaded, possibly because the main module is lazy + // or possibly because we haven't needed to load the graph yet. + // Save sums for the root modules (or their replacements), but don't + // incur the cost of loading the graph just to find and retain the sums. for _, m := range rs.rootModules { r := resolveReplacement(m) keep[modkey(r)] = true |