1
0
mirror of https://github.com/golang/go synced 2024-11-11 22:50:22 -07:00

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>
This commit is contained in:
Bryan C. Mills 2021-03-12 11:28:05 -05:00
parent 26c32de7c9
commit 120b9eb1c3

View File

@ -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:]
}
}
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
}
}
}
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 {