mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 12:24:38 +03:00
Check if scenes are in the library when cleaning (#169)
This commit is contained in:
@@ -4,8 +4,11 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"github.com/stashapp/stash/pkg/database"
|
"github.com/stashapp/stash/pkg/database"
|
||||||
"github.com/stashapp/stash/pkg/logger"
|
"github.com/stashapp/stash/pkg/logger"
|
||||||
|
"github.com/stashapp/stash/pkg/manager/config"
|
||||||
"github.com/stashapp/stash/pkg/models"
|
"github.com/stashapp/stash/pkg/models"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -16,7 +19,7 @@ type CleanTask struct {
|
|||||||
func (t *CleanTask) Start(wg *sync.WaitGroup) {
|
func (t *CleanTask) Start(wg *sync.WaitGroup) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
|
||||||
if t.fileExists(t.Scene.Path) {
|
if t.fileExists(t.Scene.Path) && t.pathInStash() {
|
||||||
logger.Debugf("File Found: %s", t.Scene.Path)
|
logger.Debugf("File Found: %s", t.Scene.Path)
|
||||||
} else {
|
} else {
|
||||||
logger.Infof("File not found. Cleaning: %s", t.Scene.Path)
|
logger.Infof("File not found. Cleaning: %s", t.Scene.Path)
|
||||||
@@ -53,3 +56,20 @@ func (t *CleanTask) fileExists(filename string) bool {
|
|||||||
}
|
}
|
||||||
return !info.IsDir()
|
return !info.IsDir()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *CleanTask) pathInStash() bool {
|
||||||
|
for _, path := range config.GetStashPaths() {
|
||||||
|
|
||||||
|
rel, error := filepath.Rel(path, filepath.Dir(t.Scene.Path))
|
||||||
|
|
||||||
|
if error == nil {
|
||||||
|
if !strings.HasPrefix(rel, ".."+string(filepath.Separator)) {
|
||||||
|
logger.Debugf("File %s belongs to stash path %s", t.Scene.Path, path)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
logger.Debugf("File %s is out from stash path", t.Scene.Path)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user