Skip to content

Commit e240316

Browse files
authored
Merge pull request #6311 from ipfs/fix/6295
pin: don't walk all pinned blocks when removing a non-existent pin
2 parents 857080b + f0addb4 commit e240316

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

pin/pin.go

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -263,32 +263,24 @@ func (p *pinner) Pin(ctx context.Context, node ipld.Node, recurse bool) error {
263263
}
264264

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

268268
// Unpin a given key
269269
func (p *pinner) Unpin(ctx context.Context, c cid.Cid, recursive bool) error {
270270
p.lock.Lock()
271271
defer p.lock.Unlock()
272-
reason, pinned, err := p.isPinnedWithType(c, Any)
273-
if err != nil {
274-
return err
275-
}
276-
if !pinned {
277-
return ErrNotPinned
278-
}
279-
switch reason {
280-
case "recursive":
281-
if recursive {
282-
p.recursePin.Remove(c)
283-
return nil
272+
if p.recursePin.Has(c) {
273+
if !recursive {
274+
return fmt.Errorf("%s is pinned recursively", c)
284275
}
285-
return fmt.Errorf("%s is pinned recursively", c)
286-
case "direct":
276+
p.recursePin.Remove(c)
277+
return nil
278+
}
279+
if p.directPin.Has(c) {
287280
p.directPin.Remove(c)
288281
return nil
289-
default:
290-
return fmt.Errorf("%s is pinned indirectly under %s", c, reason)
291282
}
283+
return ErrNotPinned
292284
}
293285

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

0 commit comments

Comments
 (0)