Skip to content

Commit

Permalink
fix: pr comments on style and execution flow
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Phillips <[email protected]>
  • Loading branch information
spiffcs committed May 8, 2024
1 parent 17dbf5a commit 87113bd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ func TestBinaryElfRelationships(t *testing.T) {
"libhello_world.so": {
"syfttestfixture",
},
// TODO: we need to capture devel package
}

// run the test...
Expand Down
8 changes: 4 additions & 4 deletions internal/relationship/finalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import (
func Finalize(resolver file.Resolver, builder sbomsync.Builder, cfg cataloging.RelationshipsConfig, src artifact.Identifiable) {
accessor := builder.(sbomsync.Accessor)

// TODO (also, how should we update the TUI to reflect that we removed packages?)
// remove ELF packages and Binary packages that are already
// represented by a source package (e.g. a package that is evident by some package manager)
builder.DeletePackages(binary.PackagesToRemove(resolver, accessor)...)

// add relationships showing packages that are evident by a file which is owned by another package (package-to-package)
if cfg.PackageFileOwnershipOverlap {
Expand Down Expand Up @@ -43,8 +45,6 @@ func Finalize(resolver file.Resolver, builder sbomsync.Builder, cfg cataloging.R
accessor.ReadFromSBOM(func(s *sbom.SBOM) {
evidentByRelationships = evidentBy(s.Artifacts.Packages)
})
builder.AddRelationships(evidentByRelationships...)

// remove ELF packages that are already represented by a non-ELF package
builder.DeletePackages(binary.PackagesToRemove(resolver, accessor)...)
builder.AddRelationships(evidentByRelationships...)
}
18 changes: 7 additions & 11 deletions internal/sbomsync/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,27 +84,23 @@ func (b sbomBuilder) DeletePackages(ids ...artifact.ID) {
b.lock.Lock()
defer b.lock.Unlock()

toDelete := make(map[artifact.ID]struct{})
deleted := make(map[artifact.ID]struct{})
for _, id := range ids {
b.sbom.Artifacts.Packages.Delete(id)
toDelete[id] = struct{}{}
deleted[id] = struct{}{}
}

// remove any relationships that reference the deleted packages
var relationships []artifact.Relationship
for _, rel := range b.sbom.Relationships {
fromID := false
toID := false
if _, ok := toDelete[rel.From.ID()]; ok {
fromID = true
}
if _, ok := toDelete[rel.To.ID()]; ok {
toID = true
if _, ok := deleted[rel.From.ID()]; ok {
continue
}
// skip (remove) relationships that reference the deleted packages
if fromID || toID {
if _, ok := deleted[rel.To.ID()]; ok {
continue
}

// only keep relationships that don't reference the deleted packages
relationships = append(relationships, rel)
}

Expand Down

0 comments on commit 87113bd

Please sign in to comment.