gophi/regex.go
kim (grufwub) 0f2a2099f2 improve code commenting
Signed-off-by: kim (grufwub) <grufwub@gmail.com>
2020-04-24 12:09:54 +01:00

35 lines
967 B
Go

package main
import (
"regexp"
"strings"
)
func compileUserRestrictedFilesRegex(restrictedFiles string) []*regexp.Regexp {
Config.LogSystem("Compiling restricted file regular expressions\n")
/* Return slice */
restrictedFilesRegex := make([]*regexp.Regexp, 0)
/* Split the user supplied RestrictedFiles string by new-line */
for _, expr := range strings.Split(restrictedFiles, "\n") {
regex, err := regexp.Compile(expr)
if err != nil {
Config.LogSystemFatal("Failed compiling user restricted files regex: %s\n", expr)
}
restrictedFilesRegex = append(restrictedFilesRegex, regex)
}
return restrictedFilesRegex
}
/* Iterate through restricted file expressions, check if file _is_ restricted */
func isRestrictedFile(name string) bool {
for _, regex := range Config.RestrictedFiles {
if regex.MatchString(name) {
return true
}
}
return false
}