2024-06-02 19:53:33 +00:00
|
|
|
package ytdlp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"io/fs"
|
2024-06-25 21:39:30 +00:00
|
|
|
"os"
|
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 {
|
|
|
|
entries = append(entries, vfs.NewFileInfo(info.Name(), info.Size()))
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|