提交 9adcfe7b 作者: Jeromy

address concerns from PR

上级 ccb36277
......@@ -71,9 +71,17 @@ on disk.
return nil, u.ErrCast()
}
var pintype string
rec, _, _ := res.Request().Option("recursive").Bool()
if rec {
pintype = "recursively"
} else {
pintype = "directly"
}
buf := new(bytes.Buffer)
for _, k := range added.Pinned {
fmt.Fprintf(buf, "Pinned %s\n", k)
fmt.Fprintf(buf, "pinned %s %s\n", k, pintype)
}
return buf, nil
},
......@@ -127,7 +135,7 @@ collected if needed.
buf := new(bytes.Buffer)
for _, k := range added.Pinned {
fmt.Fprintf(buf, "Unpinned %s\n", k)
fmt.Fprintf(buf, "unpinned %s\n", k)
}
return buf, nil
},
......
......@@ -14,7 +14,7 @@ func Pin(n *core.IpfsNode, paths []string, recursive bool) ([]u.Key, error) {
for _, path := range paths {
dagnode, err := n.Resolver.ResolvePath(path)
if err != nil {
return nil, fmt.Errorf("pin error: %v", err)
return nil, fmt.Errorf("pin: %s", err)
}
dagnodes = append(dagnodes, dagnode)
}
......@@ -28,7 +28,7 @@ func Pin(n *core.IpfsNode, paths []string, recursive bool) ([]u.Key, error) {
err = n.Pinning.Pin(dagnode, recursive)
if err != nil {
return nil, fmt.Errorf("pin: %v", err)
return nil, fmt.Errorf("pin: %s", err)
}
out = append(out, k)
}
......
......@@ -5,6 +5,7 @@ package pin
import (
"encoding/json"
"errors"
"fmt"
"sync"
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 {
}
} else {
if p.recursePin.HasKey(k) {
return errors.New("Key already pinned recursively.")
return fmt.Errorf("%s already pinned recursively", k.B58String())
}
p.directPin.AddBlock(k)
}
......@@ -124,15 +125,15 @@ func (p *pinner) Unpin(k util.Key, recursive bool) error {
return p.unpinLinks(node)
} else {
return errors.New("Key pinned recursively.")
return fmt.Errorf("%s is pinned recursively", k)
}
} else if p.directPin.HasKey(k) {
p.directPin.RemoveBlock(k)
return nil
} else if p.indirPin.HasKey(k) {
return errors.New("Cannot unpin indirectly pinned block.")
return fmt.Errorf("%s is pinned indirectly. indirect pins cannot be removed directly", k)
} else {
return errors.New("Given key was not pinned.")
return fmt.Errorf("%s is not pinned", k)
}
}
......
......@@ -24,15 +24,15 @@ test_expect_success "added file was pinned" '
# TODO: run gc, then ipfs cat file, should still be there
test_expect_success "'ipfs pin rm' succeeds" '
echo Unpinned `cat hashfile` > expected
ipfs pin rm -r `cat hashfile` > actual
test_cmp expected actual
echo unpinned `cat hashfile` > expected1
ipfs pin rm -r `cat hashfile` > actual1
test_cmp expected1 actual1
'
test_expect_success "file no longer pinned" '
echo -n "" > expected
ipfs pin ls -type=recursive > actual
test_cmp expected actual
echo -n "" > expected2
ipfs pin ls -type=recursive > actual2
test_cmp expected2 actual2
'
test_expect_success "recursively pin afile" '
......@@ -40,28 +40,28 @@ test_expect_success "recursively pin afile" '
'
test_expect_success "pinning directly should fail now" '
echo "Error: pin: Key already pinned recursively." > expected
ipfs pin add `cat hashfile` 2> actual
test_cmp expected actual
echo Error: pin: `cat hashfile` already pinned recursively > expected3
ipfs pin add `cat hashfile` 2> actual3
test_cmp expected3 actual3
'
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
echo Error: `cat hashfile` is pinned recursively > expected4
ipfs pin rm `cat hashfile` 2> actual4
test_cmp expected4 actual4
'
test_expect_success "remove recursive pin, add direct" '
echo Unpinned `cat hashfile` > expected
ipfs pin rm -r `cat hashfile` > actual
test_cmp expected actual
echo unpinned `cat hashfile` > expected5
ipfs pin rm -r `cat hashfile` > actual5
test_cmp expected5 actual5
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
echo unpinned `cat hashfile` > expected6
ipfs pin rm `cat hashfile` > actual6
test_cmp expected6 actual6
'
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论