progressbar: use int64 instead of uint64

* it's what's used for file sizes and used lib
This commit is contained in:
Adrien Delorme 2018-09-06 16:49:15 +02:00
parent f9c58e2b1f
commit bb59a70e8f
5 changed files with 23 additions and 23 deletions

View File

@ -242,7 +242,7 @@ func (d *HTTPDownloader) Download(dst *os.File, src *url.URL) error {
return err
}
var current uint64
var current int64
// Make the request. We first make a HEAD request so we can check
// if the server supports range queries. If the server/URL doesn't
@ -286,7 +286,7 @@ func (d *HTTPDownloader) Download(dst *os.File, src *url.URL) error {
if _, err = dst.Seek(0, os.SEEK_END); err == nil {
req.Header.Set("Range", fmt.Sprintf("bytes=%d-", fi.Size()))
current = uint64(fi.Size())
current = fi.Size()
}
}
}
@ -313,7 +313,7 @@ func (d *HTTPDownloader) Download(dst *os.File, src *url.URL) error {
return fmt.Errorf("HTTP error: %s", err.Error())
}
total := current + uint64(resp.ContentLength)
total := current + resp.ContentLength
bar := d.ProgressBar()
bar.Start(total)
@ -429,7 +429,7 @@ func (d *FileDownloader) Download(dst *os.File, src *url.URL) error {
bar := d.ProgressBar()
bar.Start(uint64(fi.Size()))
bar.Start(fi.Size())
defer bar.Finish()
fProxy := bar.NewProxyReader(f)
@ -531,7 +531,7 @@ func (d *SMBDownloader) Download(dst *os.File, src *url.URL) error {
bar := d.ProgressBar()
bar.Start(uint64(fi.Size()))
bar.Start(fi.Size())
defer bar.Finish()
fProxy := bar.NewProxyReader(f)

View File

@ -12,15 +12,15 @@ import (
// ProgressBar allows to graphically display
// a self refreshing progress bar.
type ProgressBar interface {
Start(total uint64)
Add(current uint64)
Start(total int64)
Add(current int64)
NewProxyReader(r io.Reader) (proxy io.Reader)
Finish()
}
type StackableProgressBar struct {
items int32
total uint64
total int64
started bool
BasicProgressBar
startOnce sync.Once
@ -42,12 +42,12 @@ func (spb *StackableProgressBar) start() {
}()
}
func (spb *StackableProgressBar) Start(total uint64) {
atomic.AddUint64(&spb.total, total)
func (spb *StackableProgressBar) Start(total int64) {
atomic.AddInt64(&spb.total, total)
atomic.AddInt32(&spb.items, 1)
spb.group.Add(1)
spb.startOnce.Do(spb.start)
spb.SetTotal64(int64(atomic.LoadUint64(&spb.total)))
spb.SetTotal64(atomic.LoadInt64(&spb.total))
spb.prefix()
}
@ -67,12 +67,12 @@ type BasicProgressBar struct {
var _ ProgressBar = new(BasicProgressBar)
func (bpb *BasicProgressBar) Start(total uint64) {
func (bpb *BasicProgressBar) Start(total int64) {
bpb.SetTotal64(int64(total))
bpb.ProgressBar.Start()
}
func (bpb *BasicProgressBar) Add(current uint64) {
func (bpb *BasicProgressBar) Add(current int64) {
bpb.ProgressBar.Add64(int64(current))
}
func (bpb *BasicProgressBar) NewProxyReader(r io.Reader) io.Reader {
@ -94,8 +94,8 @@ type NoopProgressBar struct {
var _ ProgressBar = new(NoopProgressBar)
func (npb *NoopProgressBar) Start(uint64) {}
func (npb *NoopProgressBar) Add(uint64) {}
func (npb *NoopProgressBar) Start(int64) {}
func (npb *NoopProgressBar) Add(int64) {}
func (npb *NoopProgressBar) Finish() {}
func (npb *NoopProgressBar) NewProxyReader(r io.Reader) io.Reader { return r }
func (npb *NoopProgressBar) NewProxyReadCloser(r io.ReadCloser) io.ReadCloser { return r }
@ -109,7 +109,7 @@ type ProxyReader struct {
func (r *ProxyReader) Read(p []byte) (n int, err error) {
n, err = r.Reader.Read(p)
r.ProgressBar.Add(uint64(n))
r.ProgressBar.Add(int64(n))
return
}

View File

@ -73,11 +73,11 @@ func (u *Ui) ProgressBar() packer.ProgressBar {
var _ packer.ProgressBar = new(Ui)
func (pb *Ui) Start(total uint64) {
func (pb *Ui) Start(total int64) {
pb.client.Call("Ui.Start", total, new(interface{}))
}
func (pb *Ui) Add(current uint64) {
func (pb *Ui) Add(current int64) {
pb.client.Call("Ui.Add", current, new(interface{}))
}
@ -134,12 +134,12 @@ func (pb *UiServer) Finish(_ string, _ *interface{}) error {
return nil
}
func (pb *UiServer) Start(total uint64, _ *interface{}) error {
func (pb *UiServer) Start(total int64, _ *interface{}) error {
pb.ui.ProgressBar().Start(total)
return nil
}
func (pb *UiServer) Add(current uint64, _ *interface{}) error {
func (pb *UiServer) Add(current int64, _ *interface{}) error {
pb.ui.ProgressBar().Add(current)
return nil
}

View File

@ -60,11 +60,11 @@ func (u *testUi) ProgressBar() packer.ProgressBar {
return u
}
func (u *testUi) Start(uint64) {
func (u *testUi) Start(int64) {
u.progressBarStartCalled = true
}
func (u *testUi) Add(uint64) {
func (u *testUi) Add(int64) {
u.progressBarAddCalled = true
}

View File

@ -177,7 +177,7 @@ func (p *Provisioner) ProvisionUpload(ui packer.Ui, comm packer.Communicator) er
// Get a default progress bar
bar := ui.ProgressBar()
bar.Start(uint64(info.Size()))
bar.Start(info.Size())
defer bar.Finish()
// Create ProxyReader for the current progress