diff --git a/cmd/osbuild-dnf-json-tests/main.go b/cmd/osbuild-dnf-json-tests/main.go index 38261a12d..4c56b1845 100644 --- a/cmd/osbuild-dnf-json-tests/main.go +++ b/cmd/osbuild-dnf-json-tests/main.go @@ -57,11 +57,12 @@ func TestFetchChecksum(quiet bool, dir string) { if !quiet { log.Println("Running TestFetchChecksum on:", dir) } - c, err := repoCfg.FetchChecksum() + rpmMetadata := rpmmd.NewRPMMD() + _, c, err := rpmMetadata.FetchMetadata([]rpmmd.RepoConfig{repoCfg}, "platform:f31") if err != nil { log.Panic("Failed to fetch checksum:", err) } - if c == "" { + if c["repo"] == "" { log.Panic("The checksum is empty") } if !quiet { diff --git a/internal/mocks/rpmmd/rpmmd_mock.go b/internal/mocks/rpmmd/rpmmd_mock.go index 3bc8fe40e..fabbe7fda 100644 --- a/internal/mocks/rpmmd/rpmmd_mock.go +++ b/internal/mocks/rpmmd/rpmmd_mock.go @@ -30,7 +30,7 @@ func NewRPMMDMock(fixture Fixture) rpmmd.RPMMD { return &rpmmdMock{Fixture: fixture} } -func (r *rpmmdMock) FetchPackageList(repos []rpmmd.RepoConfig, modulePlatformID string) (rpmmd.PackageList, map[string]string, error) { +func (r *rpmmdMock) FetchMetadata(repos []rpmmd.RepoConfig, modulePlatformID string) (rpmmd.PackageList, map[string]string, error) { return r.Fixture.fetchPackageList.ret, r.Fixture.fetchPackageList.checksums, r.Fixture.fetchPackageList.err } diff --git a/internal/rpmmd/repository.go b/internal/rpmmd/repository.go index 2c594b5d0..9175438a0 100644 --- a/internal/rpmmd/repository.go +++ b/internal/rpmmd/repository.go @@ -95,7 +95,13 @@ type PackageInfo struct { } type RPMMD interface { - FetchPackageList(repos []RepoConfig, modulePlatformID string) (PackageList, map[string]string, error) + // FetchMetadata returns all metadata about the repositories we use in the code. Specifically it is a + // list of packages and dictionary of checksums of the repositories. + FetchMetadata(repos []RepoConfig, modulePlatformID string) (PackageList, map[string]string, error) + + // Depsolve takes a list of required content (specs), explicitly unwanted content (excludeSpecs), list + // or repositories, and platform ID for modularity. It returns a list of all packages (with solved + // dependencies) that will be installed into the system. Depsolve(specs, excludeSpecs []string, repos []RepoConfig, modulePlatformID string, clean bool) ([]PackageSpec, map[string]string, error) } @@ -207,7 +213,7 @@ func NewRPMMD() RPMMD { return &rpmmdImpl{} } -func (*rpmmdImpl) FetchPackageList(repos []RepoConfig, modulePlatformID string) (PackageList, map[string]string, error) { +func (*rpmmdImpl) FetchMetadata(repos []RepoConfig, modulePlatformID string) (PackageList, map[string]string, error) { var arguments = struct { Repos []RepoConfig `json:"repos"` ModulePlatformID string `json:"module_platform_id"` @@ -295,27 +301,3 @@ func (pkg *PackageInfo) FillDependencies(rpmmd RPMMD, repos []RepoConfig, module pkg.Dependencies, _, err = rpmmd.Depsolve([]string{pkg.Name}, nil, repos, modulePlatformID, false) return } - -// FetchChecksum returns a repository checksum for given repo config -func (rc *RepoConfig) FetchChecksum() (string, error) { - command := "dump" - arguments := struct { - Repos []RepoConfig `json:"repos"` - }{ - Repos: []RepoConfig{*rc}, - } - output := struct { - Checksums map[string]string `json:"checksums"` - Packages []Package `json:"packages"` - }{} - err := runDNF(command, arguments, &output) - if err != nil { - return "", err - } - checksum, exists := output.Checksums[rc.Id] - if !exists { - // This should never happen unless there is a bug in dnf-json - return "", &RepositoryError{"fatal error, dnf-json did not return required checksum"} - } - return checksum, nil -} diff --git a/internal/store/store.go b/internal/store/store.go index 6b8e0c90d..5f5338628 100644 --- a/internal/store/store.go +++ b/internal/store/store.go @@ -600,13 +600,10 @@ func (s *Store) PushComposeRequest(request common.ComposeRequest) error { } // map( repo-id => checksum ) - checksums := make(map[string]string) - for _, repo := range request.Repositories { - checksum, err := repo.FetchChecksum() - if err != nil { - return err - } - checksums[repo.Id] = checksum + rpmMetadata := rpmmd.NewRPMMD() + _, checksums, err := rpmMetadata.FetchMetadata(request.Repositories, distroStruct.ModulePlatformID()) + if err != nil { + return err } for imageBuildID, imageRequest := range request.RequestedImages { diff --git a/internal/weldr/api.go b/internal/weldr/api.go index 1b1c82a21..47c40a1f9 100644 --- a/internal/weldr/api.go +++ b/internal/weldr/api.go @@ -1839,7 +1839,7 @@ func (api *API) fetchPackageList() (rpmmd.PackageList, error) { repos = append(repos, source.RepoConfig()) } - packages, _, err := api.rpmmd.FetchPackageList(repos, api.distro.ModulePlatformID()) + packages, _, err := api.rpmmd.FetchMetadata(repos, api.distro.ModulePlatformID()) return packages, err }