From bb59a70e8f41fc2fa6c3dc89552e788bcdf37359 Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Thu, 6 Sep 2018 16:49:15 +0200 Subject: [PATCH] progressbar: use int64 instead of uint64 * it's what's used for file sizes and used lib --- common/download.go | 10 +++++----- packer/progressbar.go | 22 +++++++++++----------- packer/rpc/ui.go | 8 ++++---- packer/rpc/ui_test.go | 4 ++-- provisioner/file/provisioner.go | 2 +- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/common/download.go b/common/download.go index 0d3e9fc0e..592cd2975 100644 --- a/common/download.go +++ b/common/download.go @@ -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) diff --git a/packer/progressbar.go b/packer/progressbar.go index ac181757e..c9b8d7d4b 100644 --- a/packer/progressbar.go +++ b/packer/progressbar.go @@ -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 } diff --git a/packer/rpc/ui.go b/packer/rpc/ui.go index c06329772..c9d3ef176 100644 --- a/packer/rpc/ui.go +++ b/packer/rpc/ui.go @@ -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 } diff --git a/packer/rpc/ui_test.go b/packer/rpc/ui_test.go index 42c68292f..078b85e44 100644 --- a/packer/rpc/ui_test.go +++ b/packer/rpc/ui_test.go @@ -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 } diff --git a/provisioner/file/provisioner.go b/provisioner/file/provisioner.go index 7ae675f26..1be9f1885 100644 --- a/provisioner/file/provisioner.go +++ b/provisioner/file/provisioner.go @@ -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