Pinner: Provide Pinned.String() method and use it in "block rm"
License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>
Kevin Atkinson committed
Aug 21, 2016 at 09:39 UTC
0a459f65ac7fa9cb957a2294f106e5bf8d460031
2 files changed
+24
-10
core/commands/block.go
+4
-10
@@ -308,19 +308,13 @@ func checkIfPinned(pins pin.Pinner, cids []*cid.Cid, out chan<- interface{}) ([]
308
return nil, err
309
}
310
for _, r := range res {
311
- switch r.Mode {
312
- case pin.NotPinned:
311
+ if !r.Pinned() {
312
stillOkay = append(stillOkay, r.Key)
314
- case pin.Indirect:
313
+ } else {
314
out <- &RemovedBlock{
315
Hash: r.Key.String(),
317
- Error: fmt.Sprintf("pinned via %s", r.Via)}
318
- default:
319
- modeStr, _ := pin.PinModeToString(r.Mode)
320
- out <- &RemovedBlock{
321
- Hash: r.Key.String(),
322
- Error: fmt.Sprintf("pinned: %s", modeStr)}
323
-
316
+ Error: r.String(),
317
+ }
318
}
319
}
320
return stillOkay, nil
pin/pin.go
+20
@@ -111,6 +111,26 @@ type Pinned struct {
111
Via *cid.Cid
112
}
113
114
+func (p Pinned) Pinned() bool {
115
+ if p.Mode == NotPinned {
116
+ return false
117
+ } else {
118
+ return true
119
+ }
120
+}
121
+
122
+func (p Pinned) String() string {
123
+ switch p.Mode {
124
+ case NotPinned:
125
+ return "not pinned"
126
+ case Indirect:
127
+ return fmt.Sprintf("pinned via %s", p.Via)
128
+ default:
129
+ modeStr, _ := PinModeToString(p.Mode)
130
+ return fmt.Sprintf("pinned: %s", modeStr)
131
+ }
132
+}
133
+
134
// pinner implements the Pinner interface
135
type pinner struct {
136
lock sync.RWMutex