Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpm: implement an RPM filescanner to discern RPM filepaths #1320

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions file.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type FileKind string

const (
FileKindWhiteout = FileKind("whiteout")
FileKindRPM = FileKind("rpm")
hdonnay marked this conversation as resolved.
Show resolved Hide resolved
)

// File represents interesting files that are found in the layer.
Expand Down
2 changes: 1 addition & 1 deletion indexer/controller/coalesce.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
}

for k, v := range ir.Files {
source.Files[k] = v
source.Files[k] = append(source.Files[k], v...)

Check warning on line 131 in indexer/controller/coalesce.go

View check run for this annotation

Codecov / codecov/patch

indexer/controller/coalesce.go#L131

Added line #L131 was not covered by tests
}
}
return source
Expand Down
2 changes: 1 addition & 1 deletion indexer/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func New(options *indexer.Options) *Controller {
Environments: map[string][]*claircore.Environment{},
Distributions: map[string]*claircore.Distribution{},
Repositories: map[string]*claircore.Repository{},
Files: map[string]claircore.File{},
Files: map[string][]claircore.File{},
}

s := &Controller{
Expand Down
2 changes: 1 addition & 1 deletion indexreport.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type IndexReport struct {
// an error string in the case the index did not succeed
Err string `json:"err"`
// Files doesn't end up in the json report but needs to be available at post-coalesce
Files map[string]File `json:"-"`
Files map[string][]File `json:"-"`
}

// IndexRecords returns a list of IndexRecords derived from the IndexReport
Expand Down
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
7 changes: 7 additions & 0 deletions linux/coalescer.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
if len(artifacts.Pkgs) == 0 {
continue
}
lh := artifacts.Hash.String()

tmp := make(map[string][]*claircore.Package)
for _, pkg := range artifacts.Pkgs {
Expand All @@ -58,6 +59,12 @@
for db, pkgs := range tmp {
dbs[db] = pkgs
}
for _, f := range artifacts.Files {
if c.ir.Files == nil {
c.ir.Files = make(map[string][]claircore.File)

Check warning on line 64 in linux/coalescer.go

View check run for this annotation

Codecov / codecov/patch

linux/coalescer.go#L63-L64

Added lines #L63 - L64 were not covered by tests
}
crozzy marked this conversation as resolved.
Show resolved Hide resolved
c.ir.Files[lh] = append(c.ir.Files[lh], f)

Check warning on line 66 in linux/coalescer.go

View check run for this annotation

Codecov / codecov/patch

linux/coalescer.go#L66

Added line #L66 was not covered by tests
}
}

for db, packages := range dbs {
Expand Down
57 changes: 57 additions & 0 deletions rhel/resolver.go
hdonnay marked this conversation as resolved.
Show resolved Hide resolved
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
Loading