Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions pkg/backend/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ func (p *ProgressBar) PrintMessage(prompt string, desc ocispec.Descriptor, messa
p.bars[desc.Digest.String()] = bar
}

// Abort aborts the progress bar by the given desc.
func (p *ProgressBar) Abort(desc ocispec.Descriptor) {
p.mu.Lock()
defer p.mu.Unlock()
// if the bar already exists, abort it.
bar, ok := p.bars[desc.Digest.String()]
if ok {
bar.Abort(false)
}
}

// Wait waits for the progress bar to finish.
func (p *ProgressBar) Wait() {
p.mpb.Wait()
Expand Down
2 changes: 2 additions & 0 deletions pkg/backend/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ func pullIfNotExist(ctx context.Context, pb *ProgressBar, prompt string, src *re
if desc.MediaType == ocispec.MediaTypeImageManifest {
body, err := io.ReadAll(pb.Add(prompt, desc, content))
if err != nil {
pb.Abort(desc)
return fmt.Errorf("failed to read the manifest: %w", err)
}

Expand All @@ -171,6 +172,7 @@ func pullIfNotExist(ctx context.Context, pb *ProgressBar, prompt string, src *re
}
} else {
if _, _, err := dst.PushBlob(ctx, repo, pb.Add(prompt, desc, content)); err != nil {
pb.Abort(desc)
return err
}
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/backend/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ func pushIfNotExist(ctx context.Context, pb *ProgressBar, prompt string, src sto
}

if err := dst.Manifests().Push(ctx, desc, pb.Add(prompt, desc, bytes.NewReader(manifestRaw))); err != nil {
pb.Abort(desc)
return err
}

Expand All @@ -159,6 +160,7 @@ func pushIfNotExist(ctx context.Context, pb *ProgressBar, prompt string, src sto
defer content.Close()

if err := dst.Blobs().Push(ctx, desc, pb.Add(prompt, desc, content)); err != nil {
pb.Abort(desc)
return err
}
}
Expand Down