aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modget/get.go
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2020-10-30 12:24:51 -0400
committerBryan C. Mills <bcmills@google.com>2020-11-05 16:46:56 +0000
commit04b5b4f740a34a95a10253a0e34779bb259ec9c4 (patch)
treedb270568beafe25756252ba20239e5189b23a757 /src/cmd/go/internal/modget/get.go
parent40f0359d52e04ed124a8f81e1ef8ac86957dd983 (diff)
downloadgo-04b5b4f740a34a95a10253a0e34779bb259ec9c4.tar.gz
go-04b5b4f740a34a95a10253a0e34779bb259ec9c4.zip
cmd/go/internal/modload: return a module-only result from QueryPattern
This allows a single QueryPattern call to resolve a path that could be either a package or a module. It is important to be able to make a single QueryPattern call — rather than a QueryPattern followed by a Query for the specific module path — to provide appropriate fallback behavior: if the proxy returns package results but does not contain a module result, we don't want to fall back to the next proxy to look for the (probably-nonexistent) module. For #37438 Change-Id: I419b8bb3ab4565f443bb5cee9a8b206f453b9801 Reviewed-on: https://go-review.googlesource.com/c/go/+/266657 Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
Diffstat (limited to 'src/cmd/go/internal/modget/get.go')
-rw-r--r--src/cmd/go/internal/modget/get.go19
1 files changed, 6 insertions, 13 deletions
diff --git a/src/cmd/go/internal/modget/get.go b/src/cmd/go/internal/modget/get.go
index 171c070ab3..6d83af710f 100644
--- a/src/cmd/go/internal/modget/get.go
+++ b/src/cmd/go/internal/modget/get.go
@@ -912,22 +912,15 @@ func getQuery(ctx context.Context, path, vers string, prevM module.Version, forc
// If it turns out to only exist as a module, we can detect the resulting
// PackageNotInModuleError and avoid a second round-trip through (potentially)
// all of the configured proxies.
- results, err := modload.QueryPattern(ctx, path, vers, modload.Selected, allowed)
+ results, modOnly, err := modload.QueryPattern(ctx, path, vers, modload.Selected, allowed)
if err != nil {
- // If the path doesn't contain a wildcard, check whether it was actually a
- // module path instead. If so, return that.
- if !strings.Contains(path, "...") {
- var modErr *modload.PackageNotInModuleError
- if errors.As(err, &modErr) && modErr.Mod.Path == path {
- if modErr.Mod.Version != vers {
- logOncef("go: %s %s => %s", path, vers, modErr.Mod.Version)
- }
- return modErr.Mod, nil
- }
- }
-
return module.Version{}, err
}
+ if len(results) == 0 {
+ // The path doesn't contain a wildcard, but was actually a
+ // module path instead. Return that.
+ return modOnly.Mod, nil
+ }
m := results[0].Mod
if m.Path != path {