You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gophi/regex.go

41 lines
1.0 KiB
Go

package main
import (
"regexp"
"strings"
)
var RestrictedFilesRegex []*regexp.Regexp
func compileUserRestrictedFilesRegex() {
if *RestrictedFiles == "" {
/* User not supplied any restricted files, return here */
listDir = _listDir
return
}
/* Try compiling the RestrictedFilesRegex from finalRegex */
logSystem("Compiling restricted file regular expressions\n")
/* Split the user supplied RestrictedFiles string by new-line */
RestrictedFilesRegex = make([]*regexp.Regexp, 0)
for _, expr := range strings.Split(*RestrictedFiles, "\n") {
regex, err := regexp.Compile(expr)
if err != nil {
logSystemFatal("Failed compiling user restricted files regex: %s\n", expr)
}
RestrictedFilesRegex = append(RestrictedFilesRegex, regex)
}
listDir = _listDirRegexMatch
}
func isRestrictedFile(name string) bool {
for _, regex := range RestrictedFilesRegex {
if regex.MatchString(name) {
return true
}
}
return false
}