Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions cmd/gen-manifests/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "-", "_")
}
Expand Down Expand Up @@ -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 {
Expand Down
20 changes: 14 additions & 6 deletions pkg/reporegistry/reporegistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand All @@ -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)
Expand All @@ -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)
}

Comment on lines +123 to +128
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So why keep it and not fix the Weldr API to use ReposByArchName()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent point, I should have linked tohttps://github.com/osbuild/osbuild-composer/pull/4910 - sorry for that. Once that is in I can drop this compat wrapper.

// ListDistros returns a list of all distros which have a repository defined
// in the registry.
func (r *RepoRegistry) ListDistros() []string {
Expand Down
11 changes: 5 additions & 6 deletions pkg/reporegistry/reporegistry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/rpmmd/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
Loading