Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hook reader to seek source and hook appropriately #1070

Merged
merged 1 commit into from Feb 7, 2019

Conversation

harshavardhana
Copy link
Member

No description provided.

@harshavardhana
Copy link
Member Author

To test this with mc you need following patch

 git diff cmd/progress-bar.go
diff --git a/cmd/progress-bar.go b/cmd/progress-bar.go
index 672639f0..ae87b059 100644
--- a/cmd/progress-bar.go
+++ b/cmd/progress-bar.go
@@ -17,6 +17,7 @@
 package cmd
 
 import (
+       "errors"
        "io"
        "runtime"
        "strings"
@@ -101,6 +102,20 @@ 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) SetTotal(total int64) *progressBar {
        p.ProgressBar.Total = total
        return p

@harshavardhana
Copy link
Member Author

ping @vadmeste

@vadmeste
Copy link
Member

vadmeste commented Feb 6, 2019

@harshavardhana I believe the testing code should be like this:

       case io.SeekCurrent:
+             currentOffset := p.ProgressBar.Get()
               return p.ProgressBar.Add64(currentOffset+offset), nil

Copy link
Member

@vadmeste vadmeste left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kannappanr kannappanr merged commit 34f2b94 into minio:master Feb 7, 2019
@harshavardhana harshavardhana deleted the fix-seeker branch February 7, 2019 01:09
@harshavardhana
Copy link
Member Author

               return p.ProgressBar.Add64(currentOffset+offset), nil

The Add64() already adds to the currentOffset, if we do this we would be adding more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants