提交 ccb36277 作者: Jeromy

fix pinning UX, and add tests to match

上级 5b20e86e
......@@ -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
}
......
......@@ -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)
} else {
return errors.New("Key pinned recursively.")
}
return p.unpinLinks(node)
} 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
'
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论