mirror of
https://github.com/stashapp/stash.git
synced 2025-12-06 08:26:00 +01:00
* Move main to cmd * Move api to internal * Move logger and manager to internal * Move shell hiding code to separate package * Decouple job from desktop and utils * Decouple session from config * Move static into internal * Decouple config from dlna * Move desktop to internal * Move dlna to internal * Decouple remaining packages from config * Move config into internal * Move jsonschema and paths to models * Make ffmpeg functions private * Move file utility methods into fsutil package * Move symwalk into fsutil * Move single-use util functions into client package * Move slice functions to separate packages * Add env var to suppress windowsgui arg * Move hash functions into separate package * Move identify to internal * Move autotag to internal * Touch UI when generating backend
89 lines
1.7 KiB
Go
89 lines
1.7 KiB
Go
package manager
|
|
|
|
import (
|
|
"regexp"
|
|
"strings"
|
|
|
|
"github.com/stashapp/stash/pkg/logger"
|
|
)
|
|
|
|
func excludeFiles(files []string, patterns []string) ([]string, int) {
|
|
if patterns == nil {
|
|
logger.Infof("No exclude patterns in config")
|
|
return files, 0
|
|
} else {
|
|
var results []string
|
|
var exclCount int
|
|
|
|
fileRegexps := generateRegexps(patterns)
|
|
|
|
if len(fileRegexps) == 0 {
|
|
logger.Infof("Excluded 0 files from scan")
|
|
return files, 0
|
|
}
|
|
|
|
for _, f := range files {
|
|
if matchFileSimple(f, fileRegexps) {
|
|
logger.Infof("File matched pattern. Excluding:\"%s\"", f)
|
|
exclCount++
|
|
} else {
|
|
// if pattern doesn't match add file to list
|
|
results = append(results, f)
|
|
}
|
|
}
|
|
logger.Infof("Excluded %d file(s) from scan", exclCount)
|
|
return results, exclCount
|
|
}
|
|
}
|
|
|
|
func matchFileRegex(file string, fileRegexps []*regexp.Regexp) bool {
|
|
for _, regPattern := range fileRegexps {
|
|
if regPattern.MatchString(file) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func matchFile(file string, patterns []string) bool {
|
|
if patterns != nil {
|
|
fileRegexps := generateRegexps(patterns)
|
|
|
|
return matchFileRegex(file, fileRegexps)
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
func generateRegexps(patterns []string) []*regexp.Regexp {
|
|
|
|
var fileRegexps []*regexp.Regexp
|
|
|
|
for _, pattern := range patterns {
|
|
if !strings.HasPrefix(pattern, "(?i)") {
|
|
pattern = "(?i)" + pattern
|
|
}
|
|
reg, err := regexp.Compile(pattern)
|
|
if err != nil {
|
|
logger.Errorf("Exclude :%v", err)
|
|
} else {
|
|
fileRegexps = append(fileRegexps, reg)
|
|
}
|
|
}
|
|
|
|
if len(fileRegexps) == 0 {
|
|
return nil
|
|
} else {
|
|
return fileRegexps
|
|
}
|
|
|
|
}
|
|
|
|
func matchFileSimple(file string, regExps []*regexp.Regexp) bool {
|
|
for _, regPattern := range regExps {
|
|
if regPattern.MatchString(file) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|