From 9eee0ed4391942c73157c868a9ddcfdef48982f9 Mon Sep 17 00:00:00 2001 From: Jay Conrod Date: Wed, 28 Jul 2021 11:52:14 -0700 Subject: [PATCH] cmd/go: fix go.mod file name printed in error messages for replacements This fixes a logic error introduced in CL 337850. Fixes #47444 Change-Id: I6a49c8fc71fdde4ecb7f2e3329ad1f2cd286b7eb Reviewed-on: https://go-review.googlesource.com/c/go/+/338189 Run-TryBot: Jay Conrod TryBot-Result: Go Bot Reviewed-by: Michael Matloob Trust: Jay Conrod --- src/cmd/go/internal/modload/modfile.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/cmd/go/internal/modload/modfile.go b/src/cmd/go/internal/modload/modfile.go index 6145e8b2f03..03e02e73b63 100644 --- a/src/cmd/go/internal/modload/modfile.go +++ b/src/cmd/go/internal/modload/modfile.go @@ -652,8 +652,8 @@ func rawGoModData(m module.Version) (name string, data []byte, err error) { if !filepath.IsAbs(dir) { dir = filepath.Join(ModRoot(), dir) } - gomod := filepath.Join(dir, "go.mod") - if gomodActual, ok := fsys.OverlayPath(gomod); ok { + name = filepath.Join(dir, "go.mod") + if gomodActual, ok := fsys.OverlayPath(name); ok { // Don't lock go.mod if it's part of the overlay. // On Plan 9, locking requires chmod, and we don't want to modify any file // in the overlay. See #44700. @@ -662,16 +662,17 @@ func rawGoModData(m module.Version) (name string, data []byte, err error) { data, err = lockedfile.Read(gomodActual) } if err != nil { - return gomod, nil, module.VersionError(m, fmt.Errorf("reading %s: %v", base.ShortPath(gomod), err)) + return "", nil, module.VersionError(m, fmt.Errorf("reading %s: %v", base.ShortPath(name), err)) } } else { if !semver.IsValid(m.Version) { // Disallow the broader queries supported by fetch.Lookup. base.Fatalf("go: internal error: %s@%s: unexpected invalid semantic version", m.Path, m.Version) } + name = "go.mod" data, err = modfetch.GoMod(m.Path, m.Version) } - return "go.mod", data, err + return name, data, err } // queryLatestVersionIgnoringRetractions looks up the latest version of the