Skip to content

Commit

Permalink
pb: Do not exceed the specified total transfer bytes (#2685)
Browse files Browse the repository at this point in the history
mc, via minio-go, can retries some requests for many reasons, such as, network
disconnect. This commit ensures that the progress bar does not show transfered
bytes greater then the total transfered bytes to avoid confusing users.
  • Loading branch information
vadmeste authored and kannappanr committed Feb 13, 2019
1 parent 38965dd commit bc1a108
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions cmd/progress-bar.go
Expand Up @@ -17,8 +17,6 @@
package cmd

import (
"errors"
"io"
"runtime"
"strings"
"time"
Expand All @@ -32,10 +30,6 @@ import (
// progress extender.
type progressBar struct {
*pb.ProgressBar
reader io.Reader
readerLength int64
bytesRead int64
isResume bool
}

// newProgressBar - instantiate a progress bar.
Expand Down Expand Up @@ -102,18 +96,17 @@ func (p *progressBar) Set64(length int64) *progressBar {
return p
}

func (p *progressBar) Seek(offset int64, whence int) (n int64, err error) {
switch whence {
case io.SeekStart:
p.ProgressBar = p.ProgressBar.Set64(offset)
return offset, nil
case io.SeekCurrent:
return p.ProgressBar.Add64(offset), nil
case io.SeekEnd:
p.ProgressBar.Set64(p.ProgressBar.Total - offset)
return p.ProgressBar.Total - offset, nil
}
return 0, errors.New("invalid argument")
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)
}
}()

return p.ProgressBar.Read(buf)
}

func (p *progressBar) SetTotal(total int64) *progressBar {
Expand Down

0 comments on commit bc1a108

Please sign in to comment.