mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-24 22:38:27 +08:00
pin rm fails appropriately for indirect pins
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
This commit is contained in:
22
pin/pin.go
22
pin/pin.go
@ -126,18 +126,26 @@ func (p *pinner) Pin(ctx context.Context, node *mdag.Node, recurse bool) error {
|
|||||||
func (p *pinner) Unpin(ctx context.Context, k key.Key, recursive bool) error {
|
func (p *pinner) Unpin(ctx context.Context, k key.Key, recursive bool) error {
|
||||||
p.lock.Lock()
|
p.lock.Lock()
|
||||||
defer p.lock.Unlock()
|
defer p.lock.Unlock()
|
||||||
if p.recursePin.HasKey(k) {
|
reason, pinned, err := p.isPinned(k)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !pinned {
|
||||||
|
return fmt.Errorf("%s is not pinned", k)
|
||||||
|
}
|
||||||
|
switch reason {
|
||||||
|
case "recursive":
|
||||||
if recursive {
|
if recursive {
|
||||||
p.recursePin.RemoveBlock(k)
|
p.recursePin.RemoveBlock(k)
|
||||||
return nil
|
return nil
|
||||||
} else {
|
} else {
|
||||||
return fmt.Errorf("%s is pinned recursively", k)
|
return fmt.Errorf("%s is pinned recursively", k)
|
||||||
}
|
}
|
||||||
} else if p.directPin.HasKey(k) {
|
case "direct":
|
||||||
p.directPin.RemoveBlock(k)
|
p.directPin.RemoveBlock(k)
|
||||||
return nil
|
return nil
|
||||||
} else {
|
default:
|
||||||
return fmt.Errorf("%s is not pinned", k)
|
return fmt.Errorf("%s is pinned indirectly under %s", k, reason)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,6 +159,12 @@ func (p *pinner) isInternalPin(key key.Key) bool {
|
|||||||
func (p *pinner) IsPinned(k key.Key) (string, bool, error) {
|
func (p *pinner) IsPinned(k key.Key) (string, bool, error) {
|
||||||
p.lock.RLock()
|
p.lock.RLock()
|
||||||
defer p.lock.RUnlock()
|
defer p.lock.RUnlock()
|
||||||
|
return p.isPinned(k)
|
||||||
|
}
|
||||||
|
|
||||||
|
// isPinned is the implementation of IsPinned that does not lock.
|
||||||
|
// intended for use by other pinned methods that already take locks
|
||||||
|
func (p *pinner) isPinned(k key.Key) (string, bool, error) {
|
||||||
if p.recursePin.HasKey(k) {
|
if p.recursePin.HasKey(k) {
|
||||||
return "recursive", true, nil
|
return "recursive", true, nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user