@cryptotaxi247 / kubo / commits / ee98540e0

blockstore: fix force behavior

Steven Allen committed Aug 23, 2019 at 17:37 UTC ee98540e00a6970c3277325f30bd04501b706498
1 file changed +14 -5
blocks/blockstoreutil/remove.go
+14 -5
@@ -8,7 +8,6 @@ import (
8 "github.com/ipfs/go-ipfs/pin"
9
10 cid "github.com/ipfs/go-cid"
11 - ds "github.com/ipfs/go-datastore"
11 bs "github.com/ipfs/go-ipfs-blockstore"
12 )
13
@@ -47,10 +46,20 @@ func RmBlocks(blocks bs.GCBlockstore, pins pin.Pinner, cids []cid.Cid, opts RmBl
46 stillOkay := FilterPinned(pins, out, cids)
47
48 for _, c := range stillOkay {
50 - err := blocks.DeleteBlock(c)
51 - if err != nil && opts.Force && (err == bs.ErrNotFound || err == ds.ErrNotFound) {
52 - // ignore non-existent blocks
53 - } else if err != nil {
49 + // Kept for backwards compatibility. We may want to
50 + // remove this sometime in the future.
51 + has, err := blocks.Has(c)
52 + if err != nil {
53 + out <- &RemovedBlock{Hash: c.String(), Error: err.Error()}
54 + continue
55 + }
56 + if !has && !opts.Force {
57 + out <- &RemovedBlock{Hash: c.String(), Error: bs.ErrNotFound.Error()}
58 + continue
59 + }
60 +
61 + err = blocks.DeleteBlock(c)
62 + if err != nil {
63 out <- &RemovedBlock{Hash: c.String(), Error: err.Error()}
64 } else if !opts.Quiet {
65 out <- &RemovedBlock{Hash: c.String()}