github.com/titanous/docker@v1.4.1/pkg/fileutils/fileutils.go (about)

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