mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 10:27:46 +08:00
pin: don't walk all pinned blocks when removing a non-existent pin
We do this _just_ to make the error nicer but it's really slow. Additionally, we do it while holding the pin lock, blocking all other pin operations. fixes #6295 License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>
This commit is contained in:
parent
fdbd501f6f
commit
f0addb4319
26
pin/pin.go
26
pin/pin.go
@ -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 {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user