提交 c83bbafb 作者: Kevin Atkinson

gc: stream all errors including the last

and report "encountered errors during gc run" as the response error

License: MIT
Signed-off-by: 's avatarKevin Atkinson <k@kevina.org>
上级 f338520a
...@@ -74,28 +74,26 @@ order to reclaim hard disk space. ...@@ -74,28 +74,26 @@ order to reclaim hard disk space.
go func() { go func() {
defer close(outChan) defer close(outChan)
unreportedError := false
var lastErr error
if streamErrors { if streamErrors {
errs := false
for res := range gcOutChan { for res := range gcOutChan {
if unreportedError {
outChan <- &GcResult{Error: lastErr.Error()}
unreportedError = false
}
if res.Error != nil { if res.Error != nil {
lastErr = res.Error outChan <- &GcResult{Error: res.Error.Error()}
unreportedError = true errs = true
} else { } else {
outChan <- &GcResult{Key: res.KeyRemoved} outChan <- &GcResult{Key: res.KeyRemoved}
} }
} }
if errs {
res.SetError(fmt.Errorf("encountered errors during gc run"), cmds.ErrNormal)
}
} else { } else {
lastErr = corerepo.CollectResult(req.Context(), gcOutChan, func(k *cid.Cid) { err := corerepo.CollectResult(req.Context(), gcOutChan, func(k *cid.Cid) {
outChan <- &GcResult{Key: k} outChan <- &GcResult{Key: k}
}) })
if err != nil {
res.SetError(err, cmds.ErrNormal)
} }
if lastErr != nil {
res.SetError(lastErr, cmds.ErrNormal)
} }
}() }()
}, },
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论