Commit 6bf29205 authored by Steven Allen's avatar Steven Allen Committed by Jeromy

remove progress bar size hack

Compute the size in the PostCmd instead of the PreCmd.

License: MIT
Signed-off-by: default avatarSteven Allen <steven@stebalien.com>
parent 5583c442
package commands
import (
"context"
"errors"
"fmt"
"io"
......@@ -138,28 +137,6 @@ You can now check what blocks have been created by:
req.Options[progressOptionName] = true
}
sizeFile, ok := req.Files.(files.SizeFile)
if !ok {
// we don't need to error, the progress bar just won't know how big the files are
log.Warning("cannot determine size of input file")
return nil
}
// HACK! Using context to pass the size to PostRun
sizeCh := make(chan int64, 1)
req.Context = context.WithValue(req.Context, "size", sizeCh)
go func() {
size, err := sizeFile.Size()
if err != nil {
log.Warningf("error getting files size: %s", err)
// see comment above
return
}
sizeCh <- size
}()
return nil
},
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:
reNext, res := cmds.NewChanResponsePair(req)
outChan := make(chan interface{})
sizeChan := make(chan int64, 1)
sizeFile, ok := req.Files.(files.SizeFile)
if ok {
// Could be slow.
go func() {
size, err := sizeFile.Size()
if err != nil {
log.Warningf("error getting files size: %s", err)
// see comment above
return
}
sizeChan <- size
}()
} else {
// we don't need to error, the progress bar just
// won't know how big the files are
log.Warning("cannot determine size of input file")
}
progressBar := func(wait chan struct{}) {
defer close(wait)
......@@ -367,10 +365,6 @@ You can now check what blocks have been created by:
bar.Start()
}
// HACK! using context to pass size from PreRun
var sizeChan chan int64
sizeChan, _ = req.Context.Value("size").(chan int64)
lastFile := ""
lastHash := ""
var totalProgress, prevFiles, lastBytes int64
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment