func checkToolsAvailability(cfg *config.Config, finder toolsFinder) (version.Number, error) { currentVersion, ok := cfg.AgentVersion() if !ok || currentVersion == version.Zero { return version.Zero, nil } env, err := newEnvirons(cfg) if err != nil { return version.Zero, errors.Annotatef(err, "cannot make environ") } // finder receives major and minor as parameters as it uses them to filter versions and // only return patches for the passed major.minor (from major.minor.patch). // We'll try the released stream first, then fall back to the current configured stream // if no released tools are found. vers, err := finder(env, currentVersion.Major, currentVersion.Minor, tools.ReleasedStream, coretools.Filter{}) preferredStream := tools.PreferredStream(¤tVersion, cfg.Development(), cfg.AgentStream()) if preferredStream != tools.ReleasedStream && errors.Cause(err) == coretools.ErrNoMatches { vers, err = finder(env, currentVersion.Major, currentVersion.Minor, preferredStream, coretools.Filter{}) } if err != nil { return version.Zero, errors.Annotatef(err, "cannot find available tools") } // Newest also returns a list of the items in this list matching with the // newest version. newest, _ := vers.Newest() return newest, nil }