mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-09 18:28:08 +08:00
fix pinning UX, and add tests to match
This commit is contained in:
parent
5b20e86ed4
commit
ccb36277dd
@ -55,7 +55,7 @@ func Unpin(n *core.IpfsNode, paths []string, recursive bool) ([]u.Key, error) {
|
||||
var unpinned []u.Key
|
||||
for _, dagnode := range dagnodes {
|
||||
k, _ := dagnode.Key()
|
||||
err := n.Pinning.Unpin(k)
|
||||
err := n.Pinning.Unpin(k, recursive)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
20
pin/pin.go
20
pin/pin.go
@ -31,7 +31,7 @@ const (
|
||||
type Pinner interface {
|
||||
IsPinned(util.Key) bool
|
||||
Pin(*mdag.Node, bool) error
|
||||
Unpin(util.Key) error
|
||||
Unpin(util.Key, bool) error
|
||||
Flush() error
|
||||
GetManual() ManualPinner
|
||||
DirectKeys() []util.Key
|
||||
@ -111,17 +111,21 @@ func (p *pinner) Pin(node *mdag.Node, recurse bool) error {
|
||||
}
|
||||
|
||||
// Unpin a given key
|
||||
func (p *pinner) Unpin(k util.Key) error {
|
||||
func (p *pinner) Unpin(k util.Key, recursive bool) error {
|
||||
p.lock.Lock()
|
||||
defer p.lock.Unlock()
|
||||
if p.recursePin.HasKey(k) {
|
||||
p.recursePin.RemoveBlock(k)
|
||||
node, err := p.dserv.Get(k)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if recursive {
|
||||
p.recursePin.RemoveBlock(k)
|
||||
node, err := p.dserv.Get(k)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return p.unpinLinks(node)
|
||||
return p.unpinLinks(node)
|
||||
} else {
|
||||
return errors.New("Key pinned recursively.")
|
||||
}
|
||||
} else if p.directPin.HasKey(k) {
|
||||
p.directPin.RemoveBlock(k)
|
||||
return nil
|
||||
|
||||
@ -100,8 +100,8 @@ func TestPinnerBasic(t *testing.T) {
|
||||
t.Fatal("pinned node not found.")
|
||||
}
|
||||
|
||||
// Test unpin
|
||||
err = p.Unpin(dk)
|
||||
// Test recursive unpin
|
||||
err = p.Unpin(dk, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@ -25,7 +25,7 @@ test_expect_success "added file was pinned" '
|
||||
|
||||
test_expect_success "'ipfs pin rm' succeeds" '
|
||||
echo Unpinned `cat hashfile` > expected
|
||||
ipfs pin rm `cat hashfile` > actual
|
||||
ipfs pin rm -r `cat hashfile` > actual
|
||||
test_cmp expected actual
|
||||
'
|
||||
|
||||
@ -45,14 +45,21 @@ test_expect_success "pinning directly should fail now" '
|
||||
test_cmp expected actual
|
||||
'
|
||||
|
||||
test_expect_success "'ipfs pin rm <hash>' should fail" '
|
||||
echo Error: Key pinned recursively. > expected
|
||||
ipfs pin rm `cat hashfile` 2> error
|
||||
test_cmp expected error
|
||||
'
|
||||
|
||||
test_expect_success "remove recursive pin, add direct" '
|
||||
echo Unpinned `cat hashfile` > expected
|
||||
ipfs pin rm `cat hashfile` > actual
|
||||
ipfs pin rm -r `cat hashfile` > actual
|
||||
test_cmp expected actual
|
||||
ipfs pin add `cat hashfile`
|
||||
'
|
||||
|
||||
test_expect_success "remove direct pin" '
|
||||
echo Unpinned `cat hashfile` > expected
|
||||
ipfs pin rm `cat hashfile` > actual
|
||||
test_cmp expected actual
|
||||
'
|
||||
|
||||
Loading…
Reference in New Issue
Block a user