]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/modload: in readonly mode, do not read go.mod files missing checksums
authorBryan C. Mills <bcmills@google.com>
Fri, 12 Mar 2021 16:28:05 +0000 (11:28 -0500)
committerBryan C. Mills <bcmills@google.com>
Tue, 16 Mar 2021 13:06:17 +0000 (13:06 +0000)
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>
src/cmd/go/internal/modload/build.go

index 5a151b480244ee3fbcc82666fa5e3a55705c6f0f..b32997d29e2d4c83b5dad728d247a24c5ecdf3c8 100644 (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:]
+                       }
+               }
 
-                       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 {