"block rm": Document RemovedBlock. Interface tweaks.
License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>
Kevin Atkinson committed
Sep 15, 2016 at 13:41 UTC
d04308240d4205623780013ba48608c4e125d1a3
1 file changed
+11
-8
blocks/blockstore/util/remove.go
+11
-8
@@ -11,6 +11,12 @@ import (
11
cid "gx/ipfs/QmfSc2xehWmWLnwwYR91Y8QF4xdASypTFVknutoKQS3GHp/go-cid"
12
)
13
14
+// RemovedBlock is used to respresent the result of removing a block.
15
+// If a block was removed successfully than the Error string will be
16
+// empty. If a block could not be removed than Error will contain the
17
+// reason the block could not be removed. If the removal was aborted
18
+// due to a fatal error Hash will be be empty, Error will contain the
19
+// reason, and no more results will be sent.
20
type RemovedBlock struct {
21
Hash string `json:",omitempty"`
22
Error string `json:",omitempty"`
@@ -29,11 +35,7 @@ func RmBlocks(blocks bs.GCBlockstore, pins pin.Pinner, out chan<- interface{}, c
35
unlocker := blocks.GCLock()
36
defer unlocker.Unlock()
37
32
- stillOkay, err := checkIfPinned(pins, cids, out)
33
- if err != nil {
34
- out <- &RemovedBlock{Error: fmt.Sprintf("pin check failed: %s", err)}
35
- return
36
- }
38
+ stillOkay := FilterPinned(pins, out, cids)
39
40
for _, c := range stillOkay {
41
err := blocks.DeleteBlock(key.Key(c.Hash()))
@@ -49,11 +51,12 @@ func RmBlocks(blocks bs.GCBlockstore, pins pin.Pinner, out chan<- interface{}, c
51
return nil
52
}
53
52
-func checkIfPinned(pins pin.Pinner, cids []*cid.Cid, out chan<- interface{}) ([]*cid.Cid, error) {
54
+func FilterPinned(pins pin.Pinner, out chan<- interface{}, cids []*cid.Cid) []*cid.Cid {
55
stillOkay := make([]*cid.Cid, 0, len(cids))
56
res, err := pins.CheckIfPinned(cids...)
57
if err != nil {
56
- return nil, err
58
+ out <- &RemovedBlock{Error: fmt.Sprintf("pin check failed: %s", err)}
59
+ return nil
60
}
61
for _, r := range res {
62
if !r.Pinned() {
@@ -65,7 +68,7 @@ func checkIfPinned(pins pin.Pinner, cids []*cid.Cid, out chan<- interface{}) ([]
68
}
69
}
70
}
68
- return stillOkay, nil
71
+ return stillOkay
72
}
73
74
func ProcRmOutput(in <-chan interface{}, sout io.Writer, serr io.Writer) error {