rpmmd: create fetchchecksum method for repoconfig

this is needed for RCM API because the user will provide only the URL
and we need to fetch the checksum ourselves
This commit is contained in:
Martin Sehnoutka 2020-02-13 14:12:58 +01:00 committed by Tom Gundersen
parent b89475506e
commit 4c7b52ce2f

View file

@ -108,6 +108,14 @@ func (err *DNFError) Error() string {
return fmt.Sprintf("DNF error occured: %s: %s", err.Kind, err.Reason)
}
type RepositoryError struct {
msg string
}
func (re *RepositoryError) Error() string {
return re.msg
}
func LoadRepositories(confPaths []string, distro string) (map[string][]RepoConfig, error) {
var f *os.File
var err error
@ -287,3 +295,27 @@ 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
}