feat: improves ValidateContextDirectory performance

Signed-off-by: Nao YONASHIRO <owan.orisano@gmail.com>
This commit is contained in:
Nao YONASHIRO 2018-12-15 02:42:28 +09:00
parent f40f9c240a
commit b41ddc6058
1 changed files with 15 additions and 1 deletions

View File

@ -41,6 +41,20 @@ func ValidateContextDirectory(srcPath string, excludes []string) error {
if err != nil {
return err
}
pm, err := fileutils.NewPatternMatcher(excludes)
if err != nil {
return err
}
matches := func(file string) (bool, error) {
file = filepath.Clean(file)
if file == "." {
// Don't let them exclude everything, kind of silly.
return false, nil
}
return pm.Matches(file)
}
return filepath.Walk(contextRoot, func(filePath string, f os.FileInfo, err error) error {
if err != nil {
if os.IsPermission(err) {
@ -55,7 +69,7 @@ func ValidateContextDirectory(srcPath string, excludes []string) error {
// skip this directory/file if it's not in the path, it won't get added to the context
if relFilePath, err := filepath.Rel(contextRoot, filePath); err != nil {
return err
} else if skip, err := fileutils.Matches(relFilePath, excludes); err != nil {
} else if skip, err := matches(relFilePath); err != nil {
return err
} else if skip {
if f.IsDir() {