diff --git a/cmd/gen-manifests/main.go b/cmd/gen-manifests/main.go index 47e8b71392..69d2dd4391 100644 --- a/cmd/gen-manifests/main.go +++ b/cmd/gen-manifests/main.go @@ -388,23 +388,6 @@ func save(ms manifest.OSBuildManifest, depsolved map[string]depsolvednf.Depsolve return nil } -func filterRepos(repos []rpmmd.RepoConfig, typeName string) []rpmmd.RepoConfig { - filtered := make([]rpmmd.RepoConfig, 0) - for _, repo := range repos { - if len(repo.ImageTypeTags) == 0 { - filtered = append(filtered, repo) - } else { - for _, tt := range repo.ImageTypeTags { - if tt == typeName { - filtered = append(filtered, repo) - break - } - } - } - } - return filtered -} - func u(s string) string { return strings.ReplaceAll(s, "-", "_") } @@ -510,11 +493,10 @@ func main() { } // get repositories - repos, err := testedRepoRegistry.ReposByArchName(distroName, archName, true) + repos, err := testedRepoRegistry.ReposByImageTypeName(distroName, archName, imgTypeName) if err != nil { panic(fmt.Sprintf("failed to get repositories for %s/%s: %v", distroName, archName, err)) } - repos = filterRepos(repos, imgTypeName) if len(repos) == 0 { fmt.Printf("no repositories defined for %s/%s/%s\n", distroName, archName, imgTypeName) if skipNorepos { diff --git a/pkg/reporegistry/reporegistry.go b/pkg/reporegistry/reporegistry.go index bdf237a8e6..da083b9d9d 100644 --- a/pkg/reporegistry/reporegistry.go +++ b/pkg/reporegistry/reporegistry.go @@ -45,7 +45,7 @@ func NewFromDistrosRepoConfigs(distrosRepoConfigs rpmmd.DistrosRepoConfigs) *Rep // Therefore in general, all common distro-arch-specific repositories are returned for any image type name, // even for non-existing ones. func (r *RepoRegistry) ReposByImageTypeName(distro, arch, imageType string) ([]rpmmd.RepoConfig, error) { - repositories := []rpmmd.RepoConfig{} + var repositories []rpmmd.RepoConfig archRepos, err := r.ReposByArchName(distro, arch, true) if err != nil { @@ -71,16 +71,18 @@ func (r *RepoRegistry) ReposByImageTypeName(distro, arch, imageType string) ([]r return repositories, nil } -// reposByArchName returns a slice of rpmmd.RepoConfig instances, which should be used for building image types for the +// ReposByArchName returns a slice of rpmmd.RepoConfig instances, which should be used for building image types for the // specific architecture and distribution. This includes by default all repositories without any image type tags specified. // Depending on the `includeTagged` argument value, repositories with image type tags set will be added to the returned // slice or not. // // The method does not verify if the given architecture name is actually part of the specific distribution definition. +// +// Note that using ReposByImageTypeName() is most likely what you want to use. func (r *RepoRegistry) ReposByArchName(distro, arch string, includeTagged bool) ([]rpmmd.RepoConfig, error) { - repositories := []rpmmd.RepoConfig{} + var repositories []rpmmd.RepoConfig - archRepos, err := r.DistroHasRepos(distro, arch) + archRepos, err := r.reposByDistroArch(distro, arch) if err != nil { return nil, err } @@ -97,8 +99,8 @@ 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) ([]rpmmd.RepoConfig, error) { +// reposByDistroArch returns the repositories for the distro+arch +func (r *RepoRegistry) reposByDistroArch(distro, arch string) ([]rpmmd.RepoConfig, error) { // compatibility layer to support old repository definition filenames // without a dot to separate major and minor release versions stdDistroName, err := distroidparser.DefaultParser.Standardize(distro) @@ -118,6 +120,12 @@ func (r *RepoRegistry) DistroHasRepos(distro, arch string) ([]rpmmd.RepoConfig, return repos, nil } +// (deprecated) DistroHasRepos is just here for compatbility with weldr which could +// use `ReposByArchName(distro, arch, true)` instead. +func (r *RepoRegistry) DistroHasRepos(distro, arch string) ([]rpmmd.RepoConfig, error) { + return r.reposByDistroArch(distro, arch) +} + // ListDistros returns a list of all distros which have a repository defined // in the registry. func (r *RepoRegistry) ListDistros() []string { diff --git a/pkg/reporegistry/reporegistry_test.go b/pkg/reporegistry/reporegistry_test.go index 3c83cf2d07..e05257d33f 100644 --- a/pkg/reporegistry/reporegistry_test.go +++ b/pkg/reporegistry/reporegistry_test.go @@ -258,16 +258,15 @@ func TestReposByArch(t *testing.T) { func TestInvalidReposByArch(t *testing.T) { rr := getTestingRepoRegistry() - ta := test_distro.TestArch{} - td := test_distro.TestDistro{} + td := test_distro.DistroFactory(test_distro.TestDistro1Name) - repos, err := rr.ReposByArchName(td.Name(), ta.Name(), false) + repos, err := rr.ReposByArchName(td.Name(), "invalid-arch", false) assert.Nil(t, repos) - assert.NotNil(t, err) + assert.EqualError(t, err, `requested repository not found: for distribution "test-distro-1" and architecture "invalid-arch"`) - repos, err = rr.ReposByArchName(td.Name(), ta.Name(), false) + repos, err = rr.ReposByArchName(td.Name(), "invalid-arch", true) assert.Nil(t, repos) - assert.NotNil(t, err) + assert.EqualError(t, err, `requested repository not found: for distribution "test-distro-1" and architecture "invalid-arch"`) } // TestInvalidReposByArchName tests return values from ReposByArchName diff --git a/pkg/rpmmd/repository.go b/pkg/rpmmd/repository.go index 85c6c5dc1c..d450aab8d5 100644 --- a/pkg/rpmmd/repository.go +++ b/pkg/rpmmd/repository.go @@ -9,6 +9,7 @@ import ( "strings" ) +// repository is the presentation of a on-disk repository json file type repository struct { Name string `json:"name"` BaseURL string `json:"baseurl,omitempty"`