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:
parent
a7a1f1ac07
commit
542da40844
1 changed files with 7 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue