correct modtime

This commit is contained in:
royalcat 2024-12-17 12:51:10 +03:00
parent 92bb67959b
commit 0ae11aa283
15 changed files with 107 additions and 85 deletions
daemons/qbittorrent

View file

@ -15,7 +15,6 @@ import (
"git.kmsign.ru/royalcat/tstor/pkg/qbittorrent"
"git.kmsign.ru/royalcat/tstor/pkg/rlog"
"git.kmsign.ru/royalcat/tstor/pkg/uring"
"git.kmsign.ru/royalcat/tstor/src/vfs"
"github.com/iceber/iouring-go"
)
@ -26,6 +25,7 @@ type FS struct {
name string
hash string
dataDir string // directory where torrent files are stored
modTime time.Time
ur *iouring.IOURing
@ -43,7 +43,7 @@ type fileEntry struct {
var _ vfs.Filesystem = (*FS)(nil)
func newTorrentFS(ctx context.Context, ur *iouring.IOURing, client *cacheClient, name string, hash string, dataDir string) (*FS, error) {
func newTorrentFS(ctx context.Context, client *cacheClient, name string, hash string, modTime time.Time, dataDir string) (*FS, error) {
ctx, span := trace.Start(ctx, "newTorrentFS")
defer span.End()
@ -60,21 +60,20 @@ func newTorrentFS(ctx context.Context, ur *iouring.IOURing, client *cacheClient,
entries[vfs.AbsPath(cnt.Name)] = fileEntry{
Content: cnt,
FileInfo: vfs.NewFileInfo(cnt.Name, cnt.Size),
FileInfo: vfs.NewFileInfo(cnt.Name, cnt.Size, modTime),
}
}
return &FS{
client: client,
name: name,
hash: hash,
client: client,
name: name,
hash: hash,
modTime: modTime,
dataDir: dataDir,
entries: entries,
ur: ur,
log: rlog.Component("qbittorrent", "fs"),
FilesystemPrototype: vfs.FilesystemPrototype(name),
@ -115,7 +114,7 @@ func (f *FS) Stat(ctx context.Context, name string) (fs.FileInfo, error) {
name = vfs.AbsPath(path.Clean(name))
if vfs.IsRoot(name) {
return vfs.NewDirInfo(f.name), nil
return vfs.NewDirInfo(f.name, f.modTime), nil
}
if entry, ok := f.entries[name]; ok {
@ -124,7 +123,7 @@ func (f *FS) Stat(ctx context.Context, name string) (fs.FileInfo, error) {
for p := range f.entries {
if strings.HasPrefix(p, name) {
return vfs.NewDirInfo(name), nil
return vfs.NewDirInfo(name, f.modTime), nil
}
}
@ -219,23 +218,24 @@ func openFile(ctx context.Context, ur *iouring.IOURing, client *cacheClient, tor
pieceSize: props.PieceSize,
fileSize: content.Size,
file: uring.NewFile(ur, file),
file: file,
offset: 0,
}, nil
}
type File struct {
client *cacheClient
hash string
torrentDir string
filePath string // path inside a torrent directory
contentIndex int
pieceSize int
fileSize int64
client *cacheClient
hash string
torrentModTime time.Time
torrentDir string
filePath string // path inside a torrent directory
contentIndex int
pieceSize int
fileSize int64
mu sync.Mutex
file *uring.File
file *os.File
offset int64
}
@ -243,7 +243,7 @@ var _ vfs.File = (*File)(nil)
// Info implements vfs.File.
func (f *File) Info() (fs.FileInfo, error) {
return &fileInfo{name: path.Base(f.filePath), size: f.fileSize}, nil
return vfs.NewFileInfo(path.Base(f.filePath), f.fileSize, f.torrentModTime), nil
}
// IsDir implements vfs.File.
@ -345,7 +345,7 @@ func (f *File) Read(ctx context.Context, p []byte) (int, error) {
return 0, err
}
n, err := f.file.ReadAt(ctx, p, f.offset)
n, err := f.file.ReadAt(p, f.offset)
f.offset += int64(n)
return n, err
}
@ -356,7 +356,7 @@ func (f *File) ReadAt(ctx context.Context, p []byte, off int64) (int, error) {
return 0, err
}
return f.file.ReadAt(ctx, p, off)
return f.file.ReadAt(p, off)
}
// Size implements vfs.File.
@ -371,42 +371,43 @@ func (f *File) Type() fs.FileMode {
// Close implements vfs.File.
func (f *File) Close(ctx context.Context) error {
return f.file.Close(ctx)
return f.file.Close()
}
type fileInfo struct {
name string
size int64
}
// type fileInfo struct {
// name string
// size int64
// modTime time.Time
// }
var _ fs.FileInfo = (*fileInfo)(nil)
// var _ fs.FileInfo = (*fileInfo)(nil)
// IsDir implements fs.FileInfo.
func (f *fileInfo) IsDir() bool {
return false
}
// // IsDir implements fs.FileInfo.
// func (f *fileInfo) IsDir() bool {
// return false
// }
// ModTime implements fs.FileInfo.
func (f *fileInfo) ModTime() time.Time {
return time.Time{}
}
// // ModTime implements fs.FileInfo.
// func (f *fileInfo) ModTime() time.Time {
// return f.modTime
// }
// Mode implements fs.FileInfo.
func (f *fileInfo) Mode() fs.FileMode {
return vfs.ModeFileRO
}
// // Mode implements fs.FileInfo.
// func (f *fileInfo) Mode() fs.FileMode {
// return vfs.ModeFileRO
// }
// Name implements fs.FileInfo.
func (f *fileInfo) Name() string {
return f.name
}
// // Name implements fs.FileInfo.
// func (f *fileInfo) Name() string {
// return f.name
// }
// Size implements fs.FileInfo.
func (f *fileInfo) Size() int64 {
return f.size
}
// // Size implements fs.FileInfo.
// func (f *fileInfo) Size() int64 {
// return f.size
// }
// Sys implements fs.FileInfo.
func (f *fileInfo) Sys() any {
return nil
}
// // Sys implements fs.FileInfo.
// func (f *fileInfo) Sys() any {
// return nil
// }