dnfjson: Adjust cache size info for new layout

The repo id hash directories are now down one level, below a directory
named for the distribution.
This commit is contained in:
Brian C. Lane 2023-03-01 16:25:22 -08:00 committed by Achilleas Koutsou
parent 3481e1d3ba
commit 8f20b550ea
3 changed files with 32 additions and 12 deletions

View file

@ -70,7 +70,15 @@ func newRPMCache(path string, maxSize uint64) *rpmCache {
// updateInfo updates the repoPaths and repoRecency fields of the rpmCache.
func (r *rpmCache) updateInfo() {
cacheEntries, _ := os.ReadDir(r.root)
// Top level of the cache is now used for separate distributions
dirs, _ := os.ReadDir(r.root)
for _, d := range dirs {
r.updateCacheDirInfo(filepath.Join(r.root, d.Name()))
}
}
func (r *rpmCache) updateCacheDirInfo(path string) {
cacheEntries, _ := os.ReadDir(path)
// each repository has multiple cache entries (3 on average), so using the
// number of cacheEntries to allocate the map and ID slice is a high upper
@ -103,7 +111,7 @@ func (r *rpmCache) updateInfo() {
repoIDs = append(repoIDs, repoID)
}
mtime := eInfo.ModTime()
ePath := filepath.Join(r.root, entry.Name())
ePath := filepath.Join(path, entry.Name())
// calculate and add entry size
size, err := dirSize(ePath)
@ -180,17 +188,23 @@ func (r *rpmCache) touchRepo(repoID string, t time.Time) error {
return err
}
// we only touch the top-level directories and files of the cache
cacheEntries, err := os.ReadDir(r.root)
distroDirs, err := os.ReadDir(r.root)
if err != nil {
return err
}
for _, d := range distroDirs {
// we only touch the top-level directories and files of the cache
cacheEntries, err := os.ReadDir(filepath.Join(r.root, d.Name()))
if err != nil {
return err
}
for _, cacheEntry := range cacheEntries {
if repoGlob.Match(cacheEntry.Name()) {
path := filepath.Join(r.root, cacheEntry.Name())
if err := os.Chtimes(path, t, t); err != nil {
return err
for _, cacheEntry := range cacheEntries {
if repoGlob.Match(cacheEntry.Name()) {
path := filepath.Join(r.root, d.Name(), cacheEntry.Name())
if err := os.Chtimes(path, t, t); err != nil {
return err
}
}
}
}

View file

@ -157,8 +157,10 @@ func TestCacheRead(t *testing.T) {
for name, cfg := range testCfgs {
t.Run(name, func(t *testing.T) {
testCacheRoot := t.TempDir()
s := createTestCache(testCacheRoot, cfg)
// Cache is now per-distro, use the name of the config as a distro name
s := createTestCache(filepath.Join(testCacheRoot, name), cfg)
// Cache covers all distros, pass in top directory
cache := newRPMCache(testCacheRoot, 1048576) // 1 MiB, but doesn't matter for this test
nrepos := len(getRepoIDs(cfg))
@ -259,8 +261,12 @@ func TestCacheCleanup(t *testing.T) {
t.Run(name, func(t *testing.T) {
assert := assert.New(t)
testCacheRoot := t.TempDir()
createTestCache(testCacheRoot, cfg.cache)
// Cache is now per-distro, use the name of the config as a distro name
createTestCache(filepath.Join(testCacheRoot, name), cfg.cache)
// Cache covers all distros, pass in top directory
cache := newRPMCache(testCacheRoot, cfg.maxSize)
err := cache.shrink()
assert.NoError(err)

View file

@ -48,7 +48,7 @@ type BaseSolver struct {
// method.
func NewBaseSolver(cacheDir string) *BaseSolver {
return &BaseSolver{
cache: newRPMCache(cacheDir, 524288000), // 500 MiB
cache: newRPMCache(cacheDir, 1024*1024*1024), // 1 GiB
dnfJsonCmd: []string{"/usr/libexec/osbuild-composer/dnf-json"},
resultCache: NewDNFCache(60 * time.Second),
}