Skip to content

Commit

Permalink
"block rm": remove the option to ignore pins
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Kevin Atkinson <[email protected]>
  • Loading branch information
kevina committed Aug 15, 2016
1 parent efeb789 commit c88b4b0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 38 deletions.
35 changes: 7 additions & 28 deletions core/commands/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,7 @@ It takes a list of base58 encoded multihashs to remove.
Arguments: []cmds.Argument{
cmds.StringArg("hash", true, true, "Bash58 encoded multihash of block(s) to remove."),
},
Options: []cmds.Option{
cmds.BoolOption("ignore-pins", "Ignore pins.").Default(false),
},
Run: func(req cmds.Request, res cmds.Response) {
ignorePins, _, err := req.Option("ignore-pins").Bool()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
n, err := req.InvocContext().GetNode()
if err != nil {
res.SetError(err, cmds.ErrNormal)
Expand All @@ -225,9 +217,6 @@ It takes a list of base58 encoded multihashs to remove.
go func() {
defer close(outChan)
pinning := n.Pinning
if ignorePins {
pinning = nil
}
err := rmBlocks(n.Blockstore, pinning, outChan, keys)
if err != nil {
outChan <- &RemovedBlock{Error: err.Error()}
Expand Down Expand Up @@ -271,25 +260,15 @@ type RemovedBlock struct {
Error string `json:",omitempty"`
}

// pins may be nil
func rmBlocks(blocks bs.GCBlockstore, pins pin.Pinner, out chan<- interface{}, keys []key.Key) error {
var unlocker bs.Unlocker
defer func() {
if unlocker != nil {
unlocker.Unlock()
}
}()
stillOkay := keys
if pins != nil {
// Need to make sure that some operation that is
// finishing with a pin is ocurr simultaneously.
unlocker = blocks.GCLock()
var err error
stillOkay, err = checkIfPinned(pins, keys, out)
if err != nil {
return fmt.Errorf("pin check failed: %s", err)
}
unlocker := blocks.GCLock()
defer unlocker.Unlock()

stillOkay, err := checkIfPinned(pins, keys, out)
if err != nil {
return fmt.Errorf("pin check failed: %s", err)
}

for _, k := range stillOkay {
err := blocks.DeleteBlock(k)
if err != nil {
Expand Down
11 changes: 1 addition & 10 deletions test/sharness/t0050-block.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,7 @@ test_expect_success "can't remove indirectly pinned block: output looks good" '
grep -q "$FILE1HASH: pinned via $DIRHASH" block_rm_err
'

test_expect_success "multi-block 'ipfs block rm --ignore-pins' succeeds" '
ipfs block rm --ignore-pins $DIRHASH >actual_rm
'

test_expect_success "multi-block 'ipfs block rm --ignore-pins' output looks good" '
echo "removed $DIRHASH" > expected_rm &&
test_cmp expected_rm actual_rm
'

test_expect_success "fix up pins" '
test_expect_success "remove pin" '
ipfs pin rm -r $DIRHASH
'

Expand Down

0 comments on commit c88b4b0

Please sign in to comment.