remove progress bar size hack
Compute the size in the PostCmd instead of the PreCmd. License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>
Steven Allen committed
Jan 11, 2018 at 12:39 UTC
6bf29205bc236987ea2557efdf34611e1f3186cd
1 file changed
+21
-27
core/commands/add.go
+21
-27
@@ -1,7 +1,6 @@
1
package commands
2
3
import (
4
- "context"
4
"errors"
5
"fmt"
6
"io"
@@ -138,28 +137,6 @@ You can now check what blocks have been created by:
137
req.Options[progressOptionName] = true
138
}
139
141
- sizeFile, ok := req.Files.(files.SizeFile)
142
- if !ok {
143
- // we don't need to error, the progress bar just won't know how big the files are
144
- log.Warning("cannot determine size of input file")
145
- return nil
146
- }
147
-
148
- // HACK! Using context to pass the size to PostRun
149
- sizeCh := make(chan int64, 1)
150
- req.Context = context.WithValue(req.Context, "size", sizeCh)
151
-
152
- go func() {
153
- size, err := sizeFile.Size()
154
- if err != nil {
155
- log.Warningf("error getting files size: %s", err)
156
- // see comment above
157
- return
158
- }
159
-
160
- sizeCh <- size
161
- }()
162
-
140
return nil
141
},
142
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) {
@@ -348,6 +325,27 @@ You can now check what blocks have been created by:
325
reNext, res := cmds.NewChanResponsePair(req)
326
outChan := make(chan interface{})
327
328
+ sizeChan := make(chan int64, 1)
329
+
330
+ sizeFile, ok := req.Files.(files.SizeFile)
331
+ if ok {
332
+ // Could be slow.
333
+ go func() {
334
+ size, err := sizeFile.Size()
335
+ if err != nil {
336
+ log.Warningf("error getting files size: %s", err)
337
+ // see comment above
338
+ return
339
+ }
340
+
341
+ sizeChan <- size
342
+ }()
343
+ } else {
344
+ // we don't need to error, the progress bar just
345
+ // won't know how big the files are
346
+ log.Warning("cannot determine size of input file")
347
+ }
348
+
349
progressBar := func(wait chan struct{}) {
350
defer close(wait)
351
@@ -367,10 +365,6 @@ You can now check what blocks have been created by:
365
bar.Start()
366
}
367
370
- // HACK! using context to pass size from PreRun
371
- var sizeChan chan int64
372
- sizeChan, _ = req.Context.Value("size").(chan int64)
373
-
368
lastFile := ""
369
lastHash := ""
370
var totalProgress, prevFiles, lastBytes int64