summaryrefslogtreecommitdiff
path: root/libgo/go/cmd/go/internal/modfetch/repo.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/cmd/go/internal/modfetch/repo.go')
-rw-r--r--libgo/go/cmd/go/internal/modfetch/repo.go50
1 files changed, 36 insertions, 14 deletions
diff --git a/libgo/go/cmd/go/internal/modfetch/repo.go b/libgo/go/cmd/go/internal/modfetch/repo.go
index be52a8dc11f..f03bdd8d038 100644
--- a/libgo/go/cmd/go/internal/modfetch/repo.go
+++ b/libgo/go/cmd/go/internal/modfetch/repo.go
@@ -5,7 +5,6 @@
package modfetch
import (
- "errors"
"fmt"
"io"
"os"
@@ -17,9 +16,10 @@ import (
"cmd/go/internal/get"
"cmd/go/internal/modfetch/codehost"
"cmd/go/internal/par"
- "cmd/go/internal/semver"
"cmd/go/internal/str"
web "cmd/go/internal/web"
+
+ "golang.org/x/mod/semver"
)
const traceRepo = false // trace all repo actions, for debugging
@@ -34,7 +34,7 @@ type Repo interface {
// Pseudo-versions are not included.
// Versions should be returned sorted in semver order
// (implementations can use SortVersions).
- Versions(prefix string) (tags []string, err error)
+ Versions(prefix string) ([]string, error)
// Stat returns information about the revision rev.
// A revision can be any identifier known to the underlying service:
@@ -55,7 +55,7 @@ type Repo interface {
// A Rev describes a single revision in a module repository.
type RevInfo struct {
- Version string // version string
+ Version string // suggested version string for this revision
Time time.Time // commit time
// These fields are used for Stat of arbitrary rev,
@@ -214,7 +214,7 @@ func Lookup(proxy, path string) (Repo, error) {
// lookup returns the module with the given module path.
func lookup(proxy, path string) (r Repo, err error) {
if cfg.BuildMod == "vendor" {
- return nil, errModVendor
+ return nil, errLookupDisabled
}
if str.GlobsMatchPath(cfg.GONOPROXY, path) {
@@ -238,22 +238,33 @@ func lookup(proxy, path string) (r Repo, err error) {
}
}
+type lookupDisabledError struct{}
+
+func (lookupDisabledError) Error() string {
+ if cfg.BuildModReason == "" {
+ return fmt.Sprintf("module lookup disabled by -mod=%s", cfg.BuildMod)
+ }
+ return fmt.Sprintf("module lookup disabled by -mod=%s\n\t(%s)", cfg.BuildMod, cfg.BuildModReason)
+}
+
+var errLookupDisabled error = lookupDisabledError{}
+
var (
- errModVendor = errors.New("module lookup disabled by -mod=vendor")
- errProxyOff = notExistError("module lookup disabled by GOPROXY=off")
- errNoproxy error = notExistError("disabled by GOPRIVATE/GONOPROXY")
- errUseProxy error = notExistError("path does not match GOPRIVATE/GONOPROXY")
+ errProxyOff = notExistErrorf("module lookup disabled by GOPROXY=off")
+ errNoproxy error = notExistErrorf("disabled by GOPRIVATE/GONOPROXY")
+ errUseProxy error = notExistErrorf("path does not match GOPRIVATE/GONOPROXY")
)
func lookupDirect(path string) (Repo, error) {
security := web.SecureOnly
- if get.Insecure {
+
+ if allowInsecure(path) {
security = web.Insecure
}
rr, err := get.RepoRootForImportPath(path, get.PreferMod, security)
if err != nil {
// We don't know where to find code for a module with this path.
- return nil, notExistError(err.Error())
+ return nil, notExistError{err: err}
}
if rr.VCS == "mod" {
@@ -292,7 +303,7 @@ func ImportRepoRev(path, rev string) (Repo, *RevInfo, error) {
// version control system, we ignore meta tags about modules
// and use only direct source control entries (get.IgnoreMod).
security := web.SecureOnly
- if get.Insecure {
+ if allowInsecure(path) {
security = web.Insecure
}
rr, err := get.RepoRootForImportPath(path, get.IgnoreMod, security)
@@ -397,11 +408,22 @@ func (l *loggingRepo) Zip(dst io.Writer, version string) error {
}
// A notExistError is like os.ErrNotExist, but with a custom message
-type notExistError string
+type notExistError struct {
+ err error
+}
+
+func notExistErrorf(format string, args ...interface{}) error {
+ return notExistError{fmt.Errorf(format, args...)}
+}
func (e notExistError) Error() string {
- return string(e)
+ return e.err.Error()
}
+
func (notExistError) Is(target error) bool {
return target == os.ErrNotExist
}
+
+func (e notExistError) Unwrap() error {
+ return e.err
+}