Skip to content

Commit ecb3728

Browse files
authored
Merge branch 'main' into 2127-helm-chart-overrides
2 parents b0214f2 + ce4e953 commit ecb3728

3 files changed

Lines changed: 14 additions & 6 deletions

File tree

src/internal/packager/images/pull.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,11 @@ func (i *ImageConfig) PullAll() ([]ImgInfo, error) {
185185

186186
// Create a thread to update a progress bar as we save the image files to disk
187187
doneSaving := make(chan int)
188+
errorSaving := make(chan int)
188189
var progressBarWaitGroup sync.WaitGroup
189190
progressBarWaitGroup.Add(1)
190191
updateText := fmt.Sprintf("Pulling %d images", imageCount)
191-
go utils.RenderProgressBarForLocalDirWrite(i.ImagesPath, totalBytes, &progressBarWaitGroup, doneSaving, updateText, updateText)
192+
go utils.RenderProgressBarForLocalDirWrite(i.ImagesPath, totalBytes, &progressBarWaitGroup, doneSaving, errorSaving, updateText, updateText)
192193

193194
// Spawn a goroutine for each layer to write it to disk using crane
194195

@@ -324,7 +325,7 @@ func (i *ImageConfig) PullAll() ([]ImgInfo, error) {
324325

325326
onLayerWritingError := func(err error) error {
326327
// Send a signal to the progress bar that we're done and wait for the thread to finish
327-
doneSaving <- 1
328+
errorSaving <- 1
328329
progressBarWaitGroup.Wait()
329330
message.WarnErr(err, "Failed to write image layers, trying again up to 3 times...")
330331
if strings.HasPrefix(err.Error(), "expected blob size") {
@@ -391,7 +392,7 @@ func (i *ImageConfig) PullAll() ([]ImgInfo, error) {
391392

392393
onImageSavingError := func(err error) error {
393394
// Send a signal to the progress bar that we're done and wait for the thread to finish
394-
doneSaving <- 1
395+
errorSaving <- 1
395396
progressBarWaitGroup.Wait()
396397
message.WarnErr(err, "Failed to write image config or manifest, trying again up to 3 times...")
397398
return err

src/pkg/oci/pull.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,14 @@ func (o *OrasRemote) CopyWithProgress(layers []ocispec.Descriptor, store oras.Ta
229229

230230
// Create a thread to update a progress bar as we save the package to disk
231231
doneSaving := make(chan int)
232+
encounteredErr := make(chan int)
232233
var wg sync.WaitGroup
233234
wg.Add(1)
234235
successText := fmt.Sprintf("Pulling %q", helpers.OCIURLPrefix+o.repo.Reference.String())
235-
go utils.RenderProgressBarForLocalDirWrite(destinationDir, estimatedBytes, &wg, doneSaving, "Pulling", successText)
236+
go utils.RenderProgressBarForLocalDirWrite(destinationDir, estimatedBytes, &wg, doneSaving, encounteredErr, "Pulling", successText)
236237
_, err := oras.Copy(o.ctx, o.repo, o.repo.Reference.String(), store, o.repo.Reference.String(), copyOpts)
237238
if err != nil {
239+
encounteredErr <- 1
238240
return err
239241
}
240242

src/pkg/utils/bytes.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ func ByteFormat(inputNum float64, precision int) string {
5757
}
5858

5959
// RenderProgressBarForLocalDirWrite creates a progress bar that continuously tracks the progress of writing files to a local directory and all of its subdirectories.
60-
// NOTE: This function runs infinitely until the completeChan is triggered, this function should be run in a goroutine while a different thread/process is writing to the directory.
61-
func RenderProgressBarForLocalDirWrite(filepath string, expectedTotal int64, wg *sync.WaitGroup, completeChan chan int, updateText string, successText string) {
60+
// NOTE: This function runs infinitely until either completeChan or errChan is triggered, this function should be run in a goroutine while a different thread/process is writing to the directory.
61+
func RenderProgressBarForLocalDirWrite(filepath string, expectedTotal int64, wg *sync.WaitGroup, completeChan chan int, errChan chan int, updateText string, successText string) {
6262

6363
// Create a progress bar
6464
title := fmt.Sprintf("%s (%s of %s)", updateText, ByteFormat(float64(0), 2), ByteFormat(float64(expectedTotal), 2))
@@ -72,6 +72,11 @@ func RenderProgressBarForLocalDirWrite(filepath string, expectedTotal int64, wg
7272
wg.Done()
7373
return
7474

75+
case <-errChan:
76+
progressBar.Stop()
77+
wg.Done()
78+
return
79+
7580
default:
7681
// Read the directory size
7782
currentBytes, dirErr := GetDirSize(filepath)

0 commit comments

Comments
 (0)