Update concurrency primitives for relationships in command layer (#639)

* update concurrency primitives for relationships in command layer

Signed-off-by: Christopher Angelo Phillips <christopher.phillips@anchore.com>
This commit is contained in:
Christopher Angelo Phillips 2021-11-20 03:44:17 -05:00 committed by GitHub
parent 4f0099583a
commit 0849539729
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 23 deletions

View File

@ -5,7 +5,6 @@ import (
"fmt"
"io/ioutil"
"os"
"sync"
"github.com/anchore/stereoscope"
"github.com/anchore/syft/internal"
@ -273,10 +272,7 @@ func packagesExecWorker(userInput string) <-chan error {
go runTask(task, &s.Artifacts, src, c, errs)
}
for relationship := range mergeRelationships(relationships...) {
s.Relationships = append(s.Relationships, relationship)
}
s.Relationships = append(s.Relationships, mergeRelationships(relationships...)...)
if appConfig.Anchore.Host != "" {
if err := runPackageSbomUpload(src, s); err != nil {
@ -293,24 +289,13 @@ func packagesExecWorker(userInput string) <-chan error {
return errs
}
func mergeRelationships(cs ...<-chan artifact.Relationship) <-chan artifact.Relationship {
var wg sync.WaitGroup
var relationships = make(chan artifact.Relationship)
wg.Add(len(cs))
func mergeRelationships(cs ...<-chan artifact.Relationship) (relationships []artifact.Relationship) {
for _, c := range cs {
go func(c <-chan artifact.Relationship) {
for n := range c {
relationships <- n
}
wg.Done()
}(c)
for n := range c {
relationships = append(relationships, n)
}
}
go func() {
wg.Wait()
close(relationships)
}()
return relationships
}
@ -358,5 +343,6 @@ func runPackageSbomUpload(src *source.Source, s sbom.SBOM) error {
if err := c.Import(context.Background(), importCfg); err != nil {
return fmt.Errorf("failed to upload results to host=%s: %+v", appConfig.Anchore.Host, err)
}
return nil
}

View File

@ -135,9 +135,7 @@ func powerUserExecWorker(userInput string) <-chan error {
go runTask(task, &s.Artifacts, src, c, errs)
}
for relationship := range mergeRelationships(relationships...) {
s.Relationships = append(s.Relationships, relationship)
}
s.Relationships = append(s.Relationships, mergeRelationships(relationships...)...)
bus.Publish(partybus.Event{
Type: event.PresenterReady,