提交 4fdfbc7d 作者: Jeromy

compute add size in background to not stall add operation

License: MIT
Signed-off-by: 's avatarJeromy <jeromyj@gmail.com>
上级 dc2e343a
...@@ -65,14 +65,19 @@ remains to be implemented. ...@@ -65,14 +65,19 @@ remains to be implemented.
return nil return nil
} }
sizeCh := make(chan int64, 1)
req.Values()["size"] = sizeCh
go func() {
size, err := sizeFile.Size() size, err := sizeFile.Size()
if err != nil { if err != nil {
// see comment above // see comment above
return nil return
} }
log.Debugf("Total size of file being added: %v\n", size) log.Debugf("Total size of file being added: %v\n", size)
req.Values()["size"] = size sizeCh <- size
}()
return nil return nil
}, },
...@@ -189,17 +194,12 @@ remains to be implemented. ...@@ -189,17 +194,12 @@ remains to be implemented.
return return
} }
size := int64(0) showProgressBar := !quiet
s, found := req.Values()["size"]
if found {
size = s.(int64)
}
showProgressBar := !quiet && size >= progressBarMinSize
var bar *pb.ProgressBar var bar *pb.ProgressBar
var terminalWidth int var terminalWidth int
if showProgressBar { if showProgressBar {
bar = pb.New64(size).SetUnits(pb.U_BYTES) bar = pb.New64(0).SetUnits(pb.U_BYTES)
bar.ManualUpdate = true bar.ManualUpdate = true
bar.Start() bar.Start()
...@@ -215,10 +215,22 @@ remains to be implemented. ...@@ -215,10 +215,22 @@ remains to be implemented.
bar.Update() bar.Update()
} }
var sizeChan chan int64
s, found := req.Values()["size"]
if found {
sizeChan = s.(chan int64)
}
lastFile := "" lastFile := ""
var totalProgress, prevFiles, lastBytes int64 var totalProgress, prevFiles, lastBytes int64
for out := range outChan { LOOP:
for {
select {
case out, ok := <-outChan:
if !ok {
break LOOP
}
output := out.(*coreunix.AddedObject) output := out.(*coreunix.AddedObject)
if len(output.Hash) > 0 { if len(output.Hash) > 0 {
if showProgressBar { if showProgressBar {
...@@ -253,6 +265,12 @@ remains to be implemented. ...@@ -253,6 +265,12 @@ remains to be implemented.
if showProgressBar { if showProgressBar {
bar.Update() bar.Update()
} }
case size := <-sizeChan:
bar.Total = size
bar.ShowPercent = true
bar.ShowBar = true
bar.ShowTimeLeft = true
}
} }
}, },
Type: coreunix.AddedObject{}, Type: coreunix.AddedObject{},
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论