diff --git a/go.mod b/go.mod index ee1ae7ba12..e5594ec531 100644 --- a/go.mod +++ b/go.mod @@ -60,7 +60,7 @@ require ( github.com/stretchr/testify v1.8.4 github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 github.com/ulikunitz/xz v0.5.11 - github.com/vbauerster/mpb/v8 v8.6.1 + github.com/vbauerster/mpb/v8 v8.6.2 github.com/vishvananda/netlink v1.2.1-beta.2 go.etcd.io/bbolt v1.3.7 golang.org/x/exp v0.0.0-20230905200255-921286631fa9 diff --git a/go.sum b/go.sum index 748c7b4c57..a8fdd77914 100644 --- a/go.sum +++ b/go.sum @@ -1026,8 +1026,8 @@ github.com/urfave/cli v1.22.12/go.mod h1:sSBEIC79qR6OvcmsD4U3KABeOTxDqQtdDnaFuUN github.com/vbatts/tar-split v0.11.2/go.mod h1:vV3ZuO2yWSVsz+pfFzDG/upWH1JhjOiEaWq6kXyQ3VI= github.com/vbatts/tar-split v0.11.5 h1:3bHCTIheBm1qFTcgh9oPu+nNBtX+XJIupG/vacinCts= github.com/vbatts/tar-split v0.11.5/go.mod h1:yZbwRsSeGjusneWgA781EKej9HF8vme8okylkAeNKLk= -github.com/vbauerster/mpb/v8 v8.6.1 h1:XbBpIbJxJOO9yMcKPpI4oEFPW6tLAptefNQJNcGWri8= -github.com/vbauerster/mpb/v8 v8.6.1/go.mod h1:S0tuIjikxlLxCeNijNhwAuD/BB3UE/d2nygG8SOldk0= +github.com/vbauerster/mpb/v8 v8.6.2 h1:9EhnJGQRtvgDVCychJgR96EDCOqgg2NsMuk5JUcX4DA= +github.com/vbauerster/mpb/v8 v8.6.2/go.mod h1:oVJ7T+dib99kZ/VBjoBaC8aPXiSAihnzuKmotuihyFo= github.com/vishvananda/netlink v0.0.0-20181108222139-023a6dafdcdf/go.mod h1:+SR5DhBJrl6ZM7CoCKvpw5BKroDKQ+PJqOg65H/2ktk= github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYppBueQtXaqoE= github.com/vishvananda/netlink v1.1.1-0.20201029203352-d40f9887b852/go.mod h1:twkDnbuQxJYemMlGd4JFIcuhgX83tXhKS2B/PRMpOho= diff --git a/vendor/github.com/vbauerster/mpb/v8/bar.go b/vendor/github.com/vbauerster/mpb/v8/bar.go index 7d83268ce0..5f81412109 100644 --- a/vendor/github.com/vbauerster/mpb/v8/bar.go +++ b/vendor/github.com/vbauerster/mpb/v8/bar.go @@ -61,7 +61,6 @@ type renderFrame struct { shutdown int rmOnComplete bool noPop bool - done bool err error } @@ -82,10 +81,10 @@ func newBar(ctx context.Context, container *Progress, bs *bState) *Bar { return bar } -// ProxyReader wraps io.Reader with metrics required for progress tracking. -// If `r` is 'unknown total/size' reader it's mandatory to call -// (*Bar).SetTotal(-1, true) method after (io.Reader).Read returns io.EOF. -// If bar is already completed or aborted, returns nil. +// ProxyReader wraps io.Reader with metrics required for progress +// tracking. If `r` is 'unknown total/size' reader it's mandatory +// to call `(*Bar).SetTotal(-1, true)` after the wrapper returns +// `io.EOF`. If bar is already completed or aborted, returns nil. // Panics if `r` is nil. func (b *Bar) ProxyReader(r io.Reader) io.ReadCloser { if r == nil { @@ -177,11 +176,10 @@ func (b *Bar) TraverseDecorators(cb func(decor.Decorator)) { } } -// EnableTriggerComplete enables triggering complete event. It's -// effective only for bars which were constructed with `total <= 0` and -// after total has been set with (*Bar).SetTotal(int64, false). If bar -// has been incremented to the total, complete event is triggered right -// away. +// EnableTriggerComplete enables triggering complete event. It's effective +// only for bars which were constructed with `total <= 0` and after total +// has been set with `(*Bar).SetTotal(int64, false)`. If `curren >= total` +// at the moment of call, complete event is triggered right away. func (b *Bar) EnableTriggerComplete() { select { case b.operateState <- func(s *bState) { @@ -200,11 +198,11 @@ func (b *Bar) EnableTriggerComplete() { } } -// SetTotal sets total to an arbitrary value. It's effective only for -// bar which was constructed with `total <= 0`. Setting total to negative -// value is equivalent to (*Bar).SetTotal((*Bar).Current(), bool) but faster. -// If triggerCompletion is true, total value is set to current and -// complete event is triggered right away. +// SetTotal sets total to an arbitrary value. It's effective only for bar +// which was constructed with `total <= 0`. Setting total to negative value +// is equivalent to `(*Bar).SetTotal((*Bar).Current(), bool)` but faster. If +// triggerCompletion is true, total value is set to current and complete +// event is triggered right away. func (b *Bar) SetTotal(total int64, triggerCompletion bool) { select { case b.operateState <- func(s *bState) { @@ -344,7 +342,7 @@ func (b *Bar) SetPriority(priority int) { // Abort interrupts bar's running goroutine. Abort won't be engaged // if bar is already in complete state. If drop is true bar will be // removed as well. To make sure that bar has been removed call -// (*Bar).Wait method. +// `(*Bar).Wait()` method. func (b *Bar) Abort(drop bool) { select { case b.operateState <- func(s *bState) { @@ -415,7 +413,6 @@ func (b *Bar) serve(ctx context.Context, bs *bState) { } func (b *Bar) render(tw int) { - var done bool fn := func(s *bState) { var rows []io.Reader stat := newStatistics(tw, s) @@ -437,7 +434,6 @@ func (b *Bar) render(tw int) { shutdown: s.shutdown, rmOnComplete: s.rmOnComplete, noPop: s.noPop, - done: done, } if s.completed || s.aborted { // post increment makes sure OnComplete decorators are rendered @@ -448,7 +444,6 @@ func (b *Bar) render(tw int) { select { case b.operateState <- fn: case <-b.done: - done = true fn(b.bs) } } diff --git a/vendor/github.com/vbauerster/mpb/v8/container_option.go b/vendor/github.com/vbauerster/mpb/v8/container_option.go index f2ab01ee02..177620e063 100644 --- a/vendor/github.com/vbauerster/mpb/v8/container_option.go +++ b/vendor/github.com/vbauerster/mpb/v8/container_option.go @@ -93,9 +93,9 @@ func WithAutoRefresh() ContainerOption { } } -// PopCompletedMode will pop completed bars to the top. -// To stop rendering bar after it has been popped, use -// mpb.BarRemoveOnComplete() option on that bar. +// PopCompletedMode pop completed bars out of progress container. +// In this mode completed bars get moved to the top and stop +// participating in rendering cycle. func PopCompletedMode() ContainerOption { return func(s *pState) { s.popCompleted = true diff --git a/vendor/github.com/vbauerster/mpb/v8/progress.go b/vendor/github.com/vbauerster/mpb/v8/progress.go index f275be3e5a..8c609b463f 100644 --- a/vendor/github.com/vbauerster/mpb/v8/progress.go +++ b/vendor/github.com/vbauerster/mpb/v8/progress.go @@ -18,8 +18,8 @@ const ( defaultRefreshRate = 150 * time.Millisecond ) -// DoneError represents an error when `*mpb.Progress` is done but its functionality is requested. -var DoneError = fmt.Errorf("%T instance can't be reused after it's done", (*Progress)(nil)) +// DoneError represents use after `(*Progress).Wait()` error. +var DoneError = fmt.Errorf("%T instance can't be reused after %[1]T.Wait()", (*Progress)(nil)) // Progress represents a container that renders one or more progress bars. type Progress struct { @@ -55,13 +55,13 @@ type pState struct { } // New creates new Progress container instance. It's not possible to -// reuse instance after (*Progress).Wait method has been called. +// reuse instance after `(*Progress).Wait` method has been called. func New(options ...ContainerOption) *Progress { return NewWithContext(context.Background(), options...) } // NewWithContext creates new Progress container instance with provided -// context. It's not possible to reuse instance after (*Progress).Wait +// context. It's not possible to reuse instance after `(*Progress).Wait` // method has been called. func NewWithContext(ctx context.Context, options ...ContainerOption) *Progress { if ctx == nil { @@ -133,8 +133,7 @@ func (p *Progress) New(total int64, builder BarFillerBuilder, options ...BarOpti // MustAdd creates a bar which renders itself by provided BarFiller. // If `total <= 0` triggering complete event by increment methods is -// disabled. Panics if *Progress instance is done, i.e. called after -// (*Progress).Wait(). +// disabled. Panics if called after `(*Progress).Wait()`. func (p *Progress) MustAdd(total int64, filler BarFiller, options ...BarOption) *Bar { bar, err := p.Add(total, filler, options...) if err != nil { @@ -145,8 +144,8 @@ func (p *Progress) MustAdd(total int64, filler BarFiller, options ...BarOption) // Add creates a bar which renders itself by provided BarFiller. // If `total <= 0` triggering complete event by increment methods -// is disabled. If *Progress instance is done, i.e. called after -// (*Progress).Wait(), return error == DoneError. +// is disabled. If called after `(*Progress).Wait()` then +// `(nil, DoneError)` is returned. func (p *Progress) Add(total int64, filler BarFiller, options ...BarOption) (*Bar, error) { if filler == nil { filler = NopStyle().Build() @@ -203,7 +202,7 @@ func (p *Progress) traverseBars(cb func(b *Bar) bool) { // UpdateBarPriority either immediately or lazy. // With lazy flag order is updated after the next refresh cycle. -// If you don't care about laziness just use *Bar.SetPriority(int). +// If you don't care about laziness just use `(*Bar).SetPriority(int)`. func (p *Progress) UpdateBarPriority(b *Bar, priority int, lazy bool) { if b == nil { return @@ -215,9 +214,9 @@ func (p *Progress) UpdateBarPriority(b *Bar, priority int, lazy bool) { } // Write is implementation of io.Writer. -// Writing to `*mpb.Progress` will print lines above a running bar. +// Writing to `*Progress` will print lines above a running bar. // Writes aren't flushed immediately, but at next refresh cycle. -// If Write is called after `*mpb.Progress` is done, `mpb.DoneError` +// If called after `(*Progress).Wait()` then `(0, DoneError)` // is returned. func (p *Progress) Write(b []byte) (int, error) { type result struct { @@ -238,7 +237,7 @@ func (p *Progress) Write(b []byte) (int, error) { } // Wait waits for all bars to complete and finally shutdowns container. After -// this method has been called, there is no way to reuse (*Progress) instance. +// this method has been called, there is no way to reuse `*Progress` instance. func (p *Progress) Wait() { // wait for user wg, if any if p.uwg != nil { @@ -249,9 +248,9 @@ func (p *Progress) Wait() { p.Shutdown() } -// Shutdown cancels any running bar immediately and then shutdowns (*Progress) +// Shutdown cancels any running bar immediately and then shutdowns `*Progress` // instance. Normally this method shouldn't be called unless you know what you -// are doing. Proper way to shutdown is to call (*Progress).Wait() instead. +// are doing. Proper way to shutdown is to call `(*Progress).Wait()` instead. func (p *Progress) Shutdown() { p.cancel() p.pwg.Wait() @@ -357,7 +356,7 @@ func (s *pState) render(cw *cwriter.Writer) (err error) { func (s *pState) flush(cw *cwriter.Writer, height int) error { var wg sync.WaitGroup - defer wg.Wait() // waiting for all s.hm.push to complete + defer wg.Wait() // waiting for all s.push to complete var popCount int var rows []io.Reader @@ -381,40 +380,34 @@ func (s *pState) flush(cw *cwriter.Writer, height int) error { _, _ = io.Copy(io.Discard, row) } } - if frame.shutdown != 0 && !frame.done { + + switch frame.shutdown { + case 1: + b.cancel() if qb, ok := s.queueBars[b]; ok { - b.cancel() delete(s.queueBars, b) qb.priority = b.priority wg.Add(1) - go func(b *Bar) { - s.hm.push(b, true) - wg.Done() - }(qb) - continue + go s.push(&wg, qb, true) + } else if s.popCompleted && !frame.noPop { + b.priority = s.popPriority + s.popPriority++ + wg.Add(1) + go s.push(&wg, b, false) + } else if !frame.rmOnComplete { + wg.Add(1) + go s.push(&wg, b, false) } + case 2: if s.popCompleted && !frame.noPop { - switch frame.shutdown { - case 1: - b.priority = s.popPriority - s.popPriority++ - default: - b.cancel() - popCount += usedRows - continue - } - } else if frame.rmOnComplete { - b.cancel() + popCount += usedRows continue - } else { - b.cancel() } + fallthrough + default: + wg.Add(1) + go s.push(&wg, b, false) } - wg.Add(1) - go func(b *Bar) { - s.hm.push(b, false) - wg.Done() - }(b) } for i := len(rows) - 1; i >= 0; i-- { @@ -427,6 +420,11 @@ func (s *pState) flush(cw *cwriter.Writer, height int) error { return cw.Flush(len(rows) - popCount) } +func (s pState) push(wg *sync.WaitGroup, b *Bar, sync bool) { + s.hm.push(b, sync) + wg.Done() +} + func (s pState) makeBarState(total int64, filler BarFiller, options ...BarOption) *bState { bs := &bState{ id: s.idCount, diff --git a/vendor/modules.txt b/vendor/modules.txt index 5384dd78e2..375b9c2450 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1004,7 +1004,7 @@ github.com/ulikunitz/xz/lzma github.com/vbatts/tar-split/archive/tar github.com/vbatts/tar-split/tar/asm github.com/vbatts/tar-split/tar/storage -# github.com/vbauerster/mpb/v8 v8.6.1 +# github.com/vbauerster/mpb/v8 v8.6.2 ## explicit; go 1.17 github.com/vbauerster/mpb/v8 github.com/vbauerster/mpb/v8/cwriter