mirror of
https://github.com/anchore/syft.git
synced 2025-11-18 00:43:20 +01:00
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:
parent
4f0099583a
commit
0849539729
@ -5,7 +5,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/anchore/stereoscope"
|
"github.com/anchore/stereoscope"
|
||||||
"github.com/anchore/syft/internal"
|
"github.com/anchore/syft/internal"
|
||||||
@ -273,10 +272,7 @@ func packagesExecWorker(userInput string) <-chan error {
|
|||||||
|
|
||||||
go runTask(task, &s.Artifacts, src, c, errs)
|
go runTask(task, &s.Artifacts, src, c, errs)
|
||||||
}
|
}
|
||||||
|
s.Relationships = append(s.Relationships, mergeRelationships(relationships...)...)
|
||||||
for relationship := range mergeRelationships(relationships...) {
|
|
||||||
s.Relationships = append(s.Relationships, relationship)
|
|
||||||
}
|
|
||||||
|
|
||||||
if appConfig.Anchore.Host != "" {
|
if appConfig.Anchore.Host != "" {
|
||||||
if err := runPackageSbomUpload(src, s); err != nil {
|
if err := runPackageSbomUpload(src, s); err != nil {
|
||||||
@ -293,24 +289,13 @@ func packagesExecWorker(userInput string) <-chan error {
|
|||||||
return errs
|
return errs
|
||||||
}
|
}
|
||||||
|
|
||||||
func mergeRelationships(cs ...<-chan artifact.Relationship) <-chan artifact.Relationship {
|
func mergeRelationships(cs ...<-chan artifact.Relationship) (relationships []artifact.Relationship) {
|
||||||
var wg sync.WaitGroup
|
|
||||||
var relationships = make(chan artifact.Relationship)
|
|
||||||
|
|
||||||
wg.Add(len(cs))
|
|
||||||
for _, c := range cs {
|
for _, c := range cs {
|
||||||
go func(c <-chan artifact.Relationship) {
|
|
||||||
for n := range c {
|
for n := range c {
|
||||||
relationships <- n
|
relationships = append(relationships, n)
|
||||||
}
|
}
|
||||||
wg.Done()
|
|
||||||
}(c)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
|
||||||
wg.Wait()
|
|
||||||
close(relationships)
|
|
||||||
}()
|
|
||||||
return 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 {
|
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 fmt.Errorf("failed to upload results to host=%s: %+v", appConfig.Anchore.Host, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -135,9 +135,7 @@ func powerUserExecWorker(userInput string) <-chan error {
|
|||||||
go runTask(task, &s.Artifacts, src, c, errs)
|
go runTask(task, &s.Artifacts, src, c, errs)
|
||||||
}
|
}
|
||||||
|
|
||||||
for relationship := range mergeRelationships(relationships...) {
|
s.Relationships = append(s.Relationships, mergeRelationships(relationships...)...)
|
||||||
s.Relationships = append(s.Relationships, relationship)
|
|
||||||
}
|
|
||||||
|
|
||||||
bus.Publish(partybus.Event{
|
bus.Publish(partybus.Event{
|
||||||
Type: event.PresenterReady,
|
Type: event.PresenterReady,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user