From 8e9d1d5e910c0ce52424a082969f8cb3ee2b25e7 Mon Sep 17 00:00:00 2001 From: Will Murphy Date: Fri, 8 Sep 2023 07:48:42 -0400 Subject: [PATCH] Fix race in current stage fo go-progress Signed-off-by: Will Murphy --- cmd/syft/cli/ui/handle_attestation.go | 10 +++++----- cmd/syft/cli/ui/handle_fetch_image_test.go | 8 ++------ cmd/syft/cli/ui/handle_file_digests_cataloger_test.go | 8 ++------ cmd/syft/cli/ui/handle_file_indexing_test.go | 8 ++------ cmd/syft/cli/ui/handle_file_metadata_cataloger_test.go | 8 ++------ cmd/syft/cli/ui/handle_secrets_cataloger_test.go | 8 ++------ syft/file/cataloger/filedigest/cataloger.go | 4 ++-- syft/file/cataloger/filemetadata/cataloger.go | 2 +- syft/file/cataloger/secrets/cataloger.go | 4 ++-- syft/internal/fileresolver/directory_indexer.go | 5 ++--- 10 files changed, 22 insertions(+), 43 deletions(-) diff --git a/cmd/syft/cli/ui/handle_attestation.go b/cmd/syft/cli/ui/handle_attestation.go index f753e7248..03a44095b 100644 --- a/cmd/syft/cli/ui/handle_attestation.go +++ b/cmd/syft/cli/ui/handle_attestation.go @@ -65,7 +65,7 @@ func (m *Handler) handleAttestationStarted(e partybus.Event) []tea.Model { return nil } - stage := progress.Stage{} + stage := progress.NewStage("") tsk := m.newTaskProgress( taskprogress.Title{ @@ -79,7 +79,7 @@ func (m *Handler) handleAttestationStarted(e partybus.Event) []tea.Model { progress.Stager }{ Progressable: prog, - Stager: &stage, + Stager: stage, }, ), ) @@ -94,7 +94,7 @@ func (m *Handler) handleAttestationStarted(e partybus.Event) []tea.Model { return []tea.Model{ tsk, - newLogFrame(newBackgroundLineReader(m.Running, reader, &stage), prog, borderStyle), + newLogFrame(newBackgroundLineReader(m.Running, reader, stage), prog, borderStyle), } } @@ -146,9 +146,9 @@ func (l *backgroundLineReader) read(reader io.Reader, stage *progress.Stage) { if len(fields) == 2 { present = fmt.Sprintf("transparency log index: %s", fields[1]) } - stage.Current = present + stage.Set(present) } else if strings.Contains(text, "WARNING: skipping transparency log upload") { - stage.Current = "transparency log upload skipped" + stage.Set("transparency log upload skipped") } // only show the last X lines of the shell output diff --git a/cmd/syft/cli/ui/handle_fetch_image_test.go b/cmd/syft/cli/ui/handle_fetch_image_test.go index c514b9865..4bca47ac7 100644 --- a/cmd/syft/cli/ui/handle_fetch_image_test.go +++ b/cmd/syft/cli/ui/handle_fetch_image_test.go @@ -33,9 +33,7 @@ func TestHandler_handleFetchImage(t *testing.T) { progress.Stager }{ Progressable: prog, - Stager: &progress.Stage{ - Current: "current", - }, + Stager: progress.NewStage("current"), } return partybus.Event{ @@ -58,9 +56,7 @@ func TestHandler_handleFetchImage(t *testing.T) { progress.Stager }{ Progressable: prog, - Stager: &progress.Stage{ - Current: "current", - }, + Stager: progress.NewStage("current"), } return partybus.Event{ diff --git a/cmd/syft/cli/ui/handle_file_digests_cataloger_test.go b/cmd/syft/cli/ui/handle_file_digests_cataloger_test.go index 2e74009a4..8b39ddd3b 100644 --- a/cmd/syft/cli/ui/handle_file_digests_cataloger_test.go +++ b/cmd/syft/cli/ui/handle_file_digests_cataloger_test.go @@ -33,9 +33,7 @@ func TestHandler_handleFileDigestsCatalogerStarted(t *testing.T) { progress.Stager }{ Progressable: prog, - Stager: &progress.Stage{ - Current: "current", - }, + Stager: progress.NewStage("current"), } return partybus.Event{ @@ -57,9 +55,7 @@ func TestHandler_handleFileDigestsCatalogerStarted(t *testing.T) { progress.Stager }{ Progressable: prog, - Stager: &progress.Stage{ - Current: "current", - }, + Stager: progress.NewStage("current"), } return partybus.Event{ diff --git a/cmd/syft/cli/ui/handle_file_indexing_test.go b/cmd/syft/cli/ui/handle_file_indexing_test.go index 86473c411..4a1314f99 100644 --- a/cmd/syft/cli/ui/handle_file_indexing_test.go +++ b/cmd/syft/cli/ui/handle_file_indexing_test.go @@ -33,9 +33,7 @@ func TestHandler_handleFileIndexingStarted(t *testing.T) { progress.Stager }{ Progressable: prog, - Stager: &progress.Stage{ - Current: "current", - }, + Stager: progress.NewStage("current"), } return partybus.Event{ @@ -58,9 +56,7 @@ func TestHandler_handleFileIndexingStarted(t *testing.T) { progress.Stager }{ Progressable: prog, - Stager: &progress.Stage{ - Current: "current", - }, + Stager: progress.NewStage("current"), } return partybus.Event{ diff --git a/cmd/syft/cli/ui/handle_file_metadata_cataloger_test.go b/cmd/syft/cli/ui/handle_file_metadata_cataloger_test.go index d247001c8..f9ef1a3c6 100644 --- a/cmd/syft/cli/ui/handle_file_metadata_cataloger_test.go +++ b/cmd/syft/cli/ui/handle_file_metadata_cataloger_test.go @@ -33,9 +33,7 @@ func TestHandler_handleFileMetadataCatalogerStarted(t *testing.T) { progress.Stager }{ Progressable: prog, - Stager: &progress.Stage{ - Current: "current", - }, + Stager: progress.NewStage("current"), } return partybus.Event{ @@ -57,9 +55,7 @@ func TestHandler_handleFileMetadataCatalogerStarted(t *testing.T) { progress.Stager }{ Progressable: prog, - Stager: &progress.Stage{ - Current: "current", - }, + Stager: progress.NewStage("current"), } return partybus.Event{ diff --git a/cmd/syft/cli/ui/handle_secrets_cataloger_test.go b/cmd/syft/cli/ui/handle_secrets_cataloger_test.go index 3a04cbce5..5e7bd3970 100644 --- a/cmd/syft/cli/ui/handle_secrets_cataloger_test.go +++ b/cmd/syft/cli/ui/handle_secrets_cataloger_test.go @@ -25,9 +25,7 @@ func TestHandler_handleSecretsCatalogerStarted(t *testing.T) { { name: "cataloging in progress", eventFn: func(t *testing.T) partybus.Event { - stage := &progress.Stage{ - Current: "current", - } + stage := progress.NewStage("current") secretsDiscovered := progress.NewManual(-1) secretsDiscovered.Set(64) prog := progress.NewManual(72) @@ -47,9 +45,7 @@ func TestHandler_handleSecretsCatalogerStarted(t *testing.T) { { name: "cataloging complete", eventFn: func(t *testing.T) partybus.Event { - stage := &progress.Stage{ - Current: "current", - } + stage := progress.NewStage("current") secretsDiscovered := progress.NewManual(-1) secretsDiscovered.Set(64) prog := progress.NewManual(72) diff --git a/syft/file/cataloger/filedigest/cataloger.go b/syft/file/cataloger/filedigest/cataloger.go index 31a4367ab..4ca2773de 100644 --- a/syft/file/cataloger/filedigest/cataloger.go +++ b/syft/file/cataloger/filedigest/cataloger.go @@ -43,7 +43,7 @@ func (i *Cataloger) Catalog(resolver file.Resolver, coordinates ...file.Coordina stage, prog := digestsCatalogingProgress(int64(len(locations))) for _, location := range locations { - stage.Current = location.RealPath + stage.Set(location.RealPath) result, err := i.catalogLocation(resolver, location) if errors.Is(err, ErrUndigestableFile) { @@ -92,7 +92,7 @@ func (i *Cataloger) catalogLocation(resolver file.Resolver, location file.Locati } func digestsCatalogingProgress(locations int64) (*progress.Stage, *progress.Manual) { - stage := &progress.Stage{} + stage := progress.NewStage("") prog := progress.NewManual(locations) bus.Publish(partybus.Event{ diff --git a/syft/file/cataloger/filemetadata/cataloger.go b/syft/file/cataloger/filemetadata/cataloger.go index bae2344f4..760cbbab8 100644 --- a/syft/file/cataloger/filemetadata/cataloger.go +++ b/syft/file/cataloger/filemetadata/cataloger.go @@ -38,7 +38,7 @@ func (i *Cataloger) Catalog(resolver file.Resolver, coordinates ...file.Coordina stage, prog := metadataCatalogingProgress(int64(len(locations))) for location := range locations { - stage.Current = location.RealPath + stage.Set(location.RealPath) metadata, err := resolver.FileMetadataByLocation(location) if err != nil { return nil, err diff --git a/syft/file/cataloger/secrets/cataloger.go b/syft/file/cataloger/secrets/cataloger.go index 488f849b5..0c1239f23 100644 --- a/syft/file/cataloger/secrets/cataloger.go +++ b/syft/file/cataloger/secrets/cataloger.go @@ -47,7 +47,7 @@ func (i *Cataloger) Catalog(resolver file.Resolver) (map[file.Coordinates][]file locations := internal2.AllRegularFiles(resolver) stage, prog, secretsDiscovered := secretsCatalogingProgress(int64(len(locations))) for _, location := range locations { - stage.Current = location.RealPath + stage.Set(location.RealPath) result, err := i.catalogLocation(resolver, location) if internal.IsErrPathPermission(err) { log.Debugf("secrets cataloger skipping - %+v", err) @@ -140,7 +140,7 @@ type Monitor struct { } func secretsCatalogingProgress(locations int64) (*progress.Stage, *progress.Manual, *progress.Manual) { - stage := &progress.Stage{} + stage := progress.NewStage("") secretsDiscovered := &progress.Manual{} prog := progress.NewManual(locations) diff --git a/syft/internal/fileresolver/directory_indexer.go b/syft/internal/fileresolver/directory_indexer.go index b6432f000..acc17acd1 100644 --- a/syft/internal/fileresolver/directory_indexer.go +++ b/syft/internal/fileresolver/directory_indexer.go @@ -138,10 +138,9 @@ func (r *directoryIndexer) indexTree(root string, stager *progress.Stage) ([]str err = filepath.Walk(root, func(path string, info os.FileInfo, err error) error { - stager.Current = path + stager.Set(path) newRoot, err := r.indexPath(path, info, err) - if err != nil { return err } @@ -200,7 +199,7 @@ func (r *directoryIndexer) indexBranch(root string, stager *progress.Stage) ([]s targetPath = p } - stager.Current = targetPath + stager.Set(targetPath) lstat, err := os.Lstat(targetPath) newRoot, err := r.indexPath(targetPath, lstat, err)