// (first result). It's possible this module won't provide packages named by
// later arguments, and other modules would. Let's not try to be too
// magical though.
- allowed := modload.CheckAllowed
+ allowed := loaderstate.CheckAllowed
if modload.IsRevisionQuery(firstPath, version) {
// Don't check for retractions if a specific revision is requested.
allowed = nil
func (r *resolver) checkAllowedOr(s *modload.State, requested string, selected func(string) string) modload.AllowedFunc {
return func(ctx context.Context, m module.Version) error {
if m.Version == requested {
- return modload.CheckExclusions(ctx, m)
+ return s.CheckExclusions(ctx, m)
}
if (requested == "upgrade" || requested == "patch") && m.Version == selected(m.Path) {
return nil
}
- return modload.CheckAllowed(ctx, m)
+ return s.CheckAllowed(ctx, m)
}
}
for i := range retractions {
i := i
r.work.Add(func() {
- err := modload.CheckRetractions(loaderstate, ctx, retractions[i].m)
+ err := loaderstate.CheckRetractions(ctx, retractions[i].m)
if _, ok := errors.AsType[*modload.ModuleRetractedError](err); ok {
retractions[i].message = err.Error()
}
return
}
- info, err := Query(loaderstate, ctx, m.Path, "upgrade", m.Version, CheckAllowed)
+ info, err := Query(loaderstate, ctx, m.Path, "upgrade", m.Version, loaderstate.CheckAllowed)
if _, ok := errors.AsType[*NoMatchingVersionError](err); ok ||
errors.Is(err, fs.ErrNotExist) ||
errors.Is(err, ErrDisallowed) {
// Perhaps that doesn't buy us much, though: we would always have to fetch
// all of the version tags to list the available versions anyway.
- allowed := CheckAllowed
+ allowed := loaderstate.CheckAllowed
if listRetracted {
- allowed = CheckExclusions
+ allowed = loaderstate.CheckExclusions
}
v, origin, err := versions(loaderstate, ctx, m.Path, allowed)
if err != nil && m.Error == nil {
return
}
- err := CheckRetractions(loaderstate, ctx, module.Version{Path: m.Path, Version: m.Version})
+ err := loaderstate.CheckRetractions(ctx, module.Version{Path: m.Path, Version: m.Version})
if err == nil {
return
} else if _, ok := errors.AsType[*NoMatchingVersionError](err); ok || errors.Is(err, fs.ErrNotExist) {
return module.Version{}, err
}
- candidates, err := QueryPackages(loaderstate, ctx, path, "latest", mg.Selected, CheckAllowed)
+ candidates, err := QueryPackages(loaderstate, ctx, path, "latest", mg.Selected, loaderstate.CheckAllowed)
if err != nil {
if errors.Is(err, fs.ErrNotExist) {
// Return "cannot find module providing package […]" instead of whatever
}
}
- allowed := CheckAllowed
+ allowed := loaderstate.CheckAllowed
if IsRevisionQuery(path, vers) || mode&ListRetracted != 0 {
// Allow excluded and retracted versions if the user asked for a
// specific revision or used 'go list -retracted'.
// CheckAllowed returns an error equivalent to ErrDisallowed if m is excluded by
// the main module's go.mod or retracted by its author. Most version queries use
// this to filter out versions that should not be used.
-func CheckAllowed(ctx context.Context, m module.Version) error {
- if err := CheckExclusions(ctx, m); err != nil {
+func (s *State) CheckAllowed(ctx context.Context, m module.Version) error {
+ if err := s.CheckExclusions(ctx, m); err != nil {
return err
}
- if err := CheckRetractions(LoaderState, ctx, m); err != nil {
+ if err := s.CheckRetractions(ctx, m); err != nil {
return err
}
return nil
// CheckExclusions returns an error equivalent to ErrDisallowed if module m is
// excluded by the main module's go.mod file.
-func CheckExclusions(ctx context.Context, m module.Version) error {
- for _, mainModule := range LoaderState.MainModules.Versions() {
- if index := LoaderState.MainModules.Index(mainModule); index != nil && index.exclude[m] {
+func (s *State) CheckExclusions(ctx context.Context, m module.Version) error {
+ for _, mainModule := range s.MainModules.Versions() {
+ if index := s.MainModules.Index(mainModule); index != nil && index.exclude[m] {
return module.VersionError(m, errExcluded)
}
}
// CheckRetractions returns an error if module m has been retracted by
// its author.
-func CheckRetractions(loaderstate *State, ctx context.Context, m module.Version) (err error) {
+func (s *State) CheckRetractions(ctx context.Context, m module.Version) (err error) {
defer func() {
if err == nil {
return
// Cannot be retracted.
return nil
}
- if repl := Replacement(loaderstate, module.Version{Path: m.Path}); repl.Path != "" {
+ if repl := Replacement(s, module.Version{Path: m.Path}); repl.Path != "" {
// All versions of the module were replaced.
// Don't load retractions, since we'd just load the replacement.
return nil
// We load the raw file here: the go.mod file may have a different module
// path that we expect if the module or its repository was renamed.
// We still want to apply retractions to other aliases of the module.
- rm, err := queryLatestVersionIgnoringRetractions(loaderstate, ctx, m.Path)
+ rm, err := queryLatestVersionIgnoringRetractions(s, ctx, m.Path)
if err != nil {
return err
}
- summary, err := rawGoModSummary(loaderstate, rm)
+ summary, err := rawGoModSummary(s, rm)
if err != nil && !errors.Is(err, gover.ErrTooNew) {
return err
}
return module.Version{Path: m.Path, Version: "none"}, nil
}
- list, _, err := versions(loaderstate, ctx, m.Path, CheckAllowed)
+ list, _, err := versions(loaderstate, ctx, m.Path, loaderstate.CheckAllowed)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
return module.Version{Path: m.Path, Version: "none"}, nil
ctx := context.Background()
for _, tt := range queryTests {
+ loaderstate := NewState()
allow := tt.allow
if allow == "" {
allow = "*"
t.Run(strings.ReplaceAll(tt.path, "/", "_")+"/"+tt.query+"/"+tt.current+"/"+allow, func(t *testing.T) {
t.Parallel()
- info, err := Query(LoaderState, ctx, tt.path, tt.query, tt.current, allowed)
+ info, err := Query(loaderstate, ctx, tt.path, tt.query, tt.current, allowed)
if tt.err != "" {
if err == nil {
t.Errorf("Query(_, %q, %q, %q, %v) = %v, want error %q", tt.path, tt.query, tt.current, allow, info.Version, tt.err)
// See internal/load.PackagesAndErrorsOutsideModule
ctx := context.Background()
- allowed := modload.CheckAllowed
+ allowed := loaderstate.CheckAllowed
if modload.IsRevisionQuery(path, version) {
// Don't check for retractions if a specific revision is requested.
allowed = nil