mirror of
https://github.com/anchore/syft
synced 2024-11-10 14:24:12 +00:00
add source to packages found by rpmdb cataloger
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
parent
9581a0309b
commit
7964c27bd8
3 changed files with 11 additions and 6 deletions
|
@ -35,15 +35,15 @@ func (c *Cataloger) Catalog(resolver scope.Resolver) ([]pkg.Package, error) {
|
|||
}
|
||||
|
||||
var pkgs []pkg.Package
|
||||
for _, ref := range fileMatches {
|
||||
dbContents, err := resolver.FileContentsByRef(ref)
|
||||
for _, dbRef := range fileMatches {
|
||||
dbContents, err := resolver.FileContentsByRef(dbRef)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pkgs, err = parseRpmDB(resolver, strings.NewReader(dbContents))
|
||||
pkgs, err = parseRpmDB(resolver, dbRef, strings.NewReader(dbContents))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to catalog rpmdb package=%+v: %w", ref.Path, err)
|
||||
return nil, fmt.Errorf("unable to catalog rpmdb package=%+v: %w", dbRef.Path, err)
|
||||
}
|
||||
}
|
||||
return pkgs, nil
|
||||
|
|
|
@ -17,7 +17,7 @@ import (
|
|||
)
|
||||
|
||||
// parseApkDb parses an "Packages" RPM DB and returns the Packages listed within it.
|
||||
func parseRpmDB(resolver scope.FileResolver, reader io.Reader) ([]pkg.Package, error) {
|
||||
func parseRpmDB(resolver scope.FileResolver, dbRef file.Reference, reader io.Reader) ([]pkg.Package, error) {
|
||||
f, err := ioutil.TempFile("", internal.ApplicationName+"-rpmdb")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create temp rpmdb file: %w", err)
|
||||
|
@ -57,6 +57,7 @@ func parseRpmDB(resolver scope.FileResolver, reader io.Reader) ([]pkg.Package, e
|
|||
Name: entry.Name,
|
||||
Version: fmt.Sprintf("%s-%s", entry.Version, entry.Release), // this is what engine does
|
||||
//Version: fmt.Sprintf("%d:%s-%s.%s", entry.Epoch, entry.Version, entry.Release, entry.Arch),
|
||||
Source: []file.Reference{dbRef},
|
||||
Type: pkg.RpmPkg,
|
||||
MetadataType: pkg.RpmdbMetadataType,
|
||||
Metadata: pkg.RpmdbMetadata{
|
||||
|
|
|
@ -41,6 +41,8 @@ func (r *rpmdbTestFileResolverMock) RelativeFileByPath(file.Reference, string) (
|
|||
}
|
||||
|
||||
func TestParseRpmDB(t *testing.T) {
|
||||
dbRef := file.NewFileReference("test-path")
|
||||
|
||||
tests := []struct {
|
||||
fixture string
|
||||
expected map[string]pkg.Package
|
||||
|
@ -54,6 +56,7 @@ func TestParseRpmDB(t *testing.T) {
|
|||
"dive": {
|
||||
Name: "dive",
|
||||
Version: "0.9.2-1",
|
||||
Source: []file.Reference{dbRef},
|
||||
Type: pkg.RpmPkg,
|
||||
MetadataType: pkg.RpmdbMetadataType,
|
||||
Metadata: pkg.RpmdbMetadata{
|
||||
|
@ -79,6 +82,7 @@ func TestParseRpmDB(t *testing.T) {
|
|||
"dive": {
|
||||
Name: "dive",
|
||||
Version: "0.9.2-1",
|
||||
Source: []file.Reference{dbRef},
|
||||
Type: pkg.RpmPkg,
|
||||
MetadataType: pkg.RpmdbMetadataType,
|
||||
Metadata: pkg.RpmdbMetadata{
|
||||
|
@ -114,7 +118,7 @@ func TestParseRpmDB(t *testing.T) {
|
|||
|
||||
fileResolver := newTestFileResolver(test.ignorePaths)
|
||||
|
||||
actual, err := parseRpmDB(fileResolver, fixture)
|
||||
actual, err := parseRpmDB(fileResolver, dbRef, fixture)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to parse rpmdb: %+v", err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue