提交 feba3e1d 作者: Juan Batiz-Benet

Merge pull request #1334 from ipfs/patch/patch

'key' objects dont marshal to json well
......@@ -436,7 +436,7 @@ resulting object hash.
cmds.StringArg("command", true, false, "the operation to perform"),
cmds.StringArg("args", true, true, "extra arguments").EnableStdin(),
},
Type: key.Key(""),
Type: Object{},
Run: func(req cmds.Request, res cmds.Response) {
nd, err := req.Context().GetNode()
if err != nil {
......@@ -468,28 +468,28 @@ resulting object hash.
res.SetError(err, cmds.ErrNormal)
return
}
res.SetOutput(k)
res.SetOutput(&Object{Hash: k.B58String()})
case "rm-link":
k, err := rmLinkCaller(req, rnode)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
res.SetOutput(k)
res.SetOutput(&Object{Hash: k.B58String()})
case "set-data":
k, err := setDataCaller(req, rnode)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
res.SetOutput(k)
res.SetOutput(&Object{Hash: k.B58String()})
case "append-data":
k, err := appendDataCaller(req, rnode)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
res.SetOutput(k)
res.SetOutput(&Object{Hash: k.B58String()})
default:
res.SetError(fmt.Errorf("unrecognized subcommand"), cmds.ErrNormal)
return
......@@ -497,12 +497,12 @@ resulting object hash.
},
Marshalers: cmds.MarshalerMap{
cmds.Text: func(res cmds.Response) (io.Reader, error) {
k, ok := res.Output().(key.Key)
o, ok := res.Output().(*Object)
if !ok {
return nil, u.ErrCast()
}
return strings.NewReader(k.B58String() + "\n"), nil
return strings.NewReader(o.Hash + "\n"), nil
},
},
}
......
......@@ -94,6 +94,29 @@ test_object_cmd() {
test_cmp expected_putBroken actual_putBroken &&
test_cmp expected_putBrokenErr actual_putBrokenErr
'
test_expect_success "'ipfs object patch' should work" '
EMPTY_DIR=$(ipfs object new unixfs-dir) &&
OUTPUT=$(ipfs object patch $EMPTY_DIR add-link foo $EMPTY_DIR)
'
test_expect_success "should have created dir within a dir" '
ipfs ls $OUTPUT > patched_output
'
test_expect_success "output looks good" '
echo "QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn 4 foo/ " > patched_exp &&
test_cmp patched_exp patched_output
'
test_expect_success "can remove the directory" '
ipfs object patch $OUTPUT rm-link foo > rmlink_output
'
test_expect_success "output should be empty" '
echo QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn > rmlink_exp &&
test_cmp rmlink_exp rmlink_output
'
}
# should work offline
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论