Skip to content
Snippets Groups Projects
Commit 6bf29205 authored by Steven Allen's avatar Steven Allen Committed by Jeromy Johnson
Browse files

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
No related branches found
No related tags found
No related merge requests found
package commands package commands
import ( import (
"context"
"errors" "errors"
"fmt" "fmt"
"io" "io"
...@@ -138,28 +137,6 @@ You can now check what blocks have been created by: ...@@ -138,28 +137,6 @@ You can now check what blocks have been created by:
req.Options[progressOptionName] = true 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 return nil
}, },
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) { 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: ...@@ -348,6 +325,27 @@ You can now check what blocks have been created by:
reNext, res := cmds.NewChanResponsePair(req) reNext, res := cmds.NewChanResponsePair(req)
outChan := make(chan interface{}) 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{}) { progressBar := func(wait chan struct{}) {
defer close(wait) defer close(wait)
...@@ -367,10 +365,6 @@ You can now check what blocks have been created by: ...@@ -367,10 +365,6 @@ You can now check what blocks have been created by:
bar.Start() bar.Start()
} }
// HACK! using context to pass size from PreRun
var sizeChan chan int64
sizeChan, _ = req.Context.Value("size").(chan int64)
lastFile := "" lastFile := ""
lastHash := "" lastHash := ""
var totalProgress, prevFiles, lastBytes int64 var totalProgress, prevFiles, lastBytes int64
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment