mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
Fix race in current stage fo go-progress
Signed-off-by: Will Murphy <will.murphy@anchore.com>
This commit is contained in:
parent
3842d28e90
commit
8e9d1d5e91
@ -65,7 +65,7 @@ func (m *Handler) handleAttestationStarted(e partybus.Event) []tea.Model {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
stage := progress.Stage{}
|
stage := progress.NewStage("")
|
||||||
|
|
||||||
tsk := m.newTaskProgress(
|
tsk := m.newTaskProgress(
|
||||||
taskprogress.Title{
|
taskprogress.Title{
|
||||||
@ -79,7 +79,7 @@ func (m *Handler) handleAttestationStarted(e partybus.Event) []tea.Model {
|
|||||||
progress.Stager
|
progress.Stager
|
||||||
}{
|
}{
|
||||||
Progressable: prog,
|
Progressable: prog,
|
||||||
Stager: &stage,
|
Stager: stage,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@ -94,7 +94,7 @@ func (m *Handler) handleAttestationStarted(e partybus.Event) []tea.Model {
|
|||||||
|
|
||||||
return []tea.Model{
|
return []tea.Model{
|
||||||
tsk,
|
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 {
|
if len(fields) == 2 {
|
||||||
present = fmt.Sprintf("transparency log index: %s", fields[1])
|
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") {
|
} 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
|
// only show the last X lines of the shell output
|
||||||
|
|||||||
@ -33,9 +33,7 @@ func TestHandler_handleFetchImage(t *testing.T) {
|
|||||||
progress.Stager
|
progress.Stager
|
||||||
}{
|
}{
|
||||||
Progressable: prog,
|
Progressable: prog,
|
||||||
Stager: &progress.Stage{
|
Stager: progress.NewStage("current"),
|
||||||
Current: "current",
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return partybus.Event{
|
return partybus.Event{
|
||||||
@ -58,9 +56,7 @@ func TestHandler_handleFetchImage(t *testing.T) {
|
|||||||
progress.Stager
|
progress.Stager
|
||||||
}{
|
}{
|
||||||
Progressable: prog,
|
Progressable: prog,
|
||||||
Stager: &progress.Stage{
|
Stager: progress.NewStage("current"),
|
||||||
Current: "current",
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return partybus.Event{
|
return partybus.Event{
|
||||||
|
|||||||
@ -33,9 +33,7 @@ func TestHandler_handleFileDigestsCatalogerStarted(t *testing.T) {
|
|||||||
progress.Stager
|
progress.Stager
|
||||||
}{
|
}{
|
||||||
Progressable: prog,
|
Progressable: prog,
|
||||||
Stager: &progress.Stage{
|
Stager: progress.NewStage("current"),
|
||||||
Current: "current",
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return partybus.Event{
|
return partybus.Event{
|
||||||
@ -57,9 +55,7 @@ func TestHandler_handleFileDigestsCatalogerStarted(t *testing.T) {
|
|||||||
progress.Stager
|
progress.Stager
|
||||||
}{
|
}{
|
||||||
Progressable: prog,
|
Progressable: prog,
|
||||||
Stager: &progress.Stage{
|
Stager: progress.NewStage("current"),
|
||||||
Current: "current",
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return partybus.Event{
|
return partybus.Event{
|
||||||
|
|||||||
@ -33,9 +33,7 @@ func TestHandler_handleFileIndexingStarted(t *testing.T) {
|
|||||||
progress.Stager
|
progress.Stager
|
||||||
}{
|
}{
|
||||||
Progressable: prog,
|
Progressable: prog,
|
||||||
Stager: &progress.Stage{
|
Stager: progress.NewStage("current"),
|
||||||
Current: "current",
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return partybus.Event{
|
return partybus.Event{
|
||||||
@ -58,9 +56,7 @@ func TestHandler_handleFileIndexingStarted(t *testing.T) {
|
|||||||
progress.Stager
|
progress.Stager
|
||||||
}{
|
}{
|
||||||
Progressable: prog,
|
Progressable: prog,
|
||||||
Stager: &progress.Stage{
|
Stager: progress.NewStage("current"),
|
||||||
Current: "current",
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return partybus.Event{
|
return partybus.Event{
|
||||||
|
|||||||
@ -33,9 +33,7 @@ func TestHandler_handleFileMetadataCatalogerStarted(t *testing.T) {
|
|||||||
progress.Stager
|
progress.Stager
|
||||||
}{
|
}{
|
||||||
Progressable: prog,
|
Progressable: prog,
|
||||||
Stager: &progress.Stage{
|
Stager: progress.NewStage("current"),
|
||||||
Current: "current",
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return partybus.Event{
|
return partybus.Event{
|
||||||
@ -57,9 +55,7 @@ func TestHandler_handleFileMetadataCatalogerStarted(t *testing.T) {
|
|||||||
progress.Stager
|
progress.Stager
|
||||||
}{
|
}{
|
||||||
Progressable: prog,
|
Progressable: prog,
|
||||||
Stager: &progress.Stage{
|
Stager: progress.NewStage("current"),
|
||||||
Current: "current",
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return partybus.Event{
|
return partybus.Event{
|
||||||
|
|||||||
@ -25,9 +25,7 @@ func TestHandler_handleSecretsCatalogerStarted(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "cataloging in progress",
|
name: "cataloging in progress",
|
||||||
eventFn: func(t *testing.T) partybus.Event {
|
eventFn: func(t *testing.T) partybus.Event {
|
||||||
stage := &progress.Stage{
|
stage := progress.NewStage("current")
|
||||||
Current: "current",
|
|
||||||
}
|
|
||||||
secretsDiscovered := progress.NewManual(-1)
|
secretsDiscovered := progress.NewManual(-1)
|
||||||
secretsDiscovered.Set(64)
|
secretsDiscovered.Set(64)
|
||||||
prog := progress.NewManual(72)
|
prog := progress.NewManual(72)
|
||||||
@ -47,9 +45,7 @@ func TestHandler_handleSecretsCatalogerStarted(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "cataloging complete",
|
name: "cataloging complete",
|
||||||
eventFn: func(t *testing.T) partybus.Event {
|
eventFn: func(t *testing.T) partybus.Event {
|
||||||
stage := &progress.Stage{
|
stage := progress.NewStage("current")
|
||||||
Current: "current",
|
|
||||||
}
|
|
||||||
secretsDiscovered := progress.NewManual(-1)
|
secretsDiscovered := progress.NewManual(-1)
|
||||||
secretsDiscovered.Set(64)
|
secretsDiscovered.Set(64)
|
||||||
prog := progress.NewManual(72)
|
prog := progress.NewManual(72)
|
||||||
|
|||||||
@ -43,7 +43,7 @@ func (i *Cataloger) Catalog(resolver file.Resolver, coordinates ...file.Coordina
|
|||||||
|
|
||||||
stage, prog := digestsCatalogingProgress(int64(len(locations)))
|
stage, prog := digestsCatalogingProgress(int64(len(locations)))
|
||||||
for _, location := range locations {
|
for _, location := range locations {
|
||||||
stage.Current = location.RealPath
|
stage.Set(location.RealPath)
|
||||||
result, err := i.catalogLocation(resolver, location)
|
result, err := i.catalogLocation(resolver, location)
|
||||||
|
|
||||||
if errors.Is(err, ErrUndigestableFile) {
|
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) {
|
func digestsCatalogingProgress(locations int64) (*progress.Stage, *progress.Manual) {
|
||||||
stage := &progress.Stage{}
|
stage := progress.NewStage("")
|
||||||
prog := progress.NewManual(locations)
|
prog := progress.NewManual(locations)
|
||||||
|
|
||||||
bus.Publish(partybus.Event{
|
bus.Publish(partybus.Event{
|
||||||
|
|||||||
@ -38,7 +38,7 @@ func (i *Cataloger) Catalog(resolver file.Resolver, coordinates ...file.Coordina
|
|||||||
|
|
||||||
stage, prog := metadataCatalogingProgress(int64(len(locations)))
|
stage, prog := metadataCatalogingProgress(int64(len(locations)))
|
||||||
for location := range locations {
|
for location := range locations {
|
||||||
stage.Current = location.RealPath
|
stage.Set(location.RealPath)
|
||||||
metadata, err := resolver.FileMetadataByLocation(location)
|
metadata, err := resolver.FileMetadataByLocation(location)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@ -47,7 +47,7 @@ func (i *Cataloger) Catalog(resolver file.Resolver) (map[file.Coordinates][]file
|
|||||||
locations := internal2.AllRegularFiles(resolver)
|
locations := internal2.AllRegularFiles(resolver)
|
||||||
stage, prog, secretsDiscovered := secretsCatalogingProgress(int64(len(locations)))
|
stage, prog, secretsDiscovered := secretsCatalogingProgress(int64(len(locations)))
|
||||||
for _, location := range locations {
|
for _, location := range locations {
|
||||||
stage.Current = location.RealPath
|
stage.Set(location.RealPath)
|
||||||
result, err := i.catalogLocation(resolver, location)
|
result, err := i.catalogLocation(resolver, location)
|
||||||
if internal.IsErrPathPermission(err) {
|
if internal.IsErrPathPermission(err) {
|
||||||
log.Debugf("secrets cataloger skipping - %+v", 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) {
|
func secretsCatalogingProgress(locations int64) (*progress.Stage, *progress.Manual, *progress.Manual) {
|
||||||
stage := &progress.Stage{}
|
stage := progress.NewStage("")
|
||||||
secretsDiscovered := &progress.Manual{}
|
secretsDiscovered := &progress.Manual{}
|
||||||
prog := progress.NewManual(locations)
|
prog := progress.NewManual(locations)
|
||||||
|
|
||||||
|
|||||||
@ -138,10 +138,9 @@ func (r *directoryIndexer) indexTree(root string, stager *progress.Stage) ([]str
|
|||||||
|
|
||||||
err = filepath.Walk(root,
|
err = filepath.Walk(root,
|
||||||
func(path string, info os.FileInfo, err error) error {
|
func(path string, info os.FileInfo, err error) error {
|
||||||
stager.Current = path
|
stager.Set(path)
|
||||||
|
|
||||||
newRoot, err := r.indexPath(path, info, err)
|
newRoot, err := r.indexPath(path, info, err)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -200,7 +199,7 @@ func (r *directoryIndexer) indexBranch(root string, stager *progress.Stage) ([]s
|
|||||||
targetPath = p
|
targetPath = p
|
||||||
}
|
}
|
||||||
|
|
||||||
stager.Current = targetPath
|
stager.Set(targetPath)
|
||||||
|
|
||||||
lstat, err := os.Lstat(targetPath)
|
lstat, err := os.Lstat(targetPath)
|
||||||
newRoot, err := r.indexPath(targetPath, lstat, err)
|
newRoot, err := r.indexPath(targetPath, lstat, err)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user