fix: only generate PURL on empty string (#1312)

This commit is contained in:
Christopher Angelo Phillips 2022-11-03 10:00:14 -04:00 committed by GitHub
parent e0acfa98c7
commit 10464642e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -45,9 +45,7 @@ func newMonitor() (*progress.Manual, *progress.Manual) {
func Catalog(resolver source.FileResolver, release *linux.Release, catalogers ...pkg.Cataloger) (*pkg.Catalog, []artifact.Relationship, error) { func Catalog(resolver source.FileResolver, release *linux.Release, catalogers ...pkg.Cataloger) (*pkg.Catalog, []artifact.Relationship, error) {
catalog := pkg.NewCatalog() catalog := pkg.NewCatalog()
var allRelationships []artifact.Relationship var allRelationships []artifact.Relationship
filesProcessed, packagesDiscovered := newMonitor() filesProcessed, packagesDiscovered := newMonitor()
// perform analysis, accumulating errors for each failed analysis // perform analysis, accumulating errors for each failed analysis
var errs error var errs error
for _, c := range catalogers { for _, c := range catalogers {
@ -70,7 +68,9 @@ func Catalog(resolver source.FileResolver, release *linux.Release, catalogers ..
p.CPEs = append(p.CPEs, cpe.Generate(p)...) p.CPEs = append(p.CPEs, cpe.Generate(p)...)
// generate PURL (note: this is excluded from package ID, so is safe to mutate) // generate PURL (note: this is excluded from package ID, so is safe to mutate)
p.PURL = pkg.URL(p, release) if p.PURL == "" {
p.PURL = pkg.URL(p, release)
}
// if we were not able to identify the language we have an opportunity // if we were not able to identify the language we have an opportunity
// to try and get this value from the PURL. Worst case we assert that // to try and get this value from the PURL. Worst case we assert that
@ -86,7 +86,6 @@ func Catalog(resolver source.FileResolver, release *linux.Release, catalogers ..
} else { } else {
allRelationships = append(allRelationships, owningRelationships...) allRelationships = append(allRelationships, owningRelationships...)
} }
// add to catalog
catalog.Add(p) catalog.Add(p)
} }