Skip to content
Merged
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
12 changes: 8 additions & 4 deletions internal/pb/pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"io"
"os"
"sync"
"sync/atomic"
"time"

humanize "github.com/dustin/go-humanize"
Expand All @@ -30,13 +31,16 @@ import (
)

var (
// disableProgress is the flag to disable progress bar.
disableProgress bool
// disableProgress is the flag to disable progress bar. Read from the
// progress-bar hot path by concurrent pull/push workers while a single
// goroutine may flip it via SetDisableProgress, so the access is guarded
// by sync/atomic to stay race-free under `go test -race`.
disableProgress atomic.Bool
)

// SetDisableProgress disables the progress bar.
func SetDisableProgress(disable bool) {
disableProgress = disable
disableProgress.Store(disable)
}

// NormalizePrompt normalizes the prompt string.
Expand Down Expand Up @@ -85,7 +89,7 @@ func NewProgressBar(writers ...io.Writer) *ProgressBar {
// Add adds a new progress bar.
func (p *ProgressBar) Add(prompt, name string, size int64, reader io.Reader) io.Reader {
// Return the reader directly if progress is disabled.
if disableProgress {
if disableProgress.Load() {
return reader
}

Expand Down
Loading