From 8e505f291fe84d28538d796c3cb2774c2399cd1d Mon Sep 17 00:00:00 2001 From: Jeromy Date: Wed, 22 Jun 2016 17:09:35 -0700 Subject: [PATCH 1/2] fix progress bar in add License: MIT Signed-off-by: Jeromy --- commands/files/serialfile.go | 7 ++++++- core/commands/add.go | 15 +++------------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/commands/files/serialfile.go b/commands/files/serialfile.go index 520aa81e0..22de5c1b4 100644 --- a/commands/files/serialfile.go +++ b/commands/files/serialfile.go @@ -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 } diff --git a/core/commands/add.go b/core/commands/add.go index 2198dedca..17cb7e65c 100644 --- a/core/commands/add.go +++ b/core/commands/add.go @@ -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 From f26d8c7b4657f51aa81749d15a962e6b6831ac18 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Wed, 22 Jun 2016 17:16:34 -0700 Subject: [PATCH 2/2] respect context cancellation in add License: MIT Signed-off-by: Jeromy --- core/commands/add.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/commands/add.go b/core/commands/add.go index 17cb7e65c..5daf71705 100644 --- a/core/commands/add.go +++ b/core/commands/add.go @@ -308,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 } } },