dnfjson: use new size-based cache management

- Update timestamps for cache elements whenever a repository is used.
- Call the new `shrink()` function instead of the old `clean()`.
- Remove the old `clean()` function.
This commit is contained in:
Achilleas Koutsou 2022-06-07 13:38:03 +02:00 committed by Tom Gundersen
parent bd2fbee48c
commit 31f7040e05
2 changed files with 21 additions and 12 deletions

View file

@ -48,17 +48,6 @@ func newRPMCache(path string, maxSize uint64) *rpmCache {
return r
}
func (r *rpmCache) clean() error {
curSize, err := dirSize(r.root)
if err != nil {
return err
}
if curSize > r.maxSize {
return os.RemoveAll(r.root)
}
return nil
}
// updateInfo updates the repoPaths and repoRecency fields of the rpmCache.
func (r *rpmCache) updateInfo() {
cacheEntries, _ := os.ReadDir(r.root)

View file

@ -21,6 +21,7 @@ import (
"os"
"os/exec"
"sort"
"time"
"github.com/osbuild/osbuild-composer/internal/rhsm"
"github.com/osbuild/osbuild-composer/internal/rpmmd"
@ -75,8 +76,11 @@ func (bs *BaseSolver) NewWithConfig(modulePlatformID string, releaseVer string,
return s
}
// CleanCache deletes the least recently used repository metadata caches until
// the total size of the cache falls below the configured maximum size (see
// SetMaxCacheSize()).
func (bs *BaseSolver) CleanCache() error {
return bs.cache.clean()
return bs.cache.shrink()
}
// Solver is configured with system information in order to resolve
@ -115,6 +119,14 @@ func (s *Solver) Depsolve(pkgSets []rpmmd.PackageSet) ([]rpmmd.PackageSpec, erro
if err != nil {
return nil, err
}
// touch repos to now
now := time.Now().Local()
for _, r := range repoMap {
// ignore errors
_ = s.cache.touchRepo(r.Hash(), now)
}
s.cache.updateInfo()
var result packageSpecs
if err := json.Unmarshal(output, &result); err != nil {
return nil, err
@ -135,6 +147,14 @@ func (s *Solver) FetchMetadata(repos []rpmmd.RepoConfig) (rpmmd.PackageList, err
return nil, err
}
// touch repos to now
now := time.Now().Local()
for _, r := range repos {
// ignore errors
_ = s.cache.touchRepo(r.Hash(), now)
}
s.cache.updateInfo()
var pkgs rpmmd.PackageList
if err := json.Unmarshal(result, &pkgs); err != nil {
return nil, err