Model refactor (#3915)

* Add mockery config file
* Move basic file/folder structs to models
* Fix hack due to import loop
* Move file interfaces to models
* Move folder interfaces to models
* Move scene interfaces to models
* Move scene marker interfaces to models
* Move image interfaces to models
* Move gallery interfaces to models
* Move gallery chapter interfaces to models
* Move studio interfaces to models
* Move movie interfaces to models
* Move performer interfaces to models
* Move tag interfaces to models
* Move autotag interfaces to models
* Regenerate mocks
This commit is contained in:
DingDongSoLong4
2023-09-01 02:39:29 +02:00
committed by GitHub
parent 20520a58b4
commit c364346a59
185 changed files with 3840 additions and 2559 deletions

View File

@@ -6,6 +6,8 @@ import (
"os"
"path/filepath"
"sort"
"github.com/stashapp/stash/pkg/models"
)
// Modified from github.com/facebookgo/symwalk
@@ -48,7 +50,7 @@ import (
//
// Note that symwalk.Walk does not terminate if there are any non-terminating loops in
// the file structure.
func walkSym(f FS, filename string, linkDirname string, walkFn fs.WalkDirFunc) error {
func walkSym(f models.FS, filename string, linkDirname string, walkFn fs.WalkDirFunc) error {
symWalkFunc := func(path string, info fs.DirEntry, err error) error {
if fname, err := filepath.Rel(filename, path); err == nil {
@@ -80,7 +82,7 @@ func walkSym(f FS, filename string, linkDirname string, walkFn fs.WalkDirFunc) e
}
// symWalk extends filepath.Walk to also follow symlinks
func symWalk(fs FS, path string, walkFn fs.WalkDirFunc) error {
func symWalk(fs models.FS, path string, walkFn fs.WalkDirFunc) error {
return walkSym(fs, path, path, walkFn)
}
@@ -93,7 +95,7 @@ func (d *statDirEntry) IsDir() bool { return d.info.IsDir() }
func (d *statDirEntry) Type() fs.FileMode { return d.info.Mode().Type() }
func (d *statDirEntry) Info() (fs.FileInfo, error) { return d.info, nil }
func fsWalk(f FS, root string, fn fs.WalkDirFunc) error {
func fsWalk(f models.FS, root string, fn fs.WalkDirFunc) error {
info, err := f.Lstat(root)
if err != nil {
err = fn(root, nil, err)
@@ -106,7 +108,7 @@ func fsWalk(f FS, root string, fn fs.WalkDirFunc) error {
return err
}
func walkDir(f FS, path string, d fs.DirEntry, walkDirFn fs.WalkDirFunc) error {
func walkDir(f models.FS, path string, d fs.DirEntry, walkDirFn fs.WalkDirFunc) error {
if err := walkDirFn(path, d, nil); err != nil || !d.IsDir() {
if errors.Is(err, fs.SkipDir) && d.IsDir() {
// Successfully skipped directory.
@@ -143,7 +145,7 @@ func walkDir(f FS, path string, d fs.DirEntry, walkDirFn fs.WalkDirFunc) error {
// readDir reads the directory named by dirname and returns
// a sorted list of directory entries.
func readDir(fs FS, dirname string) ([]fs.DirEntry, error) {
func readDir(fs models.FS, dirname string) ([]fs.DirEntry, error) {
f, err := fs.Open(dirname)
if err != nil {
return nil, err