@cryptotaxi247 / kubo / commits / 38425b1a0

fuse: fix read problem in osx

@whyrusleeping's fix in c88340b broke reading fuse in osx. i'm not sure why... anyway, i chose to revert back to io.ReadFull, but use the min of req.Size and r.Size(), which should not encounter the reading problem in linux that a77ea2f fixed in the first place. This commit also changes ipns, which had not been changed.

Juan Batiz-Benet committed Mar 2, 2015 at 06:12 UTC 38425b1a06514265f0944fb129b4a47fb59789fd
2 files changed +20 -4
fuse/ipns/ipns_unix.go
+10 -1
@@ -354,7 +354,9 @@ func (s *Node) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadR
354 if err != nil {
355 return err
356 }
357 - n, err := io.ReadFull(r, resp.Data[:req.Size])
357 +
358 + buf := resp.Data[:min(req.Size, int(r.Size()))]
359 + n, err := io.ReadFull(r, buf)
360 resp.Data = resp.Data[:n]
361 lm["res_size"] = n
362 return err // may be non-nil / not succeeded
@@ -652,3 +654,10 @@ type ipnsNode interface {
654 }
655
656 var _ ipnsNode = (*Node)(nil)
657 +
658 +func min(a, b int) int {
659 + if a < b {
660 + return a
661 + }
662 + return b
663 +}
fuse/readonly/readonly_unix.go
+10 -3
@@ -5,7 +5,6 @@
5 package readonly
6
7 import (
8 - "bytes"
8 "io"
9 "os"
10
@@ -169,8 +168,9 @@ func (s *Node) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadR
168 if err != nil {
169 return err
170 }
172 - buf := bytes.NewBuffer(resp.Data)
173 - n, err := io.CopyN(buf, r, int64(req.Size))
171 +
172 + buf := resp.Data[:min(req.Size, int(r.Size()))]
173 + n, err := io.ReadFull(r, buf)
174 if err != nil && err != io.EOF {
175 return err
176 }
@@ -196,3 +196,10 @@ type roNode interface {
196 }
197
198 var _ roNode = (*Node)(nil)
199 +
200 +func min(a, b int) int {
201 + if a < b {
202 + return a
203 + }
204 + return b
205 +}