Skip to content

Commit

Permalink
data: check errors when iterating over IPFS pins
Browse files Browse the repository at this point in the history
The pin objects sent over a channel also embed an error value within
them. If we see an error, we must handle it and stop.

The upstream issue ipfs/kubo#4592 covers
some of the rough edges of this channel-based API.
  • Loading branch information
mvdan authored and p4u committed Dec 9, 2020
1 parent 6800e63 commit f7312d6
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions data/ipfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,10 @@ func (i *IPFSHandle) countPins(ctx context.Context) (int, error) {
return 0, err
}
count := 0
for range pins {
for pin := range pins {
if err := pin.Err(); err != nil {
return 0, err
}
count++
}
return count, nil
Expand All @@ -220,8 +223,11 @@ func (i *IPFSHandle) ListPins(ctx context.Context) (map[string]string, error) {
return nil, err
}
pinMap := make(map[string]string)
for p := range pins {
pinMap[p.Path().String()] = p.Type()
for pin := range pins {
if err := pin.Err(); err != nil {
return nil, err
}
pinMap[pin.Path().String()] = pin.Type()
}
return pinMap, nil
}
Expand Down

0 comments on commit f7312d6

Please sign in to comment.