Skip to content

Commit

Permalink
fix: thread safety for progress
Browse files Browse the repository at this point in the history
Signed-off-by: Keith Zantow <[email protected]>
  • Loading branch information
kzantow committed Mar 1, 2023
1 parent fab1c96 commit 1a2ec3e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions pkg/image/docker/pull_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,17 @@ func (p *PullStatus) onEvent(event *pullEvent) {
if currentPhase >= AlreadyExistsPhase {
phaseProgress.SetCompleted()
} else {
phaseProgress.N = int64(event.ProgressDetail.Current)
phaseProgress.Total = int64(event.ProgressDetail.Total)
phaseProgress.Set(int64(event.ProgressDetail.Current))
phaseProgress.SetTotal(int64(event.ProgressDetail.Total))
}

if currentPhase == DownloadingPhase {
dl := p.downloadProgress[layer]
dl.N = int64(event.ProgressDetail.Current)
dl.Total = int64(event.ProgressDetail.Total)
dl.Set(int64(event.ProgressDetail.Current))
dl.SetTotal(int64(event.ProgressDetail.Total))
} else if currentPhase >= DownloadCompletePhase {
dl := p.downloadProgress[layer]
dl.N = dl.Total
dl.Set(dl.Size())
dl.SetCompleted()
}
}
10 changes: 5 additions & 5 deletions pkg/image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ func (i *Image) IDs() []string {
}

func (i *Image) trackReadProgress(metadata Metadata) *progress.Manual {
prog := &progress.Manual{
prog := progress.NewManual(
// x2 for read and squash of each layer
Total: int64(len(metadata.Config.RootFS.DiffIDs) * 2),
}
int64(len(metadata.Config.RootFS.DiffIDs) * 2),
)

bus.Publish(partybus.Event{
Type: event.ReadImage,
Expand Down Expand Up @@ -217,7 +217,7 @@ func (i *Image) Read() error {
i.Metadata.Size += layer.Metadata.Size
layers = append(layers, layer)

readProg.N++
readProg.Increment()
}

i.Layers = layers
Expand Down Expand Up @@ -257,7 +257,7 @@ func (i *Image) squash(prog *progress.Manual) error {
layer.SquashedSearchContext = filetree.NewSearchContext(layer.SquashedTree, layer.fileCatalog.Index)
lastSquashTree = squashedTree

prog.N++
prog.Increment()
}

prog.SetCompleted()
Expand Down
4 changes: 2 additions & 2 deletions pkg/image/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func layerTarIndexer(ft filetree.Writer, fileCatalog *FileCatalog, size *int64,
fileCatalog.addImageReferences(ref.ID(), layerRef, index.Open)

if monitor != nil {
monitor.N++
monitor.Increment()
}
return nil
}
Expand Down Expand Up @@ -285,7 +285,7 @@ func squashfsVisitor(ft filetree.Writer, fileCatalog *FileCatalog, size *int64,
return r
})

monitor.N++
monitor.Increment()
return nil
}
}
Expand Down

0 comments on commit 1a2ec3e

Please sign in to comment.