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:
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user