mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 20:34:37 +03:00
Check if scenes are in the library when cleaning (#169)
This commit is contained in:
@@ -4,8 +4,11 @@ import (
|
||||
"context"
|
||||
"github.com/stashapp/stash/pkg/database"
|
||||
"github.com/stashapp/stash/pkg/logger"
|
||||
"github.com/stashapp/stash/pkg/manager/config"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
@@ -16,7 +19,7 @@ type CleanTask struct {
|
||||
func (t *CleanTask) Start(wg *sync.WaitGroup) {
|
||||
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)
|
||||
} else {
|
||||
logger.Infof("File not found. Cleaning: %s", t.Scene.Path)
|
||||
@@ -42,7 +45,7 @@ func (t *CleanTask) deleteScene(sceneID int) {
|
||||
logger.Infof("Error deleting scene from database: %s", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
DeleteGeneratedSceneFiles(scene)
|
||||
}
|
||||
|
||||
@@ -53,3 +56,20 @@ func (t *CleanTask) fileExists(filename string) bool {
|
||||
}
|
||||
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