Skip to content

Commit

Permalink
Merge pull request #2893 from ipfs/fix/add-progress-bar
Browse files Browse the repository at this point in the history
fix progress bar in add
  • Loading branch information
whyrusleeping committed Jun 23, 2016
2 parents 6e45e9d + f26d8c7 commit a72feed
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
7 changes: 6 additions & 1 deletion commands/files/serialfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,16 @@ func (f *serialFile) Size() (int64, error) {
}

var du int64
err := filepath.Walk(f.FileName(), func(p string, fi os.FileInfo, err error) error {
err := filepath.Walk(f.FullPath(), func(p string, fi os.FileInfo, err error) error {
if err != nil {
return err
}

if fi != nil && fi.Mode()&(os.ModeSymlink|os.ModeNamedPipe) == 0 {
du += fi.Size()
}
return nil
})

return du, err
}
18 changes: 6 additions & 12 deletions core/commands/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,22 +242,13 @@ You can now refer to the added file in a gateway, like so:
}

var bar *pb.ProgressBar
var terminalWidth int
if progress {
bar = pb.New64(0).SetUnits(pb.U_BYTES)
bar.ManualUpdate = true
bar.ShowTimeLeft = false
bar.ShowPercent = false
bar.Output = res.Stderr()
bar.Start()

// the progress bar lib doesn't give us a way to get the width of the output,
// so as a hack we just use a callback to measure the output, then git rid of it
terminalWidth = 0
bar.Callback = func(line string) {
terminalWidth = len(line)
bar.Callback = nil
bar.Output = res.Stderr()
log.Infof("terminal width: %v\n", terminalWidth)
}
bar.Update()
}

var sizeChan chan int64
Expand Down Expand Up @@ -317,6 +308,9 @@ You can now refer to the added file in a gateway, like so:
bar.ShowBar = true
bar.ShowTimeLeft = true
}
case <-req.Context().Done():
res.SetError(req.Context().Err(), cmds.ErrNormal)
return
}
}
},
Expand Down

0 comments on commit a72feed

Please sign in to comment.