reporegistry: Add a DistroHasRepos helper function

This returns the repos and the found flag, useful for testing if a
distro has any valid repos.
This commit is contained in:
Brian C. Lane 2021-06-04 15:22:20 -07:00 committed by Ondřej Budai
parent 963ce1d050
commit fabe0d28d2

View file

@ -96,11 +96,7 @@ func (r *RepoRegistry) ReposByArch(arch distro.Arch, includeTagged bool) ([]rpmm
func (r *RepoRegistry) ReposByArchName(distro, arch string, includeTagged bool) ([]rpmmd.RepoConfig, error) {
repositories := []rpmmd.RepoConfig{}
distroRepos, found := r.repos[distro]
if !found {
return nil, fmt.Errorf("there are no repositories for distribution '%s'", distro)
}
archRepos, found := distroRepos[arch]
archRepos, found := r.DistroHasRepos(distro, arch)
if !found {
return nil, fmt.Errorf("there are no repositories for distribution '%s' and architecture '%s'", distro, arch)
}
@ -116,3 +112,14 @@ func (r *RepoRegistry) ReposByArchName(distro, arch string, includeTagged bool)
return repositories, nil
}
// DistroHasRepos returns the repositories for the distro+arch, and a found flag
func (r *RepoRegistry) DistroHasRepos(distro, arch string) (repos []rpmmd.RepoConfig, found bool) {
distroRepos, found := r.repos[distro]
if !found {
return repos, false
}
repos, found = distroRepos[arch]
return repos, found
}