616c6b1c62
Release Docker multi arch / docker (push) Has been cancelled
Test Install Script / Test Script Syntax (push) Has been cancelled
Test Install Script / Test on almalinux-10 (default) (push) Has been cancelled
Test Install Script / Test on almalinux-10 (root) (push) Has been cancelled
Test Install Script / Test on almalinux-8 (default) (push) Has been cancelled
Test Install Script / Test on almalinux-8 (root) (push) Has been cancelled
Test Install Script / Test on almalinux-9 (default) (push) Has been cancelled
Test Install Script / Test on almalinux-9 (root) (push) Has been cancelled
Test Install Script / Test on amazonlinux-2 (default) (push) Has been cancelled
Test Install Script / Test on amazonlinux-2 (root) (push) Has been cancelled
Test Install Script / Test on debian-11 (default) (push) Has been cancelled
Test Install Script / Test on debian-11 (root) (push) Has been cancelled
Test Install Script / Test on debian-12 (default) (push) Has been cancelled
Test Install Script / Test on debian-12 (root) (push) Has been cancelled
Test Install Script / Test on debian-13 (default) (push) Has been cancelled
Test Install Script / Test on debian-13 (root) (push) Has been cancelled
Test Install Script / Test on fedora-latest (default) (push) Has been cancelled
Test Install Script / Test on fedora-latest (root) (push) Has been cancelled
Test Install Script / Test on rocky-10 (default) (push) Has been cancelled
Test Install Script / Test on rocky-10 (root) (push) Has been cancelled
Test Install Script / Test on rocky-8 (default) (push) Has been cancelled
Test Install Script / Test on rocky-8 (root) (push) Has been cancelled
Test Install Script / Test on rocky-9 (default) (push) Has been cancelled
Test Install Script / Test on rocky-9 (root) (push) Has been cancelled
Test Install Script / Test on ubuntu-22.04 (default) (push) Has been cancelled
Test Install Script / Test on ubuntu-22.04 (root) (push) Has been cancelled
Test Install Script / Test on ubuntu-24.04 (default) (push) Has been cancelled
Test Install Script / Test on ubuntu-24.04 (root) (push) Has been cancelled
86 lines
1.9 KiB
Go
86 lines
1.9 KiB
Go
package torrfs
|
|
|
|
import (
|
|
"io/fs"
|
|
"time"
|
|
|
|
sets "server/settings"
|
|
"server/torr"
|
|
"server/torr/storage/torrstor"
|
|
|
|
"github.com/anacrolix/torrent"
|
|
)
|
|
|
|
type TorrFile struct {
|
|
parent INode
|
|
|
|
info fs.FileInfo
|
|
|
|
torr *torr.Torrent
|
|
file *torrent.File
|
|
reader *torrstor.Reader
|
|
}
|
|
|
|
type TorrFileHandle struct {
|
|
*TorrFile
|
|
r *torrstor.Reader
|
|
}
|
|
|
|
func NewTorrFile(parent INode, name string, file *torrent.File) *TorrFile {
|
|
f := &TorrFile{
|
|
file: file,
|
|
parent: parent,
|
|
torr: parent.Torrent(),
|
|
info: info{
|
|
name: name,
|
|
size: file.Length(),
|
|
mode: 0o444,
|
|
mtime: time.Unix(parent.Torrent().Timestamp, 0),
|
|
isDir: false,
|
|
},
|
|
}
|
|
return f
|
|
}
|
|
|
|
func (f *TorrFile) Open(name string) (fs.File, error) {
|
|
r := f.Torrent().NewReader(f.file)
|
|
if r == nil {
|
|
return nil, fs.ErrInvalid
|
|
}
|
|
if sets.BTsets.ResponsiveMode {
|
|
r.SetResponsive()
|
|
}
|
|
return &TorrFileHandle{TorrFile: f, r: r}, nil
|
|
}
|
|
|
|
// INode
|
|
func (f *TorrFile) Parent() INode { return f.parent }
|
|
func (f *TorrFile) Torrent() *torr.Torrent { return f.torr }
|
|
func (f *TorrFile) SetTorrent(torr *torr.Torrent) { f.torr = torr }
|
|
|
|
// DirEntry
|
|
func (f *TorrFile) Name() string { return f.info.Name() }
|
|
func (f *TorrFile) IsDir() bool { return false }
|
|
func (f *TorrFile) Type() fs.FileMode {
|
|
s, _ := f.Stat()
|
|
return s.Mode()
|
|
}
|
|
func (f *TorrFile) Info() (fs.FileInfo, error) { return f.info, nil }
|
|
func (f *TorrFile) Stat() (fs.FileInfo, error) { return f.info, nil }
|
|
func (f *TorrFile) Read(p []byte) (int, error) { return 0, fs.ErrInvalid }
|
|
func (f *TorrFile) Close() error { return nil }
|
|
func (f *TorrFile) ReadDir(n int) ([]fs.DirEntry, error) { return nil, fs.ErrInvalid }
|
|
|
|
func (h *TorrFileHandle) Read(p []byte) (int, error) {
|
|
return h.r.Read(p)
|
|
}
|
|
|
|
func (h *TorrFileHandle) Seek(off int64, whence int) (int64, error) {
|
|
return h.r.Seek(off, whence)
|
|
}
|
|
|
|
func (h *TorrFileHandle) Close() error {
|
|
h.torr.CloseReader(h.r)
|
|
return nil
|
|
}
|