2022-07-13 06:30:54 +00:00
|
|
|
package file
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"io/fs"
|
|
|
|
"os"
|
2022-10-25 00:37:54 +00:00
|
|
|
|
|
|
|
"github.com/stashapp/stash/pkg/fsutil"
|
2023-09-01 00:39:29 +00:00
|
|
|
"github.com/stashapp/stash/pkg/models"
|
2022-07-13 06:30:54 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Opener provides an interface to open a file.
|
|
|
|
type Opener interface {
|
|
|
|
Open() (io.ReadCloser, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
type fsOpener struct {
|
2023-09-01 00:39:29 +00:00
|
|
|
fs models.FS
|
2022-07-13 06:30:54 +00:00
|
|
|
name string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o *fsOpener) Open() (io.ReadCloser, error) {
|
|
|
|
return o.fs.Open(o.name)
|
|
|
|
}
|
|
|
|
|
|
|
|
// OsFS is a file system backed by the OS.
|
|
|
|
type OsFS struct{}
|
|
|
|
|
2023-03-16 23:52:49 +00:00
|
|
|
func (f *OsFS) Create(name string) (*os.File, error) {
|
|
|
|
return os.Create(name)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *OsFS) MkdirAll(path string, perm fs.FileMode) error {
|
|
|
|
return os.MkdirAll(path, perm)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *OsFS) Remove(name string) error {
|
|
|
|
return os.Remove(name)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *OsFS) Rename(oldpath, newpath string) error {
|
|
|
|
return os.Rename(oldpath, newpath)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *OsFS) RemoveAll(path string) error {
|
|
|
|
return os.RemoveAll(path)
|
|
|
|
}
|
|
|
|
|
2022-10-24 23:57:37 +00:00
|
|
|
func (f *OsFS) Stat(name string) (fs.FileInfo, error) {
|
|
|
|
return os.Stat(name)
|
|
|
|
}
|
|
|
|
|
2022-07-13 06:30:54 +00:00
|
|
|
func (f *OsFS) Lstat(name string) (fs.FileInfo, error) {
|
|
|
|
return os.Lstat(name)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *OsFS) Open(name string) (fs.ReadDirFile, error) {
|
|
|
|
return os.Open(name)
|
|
|
|
}
|
|
|
|
|
2024-09-11 03:58:02 +00:00
|
|
|
func (f *OsFS) OpenZip(name string, size int64) (models.ZipFS, error) {
|
|
|
|
return newZipFS(f, name, size)
|
2022-07-13 06:30:54 +00:00
|
|
|
}
|
2022-10-25 00:37:54 +00:00
|
|
|
|
|
|
|
func (f *OsFS) IsPathCaseSensitive(path string) (bool, error) {
|
|
|
|
return fsutil.IsFsPathCaseSensitive(path)
|
|
|
|
}
|