fix pinning UX, and add tests to match
Jeromy committed
Jan 20, 2015 at 03:47 UTC
ccb36277ddc13410e76dbae87beb7c0027056ef1
4 files changed
+24
-13
core/repo/pinning.go
+1
-1
@@ -55,7 +55,7 @@ func Unpin(n *core.IpfsNode, paths []string, recursive bool) ([]u.Key, error) {
55
var unpinned []u.Key
56
for _, dagnode := range dagnodes {
57
k, _ := dagnode.Key()
58
- err := n.Pinning.Unpin(k)
58
+ err := n.Pinning.Unpin(k, recursive)
59
if err != nil {
60
return nil, err
61
}
pin/pin.go
+12
-8
@@ -31,7 +31,7 @@ const (
31
type Pinner interface {
32
IsPinned(util.Key) bool
33
Pin(*mdag.Node, bool) error
34
- Unpin(util.Key) error
34
+ Unpin(util.Key, bool) error
35
Flush() error
36
GetManual() ManualPinner
37
DirectKeys() []util.Key
@@ -111,17 +111,21 @@ func (p *pinner) Pin(node *mdag.Node, recurse bool) error {
111
}
112
113
// Unpin a given key
114
-func (p *pinner) Unpin(k util.Key) error {
114
+func (p *pinner) Unpin(k util.Key, recursive bool) error {
115
p.lock.Lock()
116
defer p.lock.Unlock()
117
if p.recursePin.HasKey(k) {
118
- p.recursePin.RemoveBlock(k)
119
- node, err := p.dserv.Get(k)
120
- if err != nil {
121
- return err
118
+ if recursive {
119
+ p.recursePin.RemoveBlock(k)
120
+ node, err := p.dserv.Get(k)
121
+ if err != nil {
122
+ return err
123
+ }
124
+
125
+ return p.unpinLinks(node)
126
+ } else {
127
+ return errors.New("Key pinned recursively.")
128
}
123
-
124
- return p.unpinLinks(node)
129
} else if p.directPin.HasKey(k) {
130
p.directPin.RemoveBlock(k)
131
return nil
pin/pin_test.go
+2
-2
@@ -100,8 +100,8 @@ func TestPinnerBasic(t *testing.T) {
100
t.Fatal("pinned node not found.")
101
}
102
103
- // Test unpin
104
- err = p.Unpin(dk)
103
+ // Test recursive unpin
104
+ err = p.Unpin(dk, true)
105
if err != nil {
106
t.Fatal(err)
107
}
test/sharness/t0080-repo.sh
+9
-2
@@ -25,7 +25,7 @@ test_expect_success "added file was pinned" '
25
26
test_expect_success "'ipfs pin rm' succeeds" '
27
echo Unpinned `cat hashfile` > expected
28
- ipfs pin rm `cat hashfile` > actual
28
+ ipfs pin rm -r `cat hashfile` > actual
29
test_cmp expected actual
30
'
31
@@ -45,14 +45,21 @@ test_expect_success "pinning directly should fail now" '
45
test_cmp expected actual
46
'
47
48
+test_expect_success "'ipfs pin rm <hash>' should fail" '
49
+ echo Error: Key pinned recursively. > expected
50
+ ipfs pin rm `cat hashfile` 2> error
51
+ test_cmp expected error
52
+'
53
+
54
test_expect_success "remove recursive pin, add direct" '
55
echo Unpinned `cat hashfile` > expected
50
- ipfs pin rm `cat hashfile` > actual
56
+ ipfs pin rm -r `cat hashfile` > actual
57
test_cmp expected actual
58
ipfs pin add `cat hashfile`
59
'
60
61
test_expect_success "remove direct pin" '
62
+ echo Unpinned `cat hashfile` > expected
63
ipfs pin rm `cat hashfile` > actual
64
test_cmp expected actual
65
'