Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade cheggaaa/pb from v1.0.27 to v3.0.1 #5025

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/blang/semver v3.5.0+incompatible
github.com/c4milo/gotoolkit v0.0.0-20170318115440-bcc06269efa9 // indirect
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/cheggaaa/pb v1.0.27
github.com/cheggaaa/pb/v3 v3.0.1
github.com/cloudfoundry-attic/jibber_jabber v0.0.0-20151120183258-bcc4c8345a21
github.com/cloudfoundry/jibber_jabber v0.0.0-20151120183258-bcc4c8345a21 // indirect
github.com/docker/docker v1.13.1 // indirect
Expand All @@ -35,7 +35,6 @@ require (
github.com/johanneswuerbach/nfsexports v0.0.0-20181204082207-1aa528dcb345
github.com/libvirt/libvirt-go v3.4.0+incompatible
github.com/machine-drivers/docker-machine-driver-vmware v0.1.1
github.com/mattn/go-colorable v0.1.2 // indirect
github.com/mattn/go-isatty v0.0.8
github.com/mitchellh/go-ps v0.0.0-20170309133038-4fdf99ab2936
github.com/moby/hyperkit v0.0.0-20171020124204-a12cd7250bcd
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ github.com/Sirupsen/logrus v0.0.0-20170822132746-89742aefa4b2 h1:k1A7eIeUk6rnX2y
github.com/Sirupsen/logrus v0.0.0-20170822132746-89742aefa4b2/go.mod h1:rmk17hk6i8ZSAJkSDa7nOxamrG+SP4P0mm+DAvExv4U=
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d h1:G0m3OIz70MZUWq3EgK3CesDbo8upS2Vm9/P3FtgI+Jk=
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
github.com/VividCortex/ewma v1.1.1 h1:MnEK4VOv6n0RSY4vtRe3h11qjxL3+t0B8yOL8iMXdcM=
github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA=
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
Expand All @@ -59,6 +61,8 @@ github.com/cespare/prettybench v0.0.0-20150116022406-03b8cfe5406c/go.mod h1:Xe6Z
github.com/chai2010/gettext-go v0.0.0-20160711120539-c6fed771bfd5/go.mod h1:/iP1qXHoty45bqomnu2LM+VVyAEdWN+vtSHGlQgyxbw=
github.com/cheggaaa/pb v1.0.27 h1:wIkZHkNfC7R6GI5w7l/PdAdzXzlrbcI3p8OAlnkTsnc=
github.com/cheggaaa/pb v1.0.27/go.mod h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXHm81s=
github.com/cheggaaa/pb/v3 v3.0.1 h1:m0BngUk2LuSRYdx4fujDKNRXNDpbNCfptPfVT2m6OJY=
github.com/cheggaaa/pb/v3 v3.0.1/go.mod h1:SqqeMF/pMOIu3xgGoxtPYhMNQP258xE4x/XRTYua+KU=
github.com/client9/misspell v0.0.0-20170928000206-9ce5d979ffda/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cloudflare/cfssl v0.0.0-20180726162950-56268a613adf/go.mod h1:yMWuSON2oQp+43nFtAV/uvKQIFpSPerB57DCt9t8sSA=
Expand Down
42 changes: 13 additions & 29 deletions pkg/util/progressbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,19 @@ limitations under the License.
package util

import (
"fmt"
"io"
"path/filepath"
"sync"

"github.com/cheggaaa/pb"
"github.com/golang/glog"
"github.com/cheggaaa/pb/v3"
"github.com/hashicorp/go-getter"
)

var defaultProgressBar getter.ProgressTracker = &progressBar{}

type progressBar struct {
lock sync.Mutex
pool *pb.Pool
pbs int
lock sync.Mutex
progress *pb.ProgressBar
}

// TrackProgress instantiates a new progress bar that will
Expand All @@ -45,38 +42,25 @@ type progressBar struct {
func (cpb *progressBar) TrackProgress(src string, currentSize, totalSize int64, stream io.ReadCloser) io.ReadCloser {
cpb.lock.Lock()
defer cpb.lock.Unlock()

if cpb.pool == nil {
cpb.pool = pb.NewPool()
if err := cpb.pool.Start(); err != nil {
glog.Errorf("pool start: %v", err)
}
if cpb.progress == nil {
cpb.progress = pb.New64(totalSize)
}
tmpl := `{{ string . "filePath" }} {{ bar . "-" "█" (cycle . "↖" "↗" "↘" "↙" ) "." "-"}} {{speed . }} {{percent .}} {{ rtime . " ETA - %s"}} {{ etime . " Elapsed - %s"}}`
blueelvis marked this conversation as resolved.
Show resolved Hide resolved
p := pb.ProgressBarTemplate(tmpl).Start64(totalSize)
p.Set("filePath", filepath.Base(src))
p.SetCurrent(currentSize)
p.Set(pb.Bytes, true)

p := pb.New64(totalSize)
p.Set64(currentSize)
p.SetUnits(pb.U_BYTES)
p.Prefix(fmt.Sprintf(" %s:", filepath.Base(src)))
// Just a hair less than 80 (standard terminal width) for aesthetics & pasting into docs
p.SetWidth(78)
cpb.pool.Add(p)
reader := p.NewProxyReader(stream)
p.SetWidth(79)
barReader := p.NewProxyReader(stream)

cpb.pbs++
return &readCloser{
Reader: reader,
Reader: barReader,
close: func() error {
cpb.lock.Lock()
defer cpb.lock.Unlock()

p.Finish()
cpb.pbs--
if cpb.pbs <= 0 {
if err := cpb.pool.Stop(); err != nil {
glog.Errorf("pool stop: %v", err)
}
cpb.pool = nil
}
return nil
},
}
Expand Down