提交 9f79dde0 作者: jbenet 提交者: Juan Benet

ipfs object patch add-link supports paths

previously, paths were not supported as link values.
this would not work, and now can:

    ipfs object patch $root add-link foo /ipfs/$hash/foo/bar

License: MIT
Signed-off-by: 's avatarJuan Benet <juan@benet.ai>
上级 0ddafe60
......@@ -5,7 +5,6 @@ import (
"io/ioutil"
"strings"
key "github.com/ipfs/go-ipfs/blocks/key"
cmds "github.com/ipfs/go-ipfs/commands"
core "github.com/ipfs/go-ipfs/core"
dag "github.com/ipfs/go-ipfs/merkledag"
......@@ -273,8 +272,12 @@ a file containing 'bar', and returns the hash of the new object.
return
}
path := req.Arguments()[1]
childk := key.B58KeyDecode(req.Arguments()[2])
npath := req.Arguments()[1]
childp, err := path.ParsePath(req.Arguments()[2])
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
create, _, err := req.Option("create").Bool()
if err != nil {
......@@ -291,13 +294,13 @@ a file containing 'bar', and returns the hash of the new object.
e := dagutils.NewDagEditor(root, nd.DAG)
childnd, err := nd.DAG.Get(req.Context(), childk)
childnd, err := core.Resolve(req.Context(), nd, childp)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
err = e.InsertNodeAtPath(req.Context(), path, childnd, createfunc)
err = e.InsertNodeAtPath(req.Context(), npath, childnd, createfunc)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
......
......@@ -180,6 +180,16 @@ test_object_cmd() {
ipfs object stat $OUTPUT
'
test_expect_success "'ipfs object patch add-link' should work with paths" '
EMPTY_DIR=$(ipfs object new unixfs-dir) &&
N1=$(ipfs object patch $EMPTY_DIR add-link baz $EMPTY_DIR) &&
N2=$(ipfs object patch $EMPTY_DIR add-link bar $N1) &&
N3=$(ipfs object patch $EMPTY_DIR add-link foo /ipfs/$N2/bar) &&
ipfs object stat /ipfs/$N3 &&
ipfs object stat $N3/foo &&
ipfs object stat /ipfs/$N3/foo/baz
'
test_expect_success "multilayer ipfs patch works" '
echo "hello world" > hwfile &&
FILE=$(ipfs add -q hwfile) &&
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论