1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-29 01:12:24 +08:00

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.
This commit is contained in:
Juan Batiz-Benet
2015-03-02 06:12:54 -08:00
parent f77dbe0a57
commit 38425b1a06
2 changed files with 20 additions and 4 deletions

View File

@ -354,7 +354,9 @@ func (s *Node) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadR
if err != nil {
return err
}
n, err := io.ReadFull(r, resp.Data[:req.Size])
buf := resp.Data[:min(req.Size, int(r.Size()))]
n, err := io.ReadFull(r, buf)
resp.Data = resp.Data[:n]
lm["res_size"] = n
return err // may be non-nil / not succeeded
@ -652,3 +654,10 @@ type ipnsNode interface {
}
var _ ipnsNode = (*Node)(nil)
func min(a, b int) int {
if a < b {
return a
}
return b
}

View File

@ -5,7 +5,6 @@
package readonly
import (
"bytes"
"io"
"os"
@ -169,8 +168,9 @@ func (s *Node) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadR
if err != nil {
return err
}
buf := bytes.NewBuffer(resp.Data)
n, err := io.CopyN(buf, r, int64(req.Size))
buf := resp.Data[:min(req.Size, int(r.Size()))]
n, err := io.ReadFull(r, buf)
if err != nil && err != io.EOF {
return err
}
@ -196,3 +196,10 @@ type roNode interface {
}
var _ roNode = (*Node)(nil)
func min(a, b int) int {
if a < b {
return a
}
return b
}