Skip to content

Commit a72feed

Browse files
Merge pull request #2893 from ipfs/fix/add-progress-bar
fix progress bar in add
2 parents 6e45e9d + f26d8c7 commit a72feed

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

commands/files/serialfile.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,16 @@ func (f *serialFile) Size() (int64, error) {
131131
}
132132

133133
var du int64
134-
err := filepath.Walk(f.FileName(), func(p string, fi os.FileInfo, err error) error {
134+
err := filepath.Walk(f.FullPath(), func(p string, fi os.FileInfo, err error) error {
135+
if err != nil {
136+
return err
137+
}
138+
135139
if fi != nil && fi.Mode()&(os.ModeSymlink|os.ModeNamedPipe) == 0 {
136140
du += fi.Size()
137141
}
138142
return nil
139143
})
144+
140145
return du, err
141146
}

core/commands/add.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -242,22 +242,13 @@ You can now refer to the added file in a gateway, like so:
242242
}
243243

244244
var bar *pb.ProgressBar
245-
var terminalWidth int
246245
if progress {
247246
bar = pb.New64(0).SetUnits(pb.U_BYTES)
248247
bar.ManualUpdate = true
248+
bar.ShowTimeLeft = false
249+
bar.ShowPercent = false
250+
bar.Output = res.Stderr()
249251
bar.Start()
250-
251-
// the progress bar lib doesn't give us a way to get the width of the output,
252-
// so as a hack we just use a callback to measure the output, then git rid of it
253-
terminalWidth = 0
254-
bar.Callback = func(line string) {
255-
terminalWidth = len(line)
256-
bar.Callback = nil
257-
bar.Output = res.Stderr()
258-
log.Infof("terminal width: %v\n", terminalWidth)
259-
}
260-
bar.Update()
261252
}
262253

263254
var sizeChan chan int64
@@ -317,6 +308,9 @@ You can now refer to the added file in a gateway, like so:
317308
bar.ShowBar = true
318309
bar.ShowTimeLeft = true
319310
}
311+
case <-req.Context().Done():
312+
res.SetError(req.Context().Err(), cmds.ErrNormal)
313+
return
320314
}
321315
}
322316
},

0 commit comments

Comments
 (0)