提交 0f6bd2d1 作者: Łukasz Magiera

coreapi: fix resolved path root for some paths

License: MIT
Signed-off-by: 's avatarŁukasz Magiera <magik6k@gmail.com>
上级 e227fc38
......@@ -108,9 +108,9 @@ func resolvePath(ctx context.Context, ng ipld.NodeGetter, nsys namesys.NameSyste
return nil, err
}
var root *cid.Cid
if ipath.IsJustAKey() {
root = node.Cid()
root, err := cid.Parse(ipath.Segments()[1])
if err != nil {
return nil, err
}
return &resolvedPath{
......
......@@ -4,6 +4,8 @@ import (
"context"
"strings"
"testing"
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
)
func TestMutablePath(t *testing.T) {
......@@ -113,3 +115,39 @@ func TestInvalidPathRemainder(t *testing.T) {
t.Fatalf("unexpected error: %s", err)
}
}
func TestPathRoot(t *testing.T) {
ctx := context.Background()
_, api, err := makeAPI(ctx)
if err != nil {
t.Fatal(err)
}
blk, err := api.Block().Put(ctx, strings.NewReader(`foo`), options.Block.Format("raw"))
if err != nil {
t.Error(err)
}
obj, err := api.Dag().Put(ctx, strings.NewReader(`{"foo": {"/": "`+blk.Cid().String()+`"}}`))
if err != nil {
t.Fatal(err)
}
p1, err := api.ParsePath(obj.String() + "/foo")
if err != nil {
t.Error(err)
}
rp, err := api.ResolvePath(ctx, p1)
if err != nil {
t.Fatal(err)
}
if rp.Root().String() != obj.Cid().String() {
t.Error("unexpected path root")
}
if rp.Cid().String() != blk.Cid().String() {
t.Error("unexpected path cid")
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论