mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-25 23:21:54 +08:00
Merge pull request #2893 from ipfs/fix/add-progress-bar
fix progress bar in add
This commit is contained in:
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
},
|
||||
|
Reference in New Issue
Block a user