-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
4 changed files
with
393 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
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 | ||
} |
Oops, something went wrong.