mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
6f4d847046
Signed-off-by: Antonio Murdaca <me@runcom.ninja>
26 lines
684 B
Go
26 lines
684 B
Go
package fileutils
|
|
|
|
import (
|
|
"github.com/Sirupsen/logrus"
|
|
"path/filepath"
|
|
)
|
|
|
|
// 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
|
|
}
|