@cryptotaxi247 / kubo / commits / c83bbafbb

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>

Kevin Atkinson committed Mar 7, 2017 at 03:02 UTC c83bbafbbc422e484f42ef4c18aa1b2d2e849d51
1 file changed +10 -12
core/commands/repo.go
+10 -12
@@ -74,28 +74,26 @@ order to reclaim hard disk space.
74
75 go func() {
76 defer close(outChan)
77 - unreportedError := false
78 - var lastErr error
77 if streamErrors {
78 + errs := false
79 for res := range gcOutChan {
81 - if unreportedError {
82 - outChan <- &GcResult{Error: lastErr.Error()}
83 - unreportedError = false
84 - }
80 if res.Error != nil {
86 - lastErr = res.Error
87 - unreportedError = true
81 + outChan <- &GcResult{Error: res.Error.Error()}
82 + errs = true
83 } else {
84 outChan <- &GcResult{Key: res.KeyRemoved}
85 }
86 }
87 + if errs {
88 + res.SetError(fmt.Errorf("encountered errors during gc run"), cmds.ErrNormal)
89 + }
90 } else {
93 - lastErr = corerepo.CollectResult(req.Context(), gcOutChan, func(k *cid.Cid) {
91 + err := corerepo.CollectResult(req.Context(), gcOutChan, func(k *cid.Cid) {
92 outChan <- &GcResult{Key: k}
93 })
96 - }
97 - if lastErr != nil {
98 - res.SetError(lastErr, cmds.ErrNormal)
94 + if err != nil {
95 + res.SetError(err, cmds.ErrNormal)
96 + }
97 }
98 }()
99 },