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 progress bar in ipfs get #2948

Merged
merged 1 commit into from
Jul 6, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions core/commands/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ may also specify the level of compression by specifying '-l=<1-9>'.
return
}

size, err := dn.Size()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}

res.SetLength(size)

archive, _, _ := req.Option("archive").Bool()
reader, err := uarchive.DagArchive(ctx, dn, p.String(), node.DAG, archive, cmplvl)
if err != nil {
Expand Down Expand Up @@ -103,6 +111,7 @@ may also specify the level of compression by specifying '-l=<1-9>'.
Err: os.Stderr,
Archive: archive,
Compression: cmplvl,
Size: int64(res.Length()),
}

if err := gw.Write(outReader, outPath); err != nil {
Expand Down Expand Up @@ -149,6 +158,7 @@ type getWriter struct {

Archive bool
Compression int
Size int64
}

func (gw *getWriter) Write(r io.Reader, fpath string) error {
Expand Down Expand Up @@ -181,7 +191,7 @@ func (gw *getWriter) writeArchive(r io.Reader, fpath string) error {
defer file.Close()

fmt.Fprintf(gw.Out, "Saving archive to %s\n", fpath)
bar, barR := progressBarForReader(gw.Err, r, 0)
bar, barR := progressBarForReader(gw.Err, r, gw.Size)
bar.Start()
defer bar.Finish()

Expand All @@ -191,7 +201,7 @@ func (gw *getWriter) writeArchive(r io.Reader, fpath string) error {

func (gw *getWriter) writeExtracted(r io.Reader, fpath string) error {
fmt.Fprintf(gw.Out, "Saving file(s) to %s\n", fpath)
bar, barR := progressBarForReader(gw.Err, r, 0)
bar, barR := progressBarForReader(gw.Err, r, gw.Size)
bar.Start()
defer bar.Finish()

Expand Down