Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix pin add api break #3760

Merged
merged 2 commits into from
Mar 8, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions core/commands/pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ var PinCmd = &cmds.Command{
}

type PinOutput struct {
Pins []*cid.Cid
Pins []string
}

type AddPinOutput struct {
Pins []*cid.Cid
Pins []string
Progress int `json:",omitempty"`
}

Expand Down Expand Up @@ -76,7 +76,7 @@ var addPinCmd = &cmds.Command{
res.SetError(err, cmds.ErrNormal)
return
}
res.SetOutput(&AddPinOutput{Pins: added})
res.SetOutput(&AddPinOutput{Pins: cidsToStrings(added)})
return
}

Expand Down Expand Up @@ -109,7 +109,7 @@ var addPinCmd = &cmds.Command{
if pv := v.Value(); pv != 0 {
out <- &AddPinOutput{Progress: v.Value()}
}
out <- &AddPinOutput{Pins: val}
out <- &AddPinOutput{Pins: cidsToStrings(val)}
return
case <-ticker.C:
out <- &AddPinOutput{Progress: v.Value()}
Expand All @@ -122,7 +122,7 @@ var addPinCmd = &cmds.Command{
},
Marshalers: cmds.MarshalerMap{
cmds.Text: func(res cmds.Response) (io.Reader, error) {
var added []*cid.Cid
var added []string

switch out := res.Output().(type) {
case *AddPinOutput:
Expand Down Expand Up @@ -203,7 +203,7 @@ collected if needed. (By default, recursively. Use -r=false for direct pins.)
return
}

res.SetOutput(&PinOutput{removed})
res.SetOutput(&PinOutput{cidsToStrings(removed)})
},
Marshalers: cmds.MarshalerMap{
cmds.Text: func(res cmds.Response) (io.Reader, error) {
Expand Down Expand Up @@ -413,3 +413,11 @@ func pinLsAll(typeStr string, ctx context.Context, n *core.IpfsNode) (map[string

return keys, nil
}

func cidsToStrings(cs []*cid.Cid) []string {
out := make([]string, 0, len(cs))
for _, c := range cs {
out = append(out, c.String())
}
return out
}
13 changes: 13 additions & 0 deletions test/sharness/t0600-issues-and-regressions-online.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ test_expect_success "metrics work" '
test_fsh cat pro_data
'

test_expect_success "pin add api looks right" '
HASH=$(echo "foo" | ipfs add -q) &&
curl "http://$API_ADDR/api/v0/pin/add/$HASH" > pinadd_out &&
echo "{\"Pins\":[\"QmYNmQKp6SuaVrpgWRsPTgCQCnpxUYGq76YEKBXuj2N4H6\"]}" > pinadd_exp &&
test_cmp pinadd_out pinadd_exp
'

test_expect_success "pin add api looks right" '
curl "http://$API_ADDR/api/v0/pin/rm/$HASH" > pinrm_out &&
echo "{\"Pins\":[\"QmYNmQKp6SuaVrpgWRsPTgCQCnpxUYGq76YEKBXuj2N4H6\"]}" > pinrm_exp &&
test_cmp pinrm_out pinrm_exp
'

test_kill_ipfs_daemon

test_expect_success "ipfs daemon --offline --mount fails - #2995" '
Expand Down