Skip to content

Commit

Permalink
Merge pull request #3760 from ipfs/fix/pin-add-api
Browse files Browse the repository at this point in the history
fix pin add api break
  • Loading branch information
whyrusleeping committed Mar 8, 2017
2 parents eca0d1c + bd5b48d commit 74afd87
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
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 - #3753" '
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 - #3753" '
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

0 comments on commit 74afd87

Please sign in to comment.