fileutils.go 679 B

1234567891011121314151617181920212223242526
  1. package fileutils
  2. import (
  3. log "github.com/Sirupsen/logrus"
  4. "path/filepath"
  5. )
  6. // Matches returns true if relFilePath matches any of the patterns
  7. func Matches(relFilePath string, patterns []string) (bool, error) {
  8. for _, exclude := range patterns {
  9. matched, err := filepath.Match(exclude, relFilePath)
  10. if err != nil {
  11. log.Errorf("Error matching: %s (pattern: %s)", relFilePath, exclude)
  12. return false, err
  13. }
  14. if matched {
  15. if filepath.Clean(relFilePath) == "." {
  16. log.Errorf("Can't exclude whole path, excluding pattern: %s", exclude)
  17. continue
  18. }
  19. log.Debugf("Skipping excluded path: %s", relFilePath)
  20. return true, nil
  21. }
  22. }
  23. return false, nil
  24. }