pkg/fileutils/fileutils.go
Antonio Murdaca c38e2a81e4 Refactor ultis/utils_daemon, fixes #11908
Signed-off-by: Antonio Murdaca <me@runcom.ninja>
2015-04-03 20:20:04 +02:00

27 lines
685 B
Go

package fileutils
import (
"path/filepath"
"github.com/Sirupsen/logrus"
)
// Matches returns true if relFilePath matches any of the patterns
func Matches(relFilePath string, patterns []string) (bool, error) {
for _, exclude := range patterns {
matched, err := filepath.Match(exclude, relFilePath)
if err != nil {
logrus.Errorf("Error matching: %s (pattern: %s)", relFilePath, exclude)
return false, err
}
if matched {
if filepath.Clean(relFilePath) == "." {
logrus.Errorf("Can't exclude whole path, excluding pattern: %s", exclude)
continue
}
logrus.Debugf("Skipping excluded path: %s", relFilePath)
return true, nil
}
}
return false, nil
}