Skip to content

Commit

Permalink
reporegistry: do not prepend repositories in confPaths
Browse files Browse the repository at this point in the history
This commit breaks the API by changing the confPaths loading
in reporegistry to stop prepending `repositories/`. This makes
it easier to use this interface in e.g. `cmd/build`.

Note that this requires changes in the upstream projecs, notably
osbuild-composer and image-builder-cli.
  • Loading branch information
mvo5 committed Feb 6, 2025
1 parent 3c38093 commit 6191f47
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
5 changes: 4 additions & 1 deletion pkg/reporegistry/reporegistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ type RepoRegistry struct {

// New returns a new RepoRegistry instance with the data loaded from
// the given repoConfigPaths and repoConfigFS instance. The order is
// important here, first the paths are tried, then the FSes
// important here, first the paths are tried, then the FSes.
//
// Note that the confPaths must point directly to the directory with
// the json repo files.
func New(repoConfigPaths []string, repoConfigFS []fs.FS) (*RepoRegistry, error) {
repositories, err := loadAllRepositories(repoConfigPaths, repoConfigFS)
if err != nil {
Expand Down
7 changes: 5 additions & 2 deletions pkg/reporegistry/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func loadAllRepositories(confPaths []string, confFSes []fs.FS) (rpmmd.DistrosRep
var mergedFSes []fs.FS

for _, confPath := range confPaths {
mergedFSes = append(mergedFSes, os.DirFS(filepath.Join(confPath, "repositories")))
mergedFSes = append(mergedFSes, os.DirFS(confPath))
}
mergedFSes = append(mergedFSes, confFSes...)

Expand Down Expand Up @@ -90,9 +90,12 @@ func loadAllRepositoriesFromFS(confPaths []fs.FS) (rpmmd.DistrosRepoConfigs, err
// If there are duplicate distro repositories definitions found in multiple paths, the first
// encounter is preferred. For this reason, the order of paths in the passed list should
// reflect the desired preference.
//
// Note that the confPaths must point directly to the directory with
// the json repo files.
func LoadRepositories(confPaths []string, distro string) (map[string][]rpmmd.RepoConfig, error) {
var repoConfigs map[string][]rpmmd.RepoConfig
path := "/repositories/" + distro + ".json"
path := distro + ".json"

for _, confPath := range confPaths {
var err error
Expand Down
4 changes: 2 additions & 2 deletions pkg/reporegistry/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (

func getConfPaths(t *testing.T) []string {
confPaths := []string{
"./test/confpaths/priority1",
"./test/confpaths/priority2",
"./test/confpaths/priority1/repositories",
"./test/confpaths/priority2/repositories",
}
var absConfPaths []string

Expand Down

0 comments on commit 6191f47

Please sign in to comment.