From a6a0538f42726ac7c9fa341d29955306cf146b1b Mon Sep 17 00:00:00 2001 From: Tobias Ribizel Date: Sun, 16 Jun 2024 23:53:33 +0200 Subject: [PATCH 1/4] 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 --- internal/pkg/util/util.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/internal/pkg/util/util.go b/internal/pkg/util/util.go index 9f314c37..890f2fa8 100644 --- a/internal/pkg/util/util.go +++ b/internal/pkg/util/util.go @@ -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 } } From faacb1cc4e0e330d76c4fccdc8c8f6cc274f5980 Mon Sep 17 00:00:00 2001 From: Tobias Ribizel Date: Sun, 16 Jun 2024 23:53:52 +0200 Subject: [PATCH 2/4] Add test for FindFilterFiles Signed-off-by: Tobias Ribizel --- internal/pkg/util/util_test.go | 50 ++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 internal/pkg/util/util_test.go diff --git a/internal/pkg/util/util_test.go b/internal/pkg/util/util_test.go new file mode 100644 index 00000000..c1d3abb3 --- /dev/null +++ b/internal/pkg/util/util_test.go @@ -0,0 +1,50 @@ +package util + +import ( + "os" + "path/filepath" + "reflect" + "sort" + "testing" + + "github.com/warewulf/warewulf/internal/pkg/wwlog" +) + +func TryCreatePath(t *testing.T, elem ...string) { + err := os.MkdirAll(filepath.Join(elem...), os.ModePerm) + if err != nil { + t.Errorf("Failed creating dir: %v", err) + t.FailNow() + } +} + +func Test_FindFilterFiles(t *testing.T) { + wwlog.SetLogLevel(wwlog.DEBUG) + dir, err := os.MkdirTemp(os.TempDir(), "warewulf-test") + if err != nil { + t.Errorf("Failed creating tmpdir: %v", err) + t.FailNow() + } + defer os.RemoveAll(dir) + TryCreatePath(t, dir, "boot") + TryCreatePath(t, dir, "usr", "local") + TryCreatePath(t, dir, "usr", "bin") + TryCreatePath(t, dir, "usr", "usr", "local") + TryCreatePath(t, dir, "bin") + TryCreatePath(t, dir, "lib") + + files, err := FindFilterFiles(dir, []string{"boot", "usr", "bin"}, []string{"/b*/", "/usr/local"}, true) + + if err != nil { + t.Errorf("FindFilerFiles failed: %v", err) + t.FailNow() + } + + expected := []string{"usr", "usr/bin", "usr/usr", "usr/usr/local"} + sort.Strings(expected) + sort.Strings(files) + if !reflect.DeepEqual(files, expected) { + t.Errorf("expected %v, got %v", expected, files) + t.FailNow() + } +} From 2681ccd8fa773f55d4355bea28d25a078e143fa9 Mon Sep 17 00:00:00 2001 From: Tobias Ribizel Date: Mon, 17 Jun 2024 00:04:48 +0200 Subject: [PATCH 3/4] Add changelog entry Signed-off-by: Tobias Ribizel --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c896e33e..de5b6505 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). `/sys/firmware/devicetree/base/serial-number` - Replace slice in templates with sprig substr. #1093 - Fix an invalid format issue for the GitHub nightly build action. #1258 +- Fix broken `/etc/warewulf/excludes` handling #1266 ## v4.5.4, 2024-06-12 From cc2690bc3571e2c93f13d3d13edf644970d35179 Mon Sep 17 00:00:00 2001 From: Tobias Ribizel Date: Mon, 17 Jun 2024 00:05:01 +0200 Subject: [PATCH 4/4] Add contributor Signed-off-by: Tobias Ribizel --- CONTRIBUTORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 6c61e512..056ec931 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -34,3 +34,4 @@ * Andreas Henkel * Timothy Middelkoop * Shane Nehring +* Tobias Ribizel