diff --git a/core/commands/object.go b/core/commands/object.go index 4e284545fe8..e522a1eb29e 100644 --- a/core/commands/object.go +++ b/core/commands/object.go @@ -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 }, }, } diff --git a/test/sharness/t0051-object.sh b/test/sharness/t0051-object.sh index c6433712b5e..9f909a5f742 100755 --- a/test/sharness/t0051-object.sh +++ b/test/sharness/t0051-object.sh @@ -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