pin: verify: parse bad node cids early
This commit was moved from ipfs/go-ipfs-http-client@7032dfc9b016f2c584e2102e80fb60c3ecf573ea
Łukasz Magiera committed
Feb 18, 2019 at 16:39 UTC
f005b8dc5666916ff2a0ff1eef58b7795670ec73
1 file changed
+10
-8
client/httpapi/pin.go
+10
-8
@@ -110,23 +110,18 @@ func (r *pinVerifyRes) BadNodes() []iface.BadPinNode {
110
type badNode struct {
111
Cid string
112
JErr string `json:"Err"`
113
+
114
+ cid cid.Cid
115
}
116
117
func (n *badNode) Path() iface.ResolvedPath {
116
- c, err := cid.Parse(n.Cid)
117
- if err != nil {
118
- return nil // todo: handle this better
119
- }
120
- return iface.IpldPath(c)
118
+ return iface.IpldPath(n.cid)
119
}
120
121
func (n *badNode) Err() error {
122
if n.JErr != "" {
123
return errors.New(n.JErr)
124
}
127
- if _, err := cid.Parse(n.Cid); err != nil {
128
- return err
129
- }
125
return nil
126
}
127
@@ -150,6 +145,13 @@ func (api *PinAPI) Verify(ctx context.Context) (<-chan iface.PinStatus, error) {
145
return // todo: handle non io.EOF somehow
146
}
147
148
+ for i, n := range out.JBadNodes {
149
+ out.JBadNodes[i].cid, err = cid.Decode(n.Cid)
150
+ if err != nil {
151
+ return
152
+ }
153
+ }
154
+
155
select {
156
case res <- &out:
157
case <-ctx.Done():