From 1e1480f4088399d9bf951db137c9f202e348ef02 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sat, 30 Nov 2019 17:19:23 -0800 Subject: [PATCH] Fix progress bar update regression (#2976) Regression introduced in cf6defe0252f9cd28bdf42c5e6426d2151e690f0 --- cmd/mirror-main.go | 10 +++++++--- cmd/status.go | 8 ++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/cmd/mirror-main.go b/cmd/mirror-main.go index 7f6eb7c9..f805a7f8 100644 --- a/cmd/mirror-main.go +++ b/cmd/mirror-main.go @@ -267,6 +267,7 @@ func (mj *mirrorJob) doMirror(ctx context.Context, cancelMirror context.CancelFu // and accounting readers under relevant conditions. if mj.isFake { mj.status.Add(sURLs.SourceContent.Size) + mj.status.Update() return sURLs.WithError(nil) } @@ -440,7 +441,8 @@ func (mj *mirrorJob) watchMirror(ctx context.Context, cancelMirror context.Cance if shouldQueue || mj.isOverwrite { // adjust total, because we want to show progress of // the item still queued to be copied. - mj.status.SetTotal(mj.status.Get() + sourceContent.Size).Update() + mj.status.Add(sourceContent.Size) + mj.status.SetTotal(mj.status.Get()).Update() mj.status.AddCounts(1) mirrorURL.TotalSize = mj.status.Get() mirrorURL.TotalCount = mj.status.GetCounts() @@ -470,7 +472,8 @@ func (mj *mirrorJob) watchMirror(ctx context.Context, cancelMirror context.Cance mirrorURL.SourceContent.Size = event.Size // adjust total, because we want to show progress // of the itemj stiil queued to be copied. - mj.status.SetTotal(mj.status.Get() + mirrorURL.SourceContent.Size).Update() + mj.status.Add(mirrorURL.SourceContent.Size) + mj.status.SetTotal(mj.status.Get()).Update() mj.status.AddCounts(1) mirrorURL.TotalSize = mj.status.Get() mirrorURL.TotalCount = mj.status.GetCounts() @@ -541,8 +544,9 @@ func (mj *mirrorJob) startMirror(ctx context.Context, cancelMirror context.Cance } } - mj.status.AddCounts(1) mj.status.Add(sURLs.SourceContent.Size) + mj.status.SetTotal(mj.status.Get()).Update() + mj.status.AddCounts(1) // Save total count. sURLs.TotalCount = mj.status.GetCounts() diff --git a/cmd/status.go b/cmd/status.go index 2d64f4c9..eb39b6ee 100644 --- a/cmd/status.go +++ b/cmd/status.go @@ -87,7 +87,7 @@ func (qs *QuietStatus) AddCounts(v int64) { // SetTotal sets the total of the progressbar, ignored for quietstatus func (qs *QuietStatus) SetTotal(v int64) Status { - qs.accounter.Total = v + qs.accounter.Set(v) return qs } @@ -102,7 +102,7 @@ func (qs *QuietStatus) Get() int64 { // Total returns the total number of bytes func (qs *QuietStatus) Total() int64 { - return qs.accounter.Total + return qs.accounter.Get() } // Add bytes to current number of bytes @@ -189,12 +189,12 @@ func (ps *ProgressStatus) Get() int64 { // Total returns the total number of bytes func (ps *ProgressStatus) Total() int64 { - return ps.progressBar.Total + return ps.progressBar.Get() } // SetTotal sets the total of the progressbar func (ps *ProgressStatus) SetTotal(v int64) Status { - ps.progressBar.Total = v + ps.progressBar.SetTotal(v) return ps }