tstor/daemons/ytdlp/fs.go

77 lines
1.6 KiB
Go
Raw Normal View History

2024-06-02 19:53:33 +00:00
package ytdlp
import (
"context"
"io/fs"
2024-06-25 21:39:30 +00:00
"os"
2024-12-17 09:51:10 +00:00
"time"
2024-06-02 19:53:33 +00:00
"git.kmsign.ru/royalcat/tstor/pkg/ctxbilly"
"git.kmsign.ru/royalcat/tstor/src/vfs"
)
type SourceFS struct {
2024-06-14 22:14:44 +00:00
service *Daemon
source Source
2024-06-02 19:53:33 +00:00
fs ctxbilly.Filesystem
vfs.DefaultFS
}
var _ vfs.Filesystem = (*SourceFS)(nil)
2024-06-14 22:14:44 +00:00
func newSourceFS(name string, fs ctxbilly.Filesystem, service *Daemon, source Source) *SourceFS {
2024-06-02 19:53:33 +00:00
return &SourceFS{
fs: fs,
service: service,
source: source,
DefaultFS: vfs.DefaultFS(name),
}
}
// Open implements vfs.Filesystem.
func (s *SourceFS) Open(ctx context.Context, filename string) (vfs.File, error) {
info, err := s.fs.Stat(ctx, filename)
if err != nil {
return nil, err
}
2024-06-25 21:39:30 +00:00
f, err := s.fs.OpenFile(ctx, filename, os.O_RDONLY, 0)
2024-06-02 19:53:33 +00:00
if err != nil {
return nil, err
}
return vfs.NewCtxBillyFile(info, f), nil
}
// ReadDir implements vfs.Filesystem.
func (s *SourceFS) ReadDir(ctx context.Context, path string) ([]fs.DirEntry, error) {
infos, err := s.fs.ReadDir(ctx, path)
if err != nil {
return nil, err
}
entries := make([]fs.DirEntry, 0, len(infos))
for _, info := range infos {
2024-12-17 09:51:10 +00:00
entries = append(entries, vfs.NewFileInfo(info.Name(), info.Size(), time.Time{}))
2024-06-02 19:53:33 +00:00
}
return entries, nil
}
// Stat implements vfs.Filesystem.
func (s *SourceFS) Stat(ctx context.Context, filename string) (fs.FileInfo, error) {
return s.fs.Stat(ctx, filename)
}
// Unlink implements vfs.Filesystem.
func (s *SourceFS) Unlink(ctx context.Context, filename string) error {
return vfs.ErrNotImplemented
}
2024-10-14 00:58:42 +00:00
// Rename implements vfs.Filesystem.
func (s *SourceFS) Rename(ctx context.Context, oldpath string, newpath string) error {
return vfs.ErrNotImplemented
}