From 977def1eb819a9f79b97eea0bfb1c054b9a797a4 Mon Sep 17 00:00:00 2001 From: Sebastian Florek Date: Wed, 18 Dec 2024 16:29:48 +0100 Subject: [PATCH] add support for glob pattern to the prautomation->deletes->files --- pkg/pr/deletes.go | 2 +- pkg/pr/utils.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/pkg/pr/deletes.go b/pkg/pr/deletes.go index 2314cda33..684d68741 100644 --- a/pkg/pr/deletes.go +++ b/pkg/pr/deletes.go @@ -15,7 +15,7 @@ func applyDeletes(deletes *DeleteSpec, ctx map[string]interface{}) error { dest = []byte(f) } - if err := os.Remove(string(dest)); err != nil { + if err := removeMatches(string(dest)); err != nil { return err } } diff --git a/pkg/pr/utils.go b/pkg/pr/utils.go index 8bca4849e..454af4c0e 100644 --- a/pkg/pr/utils.go +++ b/pkg/pr/utils.go @@ -40,3 +40,18 @@ func replaceTo(from, to string, rep func(data []byte) ([]byte, error)) error { func replaceInPlace(path string, rep func(data []byte) ([]byte, error)) error { return replaceTo(path, path, rep) } + +func removeMatches(glob string) error { + matches, err := filepath.Glob(glob) + if err != nil { + return err + } + + for _, match := range matches { + if err := os.Remove(match); err != nil { + return err + } + } + + return nil +}