2014-09-30 06:21:41 +00:00
|
|
|
package fileutils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
2015-03-29 19:48:52 +00:00
|
|
|
|
|
|
|
"github.com/Sirupsen/logrus"
|
2014-09-30 06:21:41 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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 {
|
2015-03-26 22:22:04 +00:00
|
|
|
logrus.Errorf("Error matching: %s (pattern: %s)", relFilePath, exclude)
|
2014-09-30 06:21:41 +00:00
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
if matched {
|
|
|
|
if filepath.Clean(relFilePath) == "." {
|
2015-03-26 22:22:04 +00:00
|
|
|
logrus.Errorf("Can't exclude whole path, excluding pattern: %s", exclude)
|
2014-09-30 06:21:41 +00:00
|
|
|
continue
|
|
|
|
}
|
2015-03-26 22:22:04 +00:00
|
|
|
logrus.Debugf("Skipping excluded path: %s", relFilePath)
|
2014-09-30 06:21:41 +00:00
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false, nil
|
|
|
|
}
|