From f9043c3316d41119e4f51ace7319a2ef2b92c5c3 Mon Sep 17 00:00:00 2001 From: Alexey Igrychev Date: Tue, 21 Sep 2021 16:44:55 +0100 Subject: [PATCH] fix(stapel): changes in directories of import.include/excludePaths not triggered import Changes in files were not taken into account if paths were not specified explicitly: ``` import: - ... includePaths: - dir/file ``` or using asterisks: ``` import: - ... includePaths: - dir/* ``` Thus, imports that contained `includePaths` or `excludePaths` with directories did not work correctly and related changes did not trigger importing of actual files. --- pkg/build/stage/imports.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/pkg/build/stage/imports.go b/pkg/build/stage/imports.go index fe634a7736..965535ef7f 100644 --- a/pkg/build/stage/imports.go +++ b/pkg/build/stage/imports.go @@ -186,7 +186,12 @@ func generateChecksumCommand(from string, includePaths, excludePaths []string, r var nameIncludeArgs []string for _, includePath := range includePaths { - nameIncludeArgs = append(nameIncludeArgs, fmt.Sprintf("-wholename \"%s\"", path.Join(from, includePath))) + formattedPath := formatIncludeAndExcludePath(includePath) + nameIncludeArgs = append( + nameIncludeArgs, + fmt.Sprintf("-wholename \"%s\"", path.Join(from, formattedPath)), + fmt.Sprintf("-wholename \"%s\"", path.Join(from, formattedPath, "**")), + ) } if len(nameIncludeArgs) != 0 { @@ -195,7 +200,12 @@ func generateChecksumCommand(from string, includePaths, excludePaths []string, r var nameExcludeArgs []string for _, excludePath := range excludePaths { - nameExcludeArgs = append(nameExcludeArgs, fmt.Sprintf("! -wholename \"%s\"", path.Join(from, excludePath))) + formattedPath := formatIncludeAndExcludePath(excludePath) + nameExcludeArgs = append( + nameExcludeArgs, + fmt.Sprintf("! -wholename \"%s\"", path.Join(from, formattedPath)), + fmt.Sprintf("! -wholename \"%s\"", path.Join(from, formattedPath, "**")), + ) } if len(nameExcludeArgs) != 0 { @@ -225,6 +235,10 @@ func generateChecksumCommand(from string, includePaths, excludePaths []string, r return command } +func formatIncludeAndExcludePath(path string) string { + return strings.TrimRight(path, "*/") +} + func getImportID(importElm *config.Import) string { return util.Sha256Hash( "ImageName", importElm.ImageName,