@@ -21,22 +21,19 @@ limitations under the License.
21
21
package util
22
22
23
23
import (
24
- "fmt"
25
24
"io"
26
25
"path/filepath"
27
26
"sync"
28
27
29
- "github.com/cheggaaa/pb"
30
- "github.com/golang/glog"
28
+ "github.com/cheggaaa/pb/v3"
31
29
"github.com/hashicorp/go-getter"
32
30
)
33
31
34
32
var defaultProgressBar getter.ProgressTracker = & progressBar {}
35
33
36
34
type progressBar struct {
37
- lock sync.Mutex
38
- pool * pb.Pool
39
- pbs int
35
+ lock sync.Mutex
36
+ progress * pb.ProgressBar
40
37
}
41
38
42
39
// TrackProgress instantiates a new progress bar that will
@@ -45,38 +42,24 @@ type progressBar struct {
45
42
func (cpb * progressBar ) TrackProgress (src string , currentSize , totalSize int64 , stream io.ReadCloser ) io.ReadCloser {
46
43
cpb .lock .Lock ()
47
44
defer cpb .lock .Unlock ()
48
-
49
- if cpb .pool == nil {
50
- cpb .pool = pb .NewPool ()
51
- if err := cpb .pool .Start (); err != nil {
52
- glog .Errorf ("pool start: %v" , err )
53
- }
45
+ if cpb .progress == nil {
46
+ cpb .progress = pb .New64 (totalSize )
54
47
}
48
+ p := pb .Full .Start64 (totalSize )
49
+ p .Set ("prefix" , filepath .Base (src + ": " ))
50
+ p .SetCurrent (currentSize )
51
+ p .Set (pb .Bytes , true )
55
52
56
- p := pb .New64 (totalSize )
57
- p .Set64 (currentSize )
58
- p .SetUnits (pb .U_BYTES )
59
- p .Prefix (fmt .Sprintf (" %s:" , filepath .Base (src )))
60
53
// Just a hair less than 80 (standard terminal width) for aesthetics & pasting into docs
61
- p .SetWidth (78 )
62
- cpb .pool .Add (p )
63
- reader := p .NewProxyReader (stream )
54
+ p .SetWidth (79 )
55
+ barReader := p .NewProxyReader (stream )
64
56
65
- cpb .pbs ++
66
57
return & readCloser {
67
- Reader : reader ,
58
+ Reader : barReader ,
68
59
close : func () error {
69
60
cpb .lock .Lock ()
70
61
defer cpb .lock .Unlock ()
71
-
72
62
p .Finish ()
73
- cpb .pbs --
74
- if cpb .pbs <= 0 {
75
- if err := cpb .pool .Stop (); err != nil {
76
- glog .Errorf ("pool stop: %v" , err )
77
- }
78
- cpb .pool = nil
79
- }
80
63
return nil
81
64
},
82
65
}
0 commit comments