diff --git a/core/commands/pin.go b/core/commands/pin.go index ab38987b94e..c762e5c7759 100644 --- a/core/commands/pin.go +++ b/core/commands/pin.go @@ -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"` } @@ -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 } @@ -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()} @@ -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: @@ -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) { @@ -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 +} diff --git a/test/sharness/t0600-issues-and-regressions-online.sh b/test/sharness/t0600-issues-and-regressions-online.sh index f5e5b894075..13964ce34fb 100755 --- a/test/sharness/t0600-issues-and-regressions-online.sh +++ b/test/sharness/t0600-issues-and-regressions-online.sh @@ -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" '