@cryptotaxi247 / kubo / commits / 9adcfe7bc

address concerns from PR

Jeromy committed Jan 20, 2015 at 04:52 UTC 9adcfe7bc2b6b73abb1c12a33430130d888d979f
4 files changed +35 -26
core/commands/pin.go
+10 -2
@@ -71,9 +71,17 @@ on disk.
71 return nil, u.ErrCast()
72 }
73
74 + var pintype string
75 + rec, _, _ := res.Request().Option("recursive").Bool()
76 + if rec {
77 + pintype = "recursively"
78 + } else {
79 + pintype = "directly"
80 + }
81 +
82 buf := new(bytes.Buffer)
83 for _, k := range added.Pinned {
76 - fmt.Fprintf(buf, "Pinned %s\n", k)
84 + fmt.Fprintf(buf, "pinned %s %s\n", k, pintype)
85 }
86 return buf, nil
87 },
@@ -127,7 +135,7 @@ collected if needed.
135
136 buf := new(bytes.Buffer)
137 for _, k := range added.Pinned {
130 - fmt.Fprintf(buf, "Unpinned %s\n", k)
138 + fmt.Fprintf(buf, "unpinned %s\n", k)
139 }
140 return buf, nil
141 },
core/repo/pinning.go
+2 -2
@@ -14,7 +14,7 @@ func Pin(n *core.IpfsNode, paths []string, recursive bool) ([]u.Key, error) {
14 for _, path := range paths {
15 dagnode, err := n.Resolver.ResolvePath(path)
16 if err != nil {
17 - return nil, fmt.Errorf("pin error: %v", err)
17 + return nil, fmt.Errorf("pin: %s", err)
18 }
19 dagnodes = append(dagnodes, dagnode)
20 }
@@ -28,7 +28,7 @@ func Pin(n *core.IpfsNode, paths []string, recursive bool) ([]u.Key, error) {
28
29 err = n.Pinning.Pin(dagnode, recursive)
30 if err != nil {
31 - return nil, fmt.Errorf("pin: %v", err)
31 + return nil, fmt.Errorf("pin: %s", err)
32 }
33 out = append(out, k)
34 }
pin/pin.go
+5 -4
@@ -5,6 +5,7 @@ package pin
5 import (
6 "encoding/json"
7 "errors"
8 + "fmt"
9 "sync"
10
11 ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
@@ -103,7 +104,7 @@ func (p *pinner) Pin(node *mdag.Node, recurse bool) error {
104 }
105 } else {
106 if p.recursePin.HasKey(k) {
106 - return errors.New("Key already pinned recursively.")
107 + return fmt.Errorf("%s already pinned recursively", k.B58String())
108 }
109 p.directPin.AddBlock(k)
110 }
@@ -124,15 +125,15 @@ func (p *pinner) Unpin(k util.Key, recursive bool) error {
125
126 return p.unpinLinks(node)
127 } else {
127 - return errors.New("Key pinned recursively.")
128 + return fmt.Errorf("%s is pinned recursively", k)
129 }
130 } else if p.directPin.HasKey(k) {
131 p.directPin.RemoveBlock(k)
132 return nil
133 } else if p.indirPin.HasKey(k) {
133 - return errors.New("Cannot unpin indirectly pinned block.")
134 + return fmt.Errorf("%s is pinned indirectly. indirect pins cannot be removed directly", k)
135 } else {
135 - return errors.New("Given key was not pinned.")
136 + return fmt.Errorf("%s is not pinned", k)
137 }
138 }
139
test/sharness/t0080-repo.sh
+18 -18
@@ -24,15 +24,15 @@ test_expect_success "added file was pinned" '
24 # TODO: run gc, then ipfs cat file, should still be there
25
26 test_expect_success "'ipfs pin rm' succeeds" '
27 - echo Unpinned `cat hashfile` > expected
28 - ipfs pin rm -r `cat hashfile` > actual
29 - test_cmp expected actual
27 + echo unpinned `cat hashfile` > expected1
28 + ipfs pin rm -r `cat hashfile` > actual1
29 + test_cmp expected1 actual1
30 '
31
32 test_expect_success "file no longer pinned" '
33 - echo -n "" > expected
34 - ipfs pin ls -type=recursive > actual
35 - test_cmp expected actual
33 + echo -n "" > expected2
34 + ipfs pin ls -type=recursive > actual2
35 + test_cmp expected2 actual2
36 '
37
38 test_expect_success "recursively pin afile" '
@@ -40,28 +40,28 @@ test_expect_success "recursively pin afile" '
40 '
41
42 test_expect_success "pinning directly should fail now" '
43 - echo "Error: pin: Key already pinned recursively." > expected
44 - ipfs pin add `cat hashfile` 2> actual
45 - test_cmp expected actual
43 + echo Error: pin: `cat hashfile` already pinned recursively > expected3
44 + ipfs pin add `cat hashfile` 2> actual3
45 + test_cmp expected3 actual3
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
49 + echo Error: `cat hashfile` is pinned recursively > expected4
50 + ipfs pin rm `cat hashfile` 2> actual4
51 + test_cmp expected4 actual4
52 '
53
54 test_expect_success "remove recursive pin, add direct" '
55 - echo Unpinned `cat hashfile` > expected
56 - ipfs pin rm -r `cat hashfile` > actual
57 - test_cmp expected actual
55 + echo unpinned `cat hashfile` > expected5
56 + ipfs pin rm -r `cat hashfile` > actual5
57 + test_cmp expected5 actual5
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
62 + echo unpinned `cat hashfile` > expected6
63 + ipfs pin rm `cat hashfile` > actual6
64 + test_cmp expected6 actual6
65 '
66
67