Skip to content

Commit

Permalink
Remove assumption of unique provides
Browse files Browse the repository at this point in the history
  • Loading branch information
Reeto Chatterjee committed Mar 24, 2018
1 parent 21df6b1 commit 51f7b14
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions query.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,7 @@ func hangingPackages(removeOptional bool) (hanging []string, err error) {
// State = 2 - Keep package and have iterated over dependencies
safePackages := make(map[string]uint8)
// provides stores a mapping from the provides name back to the original package name
// Assumption - multiple installed packages don't provide the same dependency
provides := make(map[string]string)
provides := make(map[string]stringSet)
packages := localDb.PkgCache()

// Mark explicit dependencies and enumerate the provides list
Expand All @@ -300,7 +299,13 @@ func hangingPackages(removeOptional bool) (hanging []string, err error) {
}

pkg.Provides().ForEach(func(dep alpm.Depend) error {
provides[dep.Name] = pkg.Name()
if deps, ok := provides[dep.Name]; ok {
deps.set(pkg.Name())
} else {
ss := make(stringSet)
ss.set(pkg.Name())
provides[dep.Name] = ss
}
return nil
})
return nil
Expand All @@ -321,9 +326,13 @@ func hangingPackages(removeOptional bool) (hanging []string, err error) {
state, ok := safePackages[dep.Name]
if !ok {
// Check if dep is a provides rather than actual package name
if p, ok2 := provides[dep.Name]; ok2 {
iterateAgain = true
safePackages[p] = 1
if pset, ok2 := provides[dep.Name]; ok2 {
for p := range pset {
if safePackages[p] == 0 {
iterateAgain = true
safePackages[p] = 1
}
}
}

return nil
Expand Down

0 comments on commit 51f7b14

Please sign in to comment.