]> Sergey Matveev's repositories - btrtrc.git/blobdiff - fs/file_handle.go
Drop support for go 1.20
[btrtrc.git] / fs / file_handle.go
index 7a7265f3461f67c111b454f9def4c0cbd9e86f61..ce5ded0b488205f54251e8631fbb72b0a6c9f1e2 100644 (file)
@@ -4,15 +4,16 @@ import (
        "context"
        "io"
 
-       "bazil.org/fuse"
-       "bazil.org/fuse/fs"
+       "github.com/anacrolix/fuse"
+       "github.com/anacrolix/fuse/fs"
        "github.com/anacrolix/missinggo/v2"
+
        "github.com/anacrolix/torrent"
 )
 
 type fileHandle struct {
        fn fileNode
-       r  torrent.Reader
+       tf *torrent.File
 }
 
 var _ interface {
@@ -25,7 +26,8 @@ func (me fileHandle) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse
        if req.Dir {
                panic("read on directory")
        }
-       r := me.r
+       r := me.tf.NewReader()
+       defer r.Close()
        pos, err := r.Seek(req.Offset, io.SeekStart)
        if err != nil {
                panic(err)
@@ -45,13 +47,16 @@ func (me fileHandle) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse
                me.fn.FS.mu.Unlock()
                var n int
                r := missinggo.ContextedReader{r, ctx}
-               //log.Printf("reading %v bytes at %v", len(resp.Data), req.Offset)
+               // log.Printf("reading %v bytes at %v", len(resp.Data), req.Offset)
                if true {
                        // A user reported on that on freebsd 12.2, the system requires that reads are
                        // completely filled. Their system only asks for 64KiB at a time. I've seen systems that
                        // can demand up to 16MiB at a time, so this gets tricky. For now, I'll restore the old
                        // behaviour from before 2a7352a, which nobody reported problems with.
                        n, readErr = io.ReadFull(r, resp.Data)
+                       if readErr == io.ErrUnexpectedEOF {
+                               readErr = nil
+                       }
                } else {
                        n, readErr = r.Read(resp.Data)
                        if readErr == io.EOF {
@@ -80,5 +85,5 @@ func (me fileHandle) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse
 }
 
 func (me fileHandle) Release(context.Context, *fuse.ReleaseRequest) error {
-       return me.r.Close()
+       return nil
 }