fix pin add api break
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
Jeromy committed
Mar 7, 2017 at 01:10 UTC
6a7750d5c20c393e5a3cb4c3420dd6a35b049a20
2 files changed
+27
-6
core/commands/pin.go
+14
-6
@@ -31,11 +31,11 @@ var PinCmd = &cmds.Command{
31
}
32
33
type PinOutput struct {
34
- Pins []*cid.Cid
34
+ Pins []string
35
}
36
37
type AddPinOutput struct {
38
- Pins []*cid.Cid
38
+ Pins []string
39
Progress int `json:",omitempty"`
40
}
41
@@ -76,7 +76,7 @@ var addPinCmd = &cmds.Command{
76
res.SetError(err, cmds.ErrNormal)
77
return
78
}
79
- res.SetOutput(&AddPinOutput{Pins: added})
79
+ res.SetOutput(&AddPinOutput{Pins: cidsToStrings(added)})
80
return
81
}
82
@@ -109,7 +109,7 @@ var addPinCmd = &cmds.Command{
109
if pv := v.Value(); pv != 0 {
110
out <- &AddPinOutput{Progress: v.Value()}
111
}
112
- out <- &AddPinOutput{Pins: val}
112
+ out <- &AddPinOutput{Pins: cidsToStrings(val)}
113
return
114
case <-ticker.C:
115
out <- &AddPinOutput{Progress: v.Value()}
@@ -122,7 +122,7 @@ var addPinCmd = &cmds.Command{
122
},
123
Marshalers: cmds.MarshalerMap{
124
cmds.Text: func(res cmds.Response) (io.Reader, error) {
125
- var added []*cid.Cid
125
+ var added []string
126
127
switch out := res.Output().(type) {
128
case *AddPinOutput:
@@ -203,7 +203,7 @@ collected if needed. (By default, recursively. Use -r=false for direct pins.)
203
return
204
}
205
206
- res.SetOutput(&PinOutput{removed})
206
+ res.SetOutput(&PinOutput{cidsToStrings(removed)})
207
},
208
Marshalers: cmds.MarshalerMap{
209
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
413
414
return keys, nil
415
}
416
+
417
+func cidsToStrings(cs []*cid.Cid) []string {
418
+ out := make([]string, 0, len(cs))
419
+ for _, c := range cs {
420
+ out = append(out, c.String())
421
+ }
422
+ return out
423
+}
test/sharness/t0600-issues-and-regressions-online.sh
+13
@@ -33,6 +33,19 @@ test_expect_success "metrics work" '
33
test_fsh cat pro_data
34
'
35
36
+test_expect_success "pin add api looks right" '
37
+ HASH=$(echo "foo" | ipfs add -q) &&
38
+ curl "http://$API_ADDR/api/v0/pin/add/$HASH" > pinadd_out &&
39
+ echo "{\"Pins\":[\"QmYNmQKp6SuaVrpgWRsPTgCQCnpxUYGq76YEKBXuj2N4H6\"]}" > pinadd_exp &&
40
+ test_cmp pinadd_out pinadd_exp
41
+'
42
+
43
+test_expect_success "pin add api looks right" '
44
+ curl "http://$API_ADDR/api/v0/pin/rm/$HASH" > pinrm_out &&
45
+ echo "{\"Pins\":[\"QmYNmQKp6SuaVrpgWRsPTgCQCnpxUYGq76YEKBXuj2N4H6\"]}" > pinrm_exp &&
46
+ test_cmp pinrm_out pinrm_exp
47
+'
48
+
49
test_kill_ipfs_daemon
50
51
test_expect_success "ipfs daemon --offline --mount fails - #2995" '