Fix mirror stats with --quiet flag (#4703)

This commit is contained in:
Anis Eleuch
2023-10-02 08:03:54 -06:00
committed by GitHub
parent d8ace59107
commit 67fa4aa7a3
3 changed files with 16 additions and 10 deletions
+12 -4
View File
@@ -32,7 +32,7 @@ import (
type accounter struct {
current int64
Total int64
total int64
startTime time.Time
startValue int64
refreshRate time.Duration
@@ -44,7 +44,7 @@ type accounter struct {
// Instantiate a new accounter.
func newAccounter(total int64) *accounter {
acct := &accounter{
Total: total,
total: total,
startTime: time.Now(),
startValue: 0,
refreshRate: time.Millisecond * 200,
@@ -112,7 +112,7 @@ func (a *accounter) Stat() accountStat {
var acntStat accountStat
a.finishOnce.Do(func() {
close(a.isFinished)
acntStat.Total = a.Total
acntStat.Total = a.total
acntStat.Transferred = atomic.LoadInt64(&a.current)
acntStat.Speed = a.write(atomic.LoadInt64(&a.current))
})
@@ -139,7 +139,8 @@ func (a *accounter) Get() int64 {
return atomic.LoadInt64(&a.current)
}
func (a *accounter) SetTotal(int64) {
func (a *accounter) SetTotal(n int64) {
atomic.StoreInt64(&a.total, n)
}
// Add add to current value atomically.
@@ -149,6 +150,13 @@ func (a *accounter) Add(n int64) int64 {
// Read implements Reader which internally updates current value.
func (a *accounter) Read(p []byte) (n int, err error) {
defer func() {
// Upload retry can read one object twice; Avoid read to be greater than Total
if n, t := a.Get(), atomic.LoadInt64(&a.total); t > 0 && n > t {
a.Set(t)
}
}()
n = len(p)
a.Add(int64(n))
return
+3 -5
View File
@@ -105,11 +105,9 @@ func (p *progressBar) Set64(length int64) *progressBar {
func (p *progressBar) Read(buf []byte) (n int, err error) {
defer func() {
// After updating the internal progress bar, make sure that its
// current progress doesn't exceed the specified total progress
currentProgress := p.ProgressBar.Get()
if currentProgress > p.ProgressBar.Total {
p.ProgressBar.Set64(p.ProgressBar.Total)
// Upload retry can read one object twice; Avoid read to be greater than Total
if n, t := p.ProgressBar.Get(), p.ProgressBar.Total; t > 0 && n > t {
p.ProgressBar.Set64(t)
}
}()
+1 -1
View File
@@ -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.Set(v)
qs.accounter.SetTotal(v)
return qs
}