"sync"
"time"
+ "golang.org/x/net/context"
+
"bazil.org/fuse"
fusefs "bazil.org/fuse/fs"
"bitbucket.org/anacrolix/go.torrent"
_ fusefs.FSIniter = &TorrentFS{}
)
-func (fs *TorrentFS) Init(req *fuse.InitRequest, resp *fuse.InitResponse, intr fusefs.Intr) fuse.Error {
+func (fs *TorrentFS) Init(ctx context.Context, req *fuse.InitRequest, resp *fuse.InitResponse) error {
log.Print(req)
log.Print(resp)
resp.MaxReadahead = req.MaxReadahead
return "/" + strings.Join(append([]string{n.metadata.Name}, n.path...), "/")
}
-func blockingRead(fs *TorrentFS, t torrent.Torrent, off int64, p []byte, intr fusefs.Intr) (n int, err fuse.Error) {
+func blockingRead(ctx context.Context, fs *TorrentFS, t torrent.Torrent, off int64, p []byte) (n int, err error) {
fs.mu.Lock()
fs.blockedReads++
fs.event.Broadcast()
fs.mu.Unlock()
var (
_n int
- _err fuse.Error
+ _err error
)
readDone := make(chan struct{})
go func() {
err = _err
case <-fs.destroyed:
err = fuse.EIO
- case <-intr:
+ case <-ctx.Done():
err = fuse.EINTR
}
fs.mu.Lock()
return
}
-func readFull(fs *TorrentFS, t torrent.Torrent, off int64, p []byte, intr fusefs.Intr) (n int, err fuse.Error) {
+func readFull(ctx context.Context, fs *TorrentFS, t torrent.Torrent, off int64, p []byte) (n int, err error) {
for len(p) != 0 {
var nn int
- nn, err = blockingRead(fs, t, off, p, intr)
+ nn, err = blockingRead(ctx, fs, t, off, p)
if err != nil {
break
}
return
}
-func (fn fileNode) Read(req *fuse.ReadRequest, resp *fuse.ReadResponse, intr fusefs.Intr) fuse.Error {
+func (fn fileNode) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error {
torrentfsReadRequests.Add(1)
started := time.Now()
if req.Dir {
return nil
}
torrentOff := fn.TorrentOffset + req.Offset
- n, err := readFull(fn.FS, fn.t, torrentOff, resp.Data, intr)
+ n, err := readFull(ctx, fn.FS, fn.t, torrentOff, resp.Data)
if err != nil {
return err
}
}
var (
- _ fusefs.HandleReadDirer = dirNode{}
- _ fusefs.HandleReader = fileNode{}
+ _ fusefs.HandleReadDirAller = dirNode{}
+ _ fusefs.HandleReader = fileNode{}
)
func isSubPath(parent, child []string) bool {
return true
}
-func (dn dirNode) ReadDir(intr fusefs.Intr) (des []fuse.Dirent, err fuse.Error) {
+func (dn dirNode) ReadDirAll(ctx context.Context) (des []fuse.Dirent, err error) {
names := map[string]bool{}
for _, fi := range dn.metadata.Files {
if !isSubPath(dn.path, fi.Path) {
return
}
-func (dn dirNode) Lookup(name string, intr fusefs.Intr) (_node fusefs.Node, err fuse.Error) {
+func (dn dirNode) Lookup(ctx context.Context, name string) (_node fusefs.Node, err error) {
var torrentOffset int64
for _, fi := range dn.metadata.Files {
if !isSubPath(dn.path, fi.Path) {
return
}
-func (me rootNode) Lookup(name string, intr fusefs.Intr) (_node fusefs.Node, err fuse.Error) {
+func (me rootNode) Lookup(ctx context.Context, name string) (_node fusefs.Node, err error) {
for _, t := range me.fs.Client.Torrents() {
if t.Name() != name || t.Info == nil {
continue
return
}
-func (me rootNode) ReadDir(intr fusefs.Intr) (dirents []fuse.Dirent, err fuse.Error) {
+func (me rootNode) ReadDir(ctx context.Context) (dirents []fuse.Dirent, err error) {
for _, t := range me.fs.Client.Torrents() {
if t.Info == nil {
continue
me.fs.Destroy()
}
-func (tfs *TorrentFS) Root() (fusefs.Node, fuse.Error) {
+func (tfs *TorrentFS) Root() (fusefs.Node, error) {
return rootNode{tfs}, nil
}
"testing"
"time"
+ "golang.org/x/net/context"
+
"bitbucket.org/anacrolix/go.torrent"
"bitbucket.org/anacrolix/go.torrent/testutil"
"bitbucket.org/anacrolix/go.torrent/util"
fs := New(leecher)
defer fs.Destroy()
root, _ := fs.Root()
- node, _ := root.(fusefs.NodeStringLookuper).Lookup("greeting", nil)
+ node, _ := root.(fusefs.NodeStringLookuper).Lookup(context.Background(), "greeting")
size := int(node.Attr().Size)
resp := &fuse.ReadResponse{
Data: make([]byte, size),
}
- node.(fusefs.HandleReader).Read(&fuse.ReadRequest{
+ node.(fusefs.HandleReader).Read(context.Background(), &fuse.ReadRequest{
Size: size,
- }, resp, nil)
+ }, resp)
content := resp.Data
if string(content) != testutil.GreetingFileContents {
t.FailNow()