@cryptotaxi247 / kubo / commits / 8d2d9185f

gc: handle errs in toRawCids()

Not that they will ever happen in the current implementation, but it makes the linter happy and covers our back for future.

Hector Sanjuan committed Feb 28, 2020 at 14:17 UTC 8d2d9185fb36b03e44339a97d373dc5f044999d8
1 file changed +11 -4
gc/gc.go
+11 -4
@@ -29,13 +29,13 @@ type Result struct {
29 }
30
31 // converts a set of CIDs with different codecs to a set of CIDs with the raw codec.
32 -func toRawCids(set *cid.Set) *cid.Set {
32 +func toRawCids(set *cid.Set) (*cid.Set, error) {
33 newSet := cid.NewSet()
34 - set.ForEach(func(c cid.Cid) error {
34 + err := set.ForEach(func(c cid.Cid) error {
35 newSet.Add(cid.NewCidV1(cid.Raw, c.Hash()))
36 return nil
37 })
38 - return newSet
38 + return newSet, err
39 }
40
41 // GC performs a mark and sweep garbage collection of the blocks in the blockstore
@@ -72,7 +72,14 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, dstor dstore.Datastore, pn
72 }
73
74 // The blockstore reports raw blocks. We need to remove the codecs from the CIDs.
75 - gcs = toRawCids(gcs)
75 + gcs, err = toRawCids(gcs)
76 + if err != nil {
77 + select {
78 + case output <- Result{Error: err}:
79 + case <-ctx.Done():
80 + }
81 + return
82 + }
83
84 keychan, err := bs.AllKeysChan(ctx)
85 if err != nil {