aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modload/build.go
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2021-03-12 11:28:05 -0500
committerBryan C. Mills <bcmills@google.com>2021-03-16 13:06:17 +0000
commit120b9eb1c38f9b074cd3f284647e0735348fa1f4 (patch)
tree070caa499482582f28dc6155db95d0b481f9ac3a /src/cmd/go/internal/modload/build.go
parent26c32de7c9a6bb54d0144d1cc2f00cc334778cac (diff)
downloadgo-120b9eb1c38f9b074cd3f284647e0735348fa1f4.tar.gz
go-120b9eb1c38f9b074cd3f284647e0735348fa1f4.zip
cmd/go/internal/modload: in readonly mode, do not read go.mod files missing checksums
This was causing test failures while revising CL 293689: splitting the roots out from the rest of the module graph may allow 'go list -e' to proceed even when the rest of the module graph can't be loaded (e.g. due to missing go.mod checksums). If that occurs, it becomes more important that the moduleInfo helper function itself avoid fetching unchecked files. For #36460 Change-Id: I088509eeb3008cc6e8bfe85a00ec2bf500bf9423 Reviewed-on: https://go-review.googlesource.com/c/go/+/301371 Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
Diffstat (limited to 'src/cmd/go/internal/modload/build.go')
-rw-r--r--src/cmd/go/internal/modload/build.go40
1 files changed, 26 insertions, 14 deletions
diff --git a/src/cmd/go/internal/modload/build.go b/src/cmd/go/internal/modload/build.go
index 5a151b4802..b32997d29e 100644
--- a/src/cmd/go/internal/modload/build.go
+++ b/src/cmd/go/internal/modload/build.go
@@ -168,7 +168,10 @@ func moduleInfo(ctx context.Context, m module.Version, fromBuildList, listRetrac
// completeFromModCache fills in the extra fields in m using the module cache.
completeFromModCache := func(m *modinfo.ModulePublic) {
- mod := module.Version{Path: m.Path, Version: m.Version}
+ checksumOk := func(suffix string) bool {
+ return !fromBuildList || m.Version == "" || cfg.BuildMod == "mod" ||
+ modfetch.HaveSum(module.Version{Path: m.Path, Version: m.Version + suffix})
+ }
if m.Version != "" {
if q, err := Query(ctx, m.Path, m.Version, "", nil); err != nil {
@@ -177,28 +180,37 @@ func moduleInfo(ctx context.Context, m module.Version, fromBuildList, listRetrac
m.Version = q.Version
m.Time = &q.Time
}
+ }
+ mod := module.Version{Path: m.Path, Version: m.Version}
+
+ if m.GoVersion == "" && checksumOk("/go.mod") {
+ // Load the go.mod file to determine the Go version, since it hasn't
+ // already been populated from rawGoVersion.
+ if summary, err := rawGoModSummary(mod); err == nil && summary.goVersionV != "" {
+ m.GoVersion = summary.goVersionV[1:]
+ }
+ }
- gomod, err := modfetch.CachePath(mod, "mod")
- if err == nil {
- if info, err := os.Stat(gomod); err == nil && info.Mode().IsRegular() {
- m.GoMod = gomod
+ if m.Version != "" {
+ if checksumOk("/go.mod") {
+ gomod, err := modfetch.CachePath(mod, "mod")
+ if err == nil {
+ if info, err := os.Stat(gomod); err == nil && info.Mode().IsRegular() {
+ m.GoMod = gomod
+ }
}
}
- dir, err := modfetch.DownloadDir(mod)
- if err == nil {
- m.Dir = dir
+ if checksumOk("") {
+ dir, err := modfetch.DownloadDir(mod)
+ if err == nil {
+ m.Dir = dir
+ }
}
if listRetracted {
addRetraction(ctx, m)
}
}
-
- if m.GoVersion == "" {
- if summary, err := rawGoModSummary(mod); err == nil && summary.goVersionV != "" {
- m.GoVersion = summary.goVersionV[1:]
- }
- }
}
if !fromBuildList {