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.
This commit is contained in:
Hector Sanjuan 2020-02-28 14:17:59 +01:00 committed by Adin Schmahmann
parent fc56055892
commit 8d2d9185fb

View File

@ -29,13 +29,13 @@ type Result struct {
}
// converts a set of CIDs with different codecs to a set of CIDs with the raw codec.
func toRawCids(set *cid.Set) *cid.Set {
func toRawCids(set *cid.Set) (*cid.Set, error) {
newSet := cid.NewSet()
set.ForEach(func(c cid.Cid) error {
err := set.ForEach(func(c cid.Cid) error {
newSet.Add(cid.NewCidV1(cid.Raw, c.Hash()))
return nil
})
return newSet
return newSet, err
}
// 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
}
// The blockstore reports raw blocks. We need to remove the codecs from the CIDs.
gcs = toRawCids(gcs)
gcs, err = toRawCids(gcs)
if err != nil {
select {
case output <- Result{Error: err}:
case <-ctx.Done():
}
return
}
keychan, err := bs.AllKeysChan(ctx)
if err != nil {