tstor/torrent/node/torrent.go
Antonio Navarro Perez 92a219e9c8 Improve permissions, close files and lazy metadata loading.
Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com>
2020-06-07 12:52:00 +02:00

44 lines
909 B
Go

package node
import (
"context"
"io"
"syscall"
"github.com/ajnavarro/distribyted/iio"
"github.com/anacrolix/torrent"
"github.com/hanwen/go-fuse/v2/fs"
"github.com/hanwen/go-fuse/v2/fuse"
)
var _ fs.NodeGetattrer = &Torrent{}
var _ fs.NodeOpendirer = &Torrent{}
type Torrent struct {
fs.Inode
t *torrent.Torrent
}
func (folder *Torrent) Opendir(ctx context.Context) syscall.Errno {
<-folder.t.GotInfo()
for _, file := range folder.t.Files() {
file := file
LoadNodeByPath(
ctx,
file.Path(),
func() (io.ReaderAt, error) { return iio.NewReadAtWrapper(file.NewReader()), nil },
&folder.Inode,
file.Length(),
int32(file.Torrent().Info().PieceLength),
int64(file.Torrent().Info().NumPieces()),
)
}
return fs.OK
}
func (folder *Torrent) Getattr(ctx context.Context, f fs.FileHandle, out *fuse.AttrOut) syscall.Errno {
out.Mode = syscall.S_IFDIR & 0555
return fs.OK
}