"block rm": remove the option to ignore pins
License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>
Kevin Atkinson committed
Aug 14, 2016 at 23:46 UTC
c88b4b0941ae240a0de70f78c435a6e4339d3f40
2 files changed
+8
-38
core/commands/block.go
+7
-28
@@ -200,15 +200,7 @@ It takes a list of base58 encoded multihashs to remove.
200
Arguments: []cmds.Argument{
201
cmds.StringArg("hash", true, true, "Bash58 encoded multihash of block(s) to remove."),
202
},
203
- Options: []cmds.Option{
204
- cmds.BoolOption("ignore-pins", "Ignore pins.").Default(false),
205
- },
203
Run: func(req cmds.Request, res cmds.Response) {
207
- ignorePins, _, err := req.Option("ignore-pins").Bool()
208
- if err != nil {
209
- res.SetError(err, cmds.ErrNormal)
210
- return
211
- }
204
n, err := req.InvocContext().GetNode()
205
if err != nil {
206
res.SetError(err, cmds.ErrNormal)
@@ -225,9 +217,6 @@ It takes a list of base58 encoded multihashs to remove.
217
go func() {
218
defer close(outChan)
219
pinning := n.Pinning
228
- if ignorePins {
229
- pinning = nil
230
- }
220
err := rmBlocks(n.Blockstore, pinning, outChan, keys)
221
if err != nil {
222
outChan <- &RemovedBlock{Error: err.Error()}
@@ -271,25 +260,15 @@ type RemovedBlock struct {
260
Error string `json:",omitempty"`
261
}
262
274
-// pins may be nil
263
func rmBlocks(blocks bs.GCBlockstore, pins pin.Pinner, out chan<- interface{}, keys []key.Key) error {
276
- var unlocker bs.Unlocker
277
- defer func() {
278
- if unlocker != nil {
279
- unlocker.Unlock()
280
- }
281
- }()
282
- stillOkay := keys
283
- if pins != nil {
284
- // Need to make sure that some operation that is
285
- // finishing with a pin is ocurr simultaneously.
286
- unlocker = blocks.GCLock()
287
- var err error
288
- stillOkay, err = checkIfPinned(pins, keys, out)
289
- if err != nil {
290
- return fmt.Errorf("pin check failed: %s", err)
291
- }
264
+ unlocker := blocks.GCLock()
265
+ defer unlocker.Unlock()
266
+
267
+ stillOkay, err := checkIfPinned(pins, keys, out)
268
+ if err != nil {
269
+ return fmt.Errorf("pin check failed: %s", err)
270
}
271
+
272
for _, k := range stillOkay {
273
err := blocks.DeleteBlock(k)
274
if err != nil {
test/sharness/t0050-block.sh
+1
-10
@@ -82,16 +82,7 @@ test_expect_success "can't remove indirectly pinned block: output looks good" '
82
grep -q "$FILE1HASH: pinned via $DIRHASH" block_rm_err
83
'
84
85
-test_expect_success "multi-block 'ipfs block rm --ignore-pins' succeeds" '
86
- ipfs block rm --ignore-pins $DIRHASH >actual_rm
87
-'
88
-
89
-test_expect_success "multi-block 'ipfs block rm --ignore-pins' output looks good" '
90
- echo "removed $DIRHASH" > expected_rm &&
91
- test_cmp expected_rm actual_rm
92
-'
93
-
94
-test_expect_success "fix up pins" '
85
+test_expect_success "remove pin" '
86
ipfs pin rm -r $DIRHASH
87
'
88