Skip to content

Commit

Permalink
Merge pull request #1334 from ipfs/patch/patch
Browse files Browse the repository at this point in the history
'key' objects dont marshal to json well
  • Loading branch information
jbenet committed Jun 8, 2015
2 parents 217fe26 + c214210 commit feba3e1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
14 changes: 7 additions & 7 deletions core/commands/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -468,41 +468,41 @@ 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
}
},
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
},
},
}
Expand Down
23 changes: 23 additions & 0 deletions test/sharness/t0051-object.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit feba3e1

Please sign in to comment.