Skip to content

Commit

Permalink
rpm: implement an RPM Resolver
Browse files Browse the repository at this point in the history
The Resolver compares file paths gleaned from RPM DBs and compares them
to a Package.Filepath to try and determine if a package needs to be
removed from an index report because its RPM counterpart has already
been included.

Signed-off-by: crozzy <[email protected]>
  • Loading branch information
crozzy committed Jul 22, 2024
1 parent bdaedd2 commit e357ba9
Show file tree
Hide file tree
Showing 4 changed files with 393 additions and 1 deletion.
1 change: 1 addition & 0 deletions libindex/libindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func New(ctx context.Context, opts *Options, cl *http.Client) (*Libindex, error)
opts.Ecosystems = append(opts.Ecosystems, whiteout.NewEcosystem(ctx))
opts.Resolvers = []indexer.Resolver{
&whiteout.Resolver{},
&rhel.Resolver{},
}

if cl == nil {
Expand Down
57 changes: 57 additions & 0 deletions rhel/resolver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package rhel

import (
"context"

"github.com/quay/zlog"

"github.com/quay/claircore"
"github.com/quay/claircore/indexer"
)

var (
_ indexer.Resolver = (*Resolver)(nil)
)

type Resolver struct{}

// Resolve takes a claircore.IndexReport and uses the rpm Files
// to determine if the package originated from an RPM. If the package
// was deemed to have been installed via RPM, it isn't included in the
// final report.
func (r *Resolver) Resolve(ctx context.Context, ir *claircore.IndexReport, layers []*claircore.Layer) *claircore.IndexReport {
for pkgID, pkg := range ir.Packages {
isRPMPackage := false
envLoop:
for _, env := range ir.Environments[pkgID] {
if env == nil {
continue

Check warning on line 28 in rhel/resolver.go

View check run for this annotation

Codecov / codecov/patch

rhel/resolver.go#L28

Added line #L28 was not covered by tests
}
for _, rID := range env.RepositoryIDs {
r := ir.Repositories[rID]
if r.Key == repositoryKey {
isRPMPackage = true
break envLoop
}
}
}
if !isRPMPackage {
filesLoop:
for _, fs := range ir.Files {
for _, f := range fs {
if f.Kind == claircore.FileKindRPM && f.Path == pkg.Filepath {
zlog.Debug(ctx).
Str("package name", pkg.Name).
Str("package file", pkg.Filepath).
Str("rpm file", f.Path).
Msg("package determined to have come from RPM, deleting")
delete(ir.Packages, pkgID)
delete(ir.Environments, pkgID)
break filesLoop
}
}
}
}
}
return ir
}
Loading

0 comments on commit e357ba9

Please sign in to comment.