PackageManager just because
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.1 KiB

package Filesystem
import (
"regexp"
"strings"
"PackageManager/Variables"
)
var (
PruneRegex []*regexp.Regexp
IgnoreRegex []*regexp.Regexp
)
func init() {
var err error
err = InitPruneRegex()
if err != nil {
panic(err)
}
err = InitIgnoreRegex()
if err != nil {
panic(err)
}
}
func InitPruneRegex() error {
var (
r *regexp.Regexp
s string
err error
)
for _, s = range Variables.PruneRegexPaths {
r, err = regexp.Compile(strings.Replace(s, "^/", "^"+Variables.RootDir, 1))
if err != nil {
return err
}
PruneRegex = append(PruneRegex, r)
}
return nil
}
func InitIgnoreRegex() error {
var (
r *regexp.Regexp
s string
err error
)
for _, s = range Variables.IgnoreRegexPaths {
r, err = regexp.Compile(strings.Replace(s, "^/", "^"+Variables.RootDir, 1))
if err != nil {
return err
}
IgnoreRegex = append(IgnoreRegex, r)
}
return nil
}
func matchAny(p string, a []*regexp.Regexp) bool {
var (
regex *regexp.Regexp
)
for _, regex = range a {
if regex.MatchString(p) {
return true
}
}
return false
}