Skip to content

Commit

Permalink
Disqualify conflicts with self for packages
Browse files Browse the repository at this point in the history
Previously, we called disqualifyConflicts to disqualify any packages
that would conflict with whatever package we selected. This made it
possible to pick multiple packages with the same name, which we'd then
deduplicate and end up with whatever the first package was. That's
unexpected and produced solutions that were missing a package in a few
corner cases, mostly caused by old packages (in wolfi) providing things
accidentally that weren't withdrawn.

I've manually tested this change against our large corpus of images and
nothing failed to solve.

Signed-off-by: Jon Johnson <[email protected]>
  • Loading branch information
jonjohnsonjr committed Nov 22, 2024
1 parent 69ea41a commit e4f8067
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions pkg/apk/apk/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,31 +355,37 @@ func (p *PkgResolver) conflictingVersion(constraint parsedConstraint, conflict *
}

// Disqualify anything that conflicts with the given pkg.
func (p *PkgResolver) disqualifyConflicts(pkg *RepositoryPackage, dq map[*RepositoryPackage]string) {
for _, prov := range pkg.Provides {
constraint := cachedResolvePackageNameVersionPin(prov)
providers, ok := p.nameMap[constraint.name]
if !ok {
func (p *PkgResolver) disqualifyConflict(pkg *RepositoryPackage, prov string, dq map[*RepositoryPackage]string) {
constraint := cachedResolvePackageNameVersionPin(prov)
providers, ok := p.nameMap[constraint.name]
if !ok {
return
}

for _, conflict := range providers {
if conflict.RepositoryPackage == pkg {
continue
}

for _, conflict := range providers {
if conflict.RepositoryPackage == pkg {
continue
}
if _, dqed := dq[conflict.RepositoryPackage]; dqed {
// Already disqualified, don't bother generating reason.
continue
}

if _, dqed := dq[conflict.RepositoryPackage]; dqed {
// Already disqualified, don't bother generating reason.
continue
}
if !p.conflictingVersion(constraint, conflict) {
// The conflicting package provides the given name but the version is the same, so no conflict.
continue
}

if !p.conflictingVersion(constraint, conflict) {
// The conflicting package provides the given name but the version is the same, so no conflict.
continue
}
p.disqualify(dq, conflict.RepositoryPackage, pkg.Filename()+" already provides "+constraint.name)
}
}

p.disqualify(dq, conflict.RepositoryPackage, pkg.Filename()+" already provides "+constraint.name)
}
func (p *PkgResolver) disqualifyConflicts(pkg *RepositoryPackage, dq map[*RepositoryPackage]string) {
p.disqualifyConflict(pkg, pkg.Name+"="+pkg.Version, dq)

for _, prov := range pkg.Provides {
p.disqualifyConflict(pkg, prov, dq)
}
}

Expand Down

0 comments on commit e4f8067

Please sign in to comment.