mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-24 03:47:45 +08:00
gc: stream all errors including the last
and report "encountered errors during gc run" as the response error License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>
This commit is contained in:
parent
f338520aa8
commit
c83bbafbbc
@ -74,28 +74,26 @@ order to reclaim hard disk space.
|
||||
|
||||
go func() {
|
||||
defer close(outChan)
|
||||
unreportedError := false
|
||||
var lastErr error
|
||||
if streamErrors {
|
||||
errs := false
|
||||
for res := range gcOutChan {
|
||||
if unreportedError {
|
||||
outChan <- &GcResult{Error: lastErr.Error()}
|
||||
unreportedError = false
|
||||
}
|
||||
if res.Error != nil {
|
||||
lastErr = res.Error
|
||||
unreportedError = true
|
||||
outChan <- &GcResult{Error: res.Error.Error()}
|
||||
errs = true
|
||||
} else {
|
||||
outChan <- &GcResult{Key: res.KeyRemoved}
|
||||
}
|
||||
}
|
||||
if errs {
|
||||
res.SetError(fmt.Errorf("encountered errors during gc run"), cmds.ErrNormal)
|
||||
}
|
||||
} 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}
|
||||
})
|
||||
}
|
||||
if lastErr != nil {
|
||||
res.SetError(lastErr, cmds.ErrNormal)
|
||||
if err != nil {
|
||||
res.SetError(err, cmds.ErrNormal)
|
||||
}
|
||||
}
|
||||
}()
|
||||
},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user