From a3b6499bb3b68908d8a1b6f6da66a8f77e49f932 Mon Sep 17 00:00:00 2001 From: German Lashevich Date: Sun, 24 Dec 2023 14:15:01 +0100 Subject: [PATCH 1/3] fix(sync): trim path separator from vendir directories --- internal/myks/sync.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/myks/sync.go b/internal/myks/sync.go index 3f961bac..b01805db 100644 --- a/internal/myks/sync.go +++ b/internal/myks/sync.go @@ -121,6 +121,7 @@ func (a Application) cleanupVendorDir(vendorDir, vendirConfigFile string) error for _, dir := range config["directories"].([]interface{}) { dirMap := dir.(map[string]interface{}) path := dirMap["path"].(string) + path = strings.TrimSuffix(path, string(filepath.Separator)) dirs = append(dirs, path+string(filepath.Separator)) } From bdca02c8260e0ba08dff6baee3036937e9328729 Mon Sep 17 00:00:00 2001 From: German Lashevich Date: Sun, 24 Dec 2023 14:42:42 +0100 Subject: [PATCH 2/3] add tests --- internal/myks/sync_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/internal/myks/sync_test.go b/internal/myks/sync_test.go index 7a64ab09..e6ae1be5 100644 --- a/internal/myks/sync_test.go +++ b/internal/myks/sync_test.go @@ -104,6 +104,31 @@ func Test_cleanupVendorDir(t *testing.T) { }, wantDirs: []string{"charts/httpbingo2"}, }, + { + name: "weird-paths", + vendirYaml: "directories:\n" + + " - path: charts/httpbingo\n" + + " - path: charts/httpbingo1/\n" + + " - path: charts/httpbingo2//\n" + + " - path: charts//httpbingo22//\n" + + " - path: charts/../httpbingo69\n", + createDirs: []string{ + "charts/httpbingo", + "charts/httpbingo1", + "charts/httpbingo2", + "charts/httpbingo22", + "httpbingo69", + "charts/trash", + "charts/trash1", + }, + wantDirs: []string{ + "charts/httpbingo", + "charts/httpbingo1", + "charts/httpbingo2", + "charts/httpbingo22", + "httpbingo69", + }, + }, } for _, tt := range tests { From 81290d1ad6aab518b6daf398b793addea7f55cf3 Mon Sep 17 00:00:00 2001 From: German Lashevich Date: Sun, 24 Dec 2023 14:42:48 +0100 Subject: [PATCH 3/3] cover more cases --- internal/myks/sync.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/internal/myks/sync.go b/internal/myks/sync.go index b01805db..869b6ff9 100644 --- a/internal/myks/sync.go +++ b/internal/myks/sync.go @@ -121,8 +121,7 @@ func (a Application) cleanupVendorDir(vendorDir, vendirConfigFile string) error for _, dir := range config["directories"].([]interface{}) { dirMap := dir.(map[string]interface{}) path := dirMap["path"].(string) - path = strings.TrimSuffix(path, string(filepath.Separator)) - dirs = append(dirs, path+string(filepath.Separator)) + dirs = append(dirs, filepath.Clean(path)+string(filepath.Separator)) } log.Debug().Strs("managed dirs", dirs).Msg("")