From de9351fd76303e152e53713ae5ecb6744802fe13 Mon Sep 17 00:00:00 2001 From: Igor Ignatyev Date: Wed, 15 Jan 2025 15:04:44 +0300 Subject: [PATCH] #60: Strategies bleeding to extra dirs/files --- compose/builder.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/compose/builder.go b/compose/builder.go index 221891c..c661e1b 100644 --- a/compose/builder.go +++ b/compose/builder.go @@ -58,7 +58,24 @@ var ( StrategyFilterPackage = "filter-package-files" ) -// return conflict const (0 - no warning, 1 - conflict with local, 2 conflict with pacakge) +// return conflict const (0 - no warning, 1 - conflict with local, 2 conflict with package) + +func cleanStrategyPaths(paths []string) []string { + // remove trailing separators and add only one separator at the end. + // so prefix won't be greedy during comparison. + var r []string + + for _, p := range paths { + path := filepath.Clean(p) + if !strings.HasSuffix(path, string(os.PathSeparator)) { + path += string(os.PathSeparator) + } + + r = append(r, path) + } + + return r +} func retrieveStrategies(packages []*Package) ([]*mergeStrategy, map[string][]*mergeStrategy) { var ls []*mergeStrategy @@ -70,7 +87,7 @@ func retrieveStrategies(packages []*Package) ([]*mergeStrategy, map[string][]*me if s == undefinedStrategy { continue } - strategy := &mergeStrategy{s, t, item.Paths} + strategy := &mergeStrategy{s, t, cleanStrategyPaths(item.Paths)} if t == localStrategy { ls = append(ls, strategy)