Fix FindFilterFiles

There are two bugs in the handling of exclusion patterns:
- The paths being checked against patterns are relative,
  so leading / need to be stripped
- filepath.Match only does a string comparison,
  and the paths we traverse don't include trailing /

Signed-off-by: Tobias Ribizel <mail@ribizel.de>
This commit is contained in:
Tobias Ribizel
2024-06-16 23:53:33 +02:00
parent d42f0f8f38
commit a6a0538f42

View File

@@ -260,6 +260,10 @@ func FindFilterFiles(
ignorePattern []string,
ignore_xdev bool) (ofiles []string, err error) {
wwlog.Debug("Finding files: %s include: %s ignore: %s", path, includePattern, ignorePattern)
// preprocess patterns to remove leading (and trailing) /, as we are handling relative paths
for i, pattern := range ignorePattern {
ignorePattern[i] = strings.Trim(pattern, "/")
}
cwd, err := os.Getwd()
if err != nil {
return ofiles, err
@@ -319,6 +323,7 @@ func FindFilterFiles(
}
for _, ignored_pat := range ignorePattern {
if ignored, _ := filepath.Match(ignored_pat, location); ignored {
wwlog.Debug("Ignored %s due to pattern %s", location, ignored_pat)
return filepath.SkipDir
}
}