feat: improves ValidateContextDirectory performance
Signed-off-by: Nao YONASHIRO <owan.orisano@gmail.com>
This commit is contained in:
parent
f40f9c240a
commit
b41ddc6058
@ -41,6 +41,20 @@ func ValidateContextDirectory(srcPath string, excludes []string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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 {
|
return filepath.Walk(contextRoot, func(filePath string, f os.FileInfo, err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsPermission(err) {
|
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
|
// 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 {
|
if relFilePath, err := filepath.Rel(contextRoot, filePath); err != nil {
|
||||||
return err
|
return err
|
||||||
} else if skip, err := fileutils.Matches(relFilePath, excludes); err != nil {
|
} else if skip, err := matches(relFilePath); err != nil {
|
||||||
return err
|
return err
|
||||||
} else if skip {
|
} else if skip {
|
||||||
if f.IsDir() {
|
if f.IsDir() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user