From 517c42ac086a8b46265d09e76b381476263a0d50 Mon Sep 17 00:00:00 2001 From: Jayson Reis Date: Tue, 24 Nov 2020 16:17:19 +0100 Subject: [PATCH 1/2] Fix exec plugins on windows The exec plugin implementation checks if an executable file exists but on windows it won't check for files with .exe suffix thus falling back to go plugin implementation --- api/internal/plugins/loader/loader.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/api/internal/plugins/loader/loader.go b/api/internal/plugins/loader/loader.go index aaa7c36004..ca186e454e 100644 --- a/api/internal/plugins/loader/loader.go +++ b/api/internal/plugins/loader/loader.go @@ -10,6 +10,7 @@ import ( "path/filepath" "plugin" "reflect" + "runtime" "strings" "github.com/pkg/errors" @@ -177,7 +178,11 @@ func (l *Loader) loadPlugin(res *resource.Resource) (resmap.Configurable, error) func (l *Loader) loadExecOrGoPlugin(resId resid.ResId) (resmap.Configurable, error) { // First try to load the plugin as an executable. - p := execplugin.NewExecPlugin(l.absolutePluginPath(resId)) + pluginPath := l.absolutePluginPath(resId) + if runtime.GOOS == "windows" { + pluginPath = fmt.Sprintf("%s.exe", pluginPath) + } + p := execplugin.NewExecPlugin(pluginPath) err := p.ErrIfNotExecutable() if err == nil { return p, nil From 975fd36216090746d071442a3dd2af108b9bced6 Mon Sep 17 00:00:00 2001 From: Jayson Reis Date: Wed, 9 Dec 2020 16:46:22 +0100 Subject: [PATCH 2/2] Implement lookForExecutable to search fo possible executable plugins --- api/internal/plugins/loader/loader.go | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/api/internal/plugins/loader/loader.go b/api/internal/plugins/loader/loader.go index ca186e454e..1907db96a9 100644 --- a/api/internal/plugins/loader/loader.go +++ b/api/internal/plugins/loader/loader.go @@ -178,11 +178,8 @@ func (l *Loader) loadPlugin(res *resource.Resource) (resmap.Configurable, error) func (l *Loader) loadExecOrGoPlugin(resId resid.ResId) (resmap.Configurable, error) { // First try to load the plugin as an executable. - pluginPath := l.absolutePluginPath(resId) - if runtime.GOOS == "windows" { - pluginPath = fmt.Sprintf("%s.exe", pluginPath) - } - p := execplugin.NewExecPlugin(pluginPath) + path, _ := lookForExecutable(l.absolutePluginPath(resId)) + p := execplugin.NewExecPlugin(path) err := p.ErrIfNotExecutable() if err == nil { return p, nil @@ -249,3 +246,21 @@ func copyPlugin(c resmap.Configurable) resmap.Configurable { newNamed := newIndirect.Interface() return newNamed.(resmap.Configurable) } + +func lookForExecutable(partialPath string) (fullPath string, err error) { + if runtime.GOOS != "windows" { + return partialPath, nil + } + + possibleWindowsSuffixes := []string{"exe", "bat", "ps1"} + + for _, possibleWindowsSuffix := range possibleWindowsSuffixes { + fullPath := fmt.Sprintf("%s.%s", partialPath, possibleWindowsSuffix) + _, err := os.Stat(fullPath) + if err == nil { + return fullPath, nil + } + } + + return "", fmt.Errorf("no possible excutable found, partial path: %v tried suffixes: %v", partialPath, possibleWindowsSuffixes) +}