dnfjson: skip deletion if repoID not found in repoElements

If the repoRecency and repoElements somehow become inconsistent (an ID
in repoRecency does not exist in repoElements), ignore and continue.
The repoID will be removed from the repoRecency list at the end as it's
still counted in the nDeleted.
This commit is contained in:
Achilleas Koutsou 2022-06-07 13:25:39 +02:00 committed by Tom Gundersen
parent a7a1f1ac07
commit 542da40844

View file

@ -136,7 +136,13 @@ func (r *rpmCache) shrink() error {
nDeleted := 0
for idx := 0; idx < len(r.repoRecency) && r.size >= r.maxSize; idx++ {
repoID := r.repoRecency[idx]
repo := r.repoElements[repoID]
nDeleted++
repo, ok := r.repoElements[repoID]
if !ok {
// cache inconsistency?
// ignore and let the ID be removed from the recency list
continue
}
for _, gPath := range repo.paths {
if err := os.RemoveAll(gPath); err != nil {
return err
@ -144,7 +150,6 @@ func (r *rpmCache) shrink() error {
}
r.size -= repo.size
delete(r.repoElements, repoID)
nDeleted++
}
// update recency list