From 4c7b52ce2feceedfa6d65ee1972a67afc6e43b71 Mon Sep 17 00:00:00 2001 From: Martin Sehnoutka Date: Thu, 13 Feb 2020 14:12:58 +0100 Subject: [PATCH] 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 --- internal/rpmmd/repository.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/internal/rpmmd/repository.go b/internal/rpmmd/repository.go index 5227a8ee9..2c594b5d0 100644 --- a/internal/rpmmd/repository.go +++ b/internal/rpmmd/repository.go @@ -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 +}