Skip to content

Commit

Permalink
Merge pull request #6311 from ipfs/fix/6295
Browse files Browse the repository at this point in the history
pin: don't walk all pinned blocks when removing a non-existent pin
  • Loading branch information
Stebalien authored May 9, 2019
2 parents 857080b + f0addb4 commit e240316
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions pin/pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,32 +263,24 @@ func (p *pinner) Pin(ctx context.Context, node ipld.Node, recurse bool) error {
}

// ErrNotPinned is returned when trying to unpin items which are not pinned.
var ErrNotPinned = fmt.Errorf("not pinned")
var ErrNotPinned = fmt.Errorf("not pinned or pinned indirectly")

// Unpin a given key
func (p *pinner) Unpin(ctx context.Context, c cid.Cid, recursive bool) error {
p.lock.Lock()
defer p.lock.Unlock()
reason, pinned, err := p.isPinnedWithType(c, Any)
if err != nil {
return err
}
if !pinned {
return ErrNotPinned
}
switch reason {
case "recursive":
if recursive {
p.recursePin.Remove(c)
return nil
if p.recursePin.Has(c) {
if !recursive {
return fmt.Errorf("%s is pinned recursively", c)
}
return fmt.Errorf("%s is pinned recursively", c)
case "direct":
p.recursePin.Remove(c)
return nil
}
if p.directPin.Has(c) {
p.directPin.Remove(c)
return nil
default:
return fmt.Errorf("%s is pinned indirectly under %s", c, reason)
}
return ErrNotPinned
}

func (p *pinner) isInternalPin(c cid.Cid) bool {
Expand Down

0 comments on commit e240316

Please sign in to comment.