Skip to content

Commit 9deab85

Browse files
committed
Implement lookForExecutable to search fo possible executable plugins
1 parent 517c42a commit 9deab85

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

api/internal/plugins/loader/loader.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,12 @@ func (l *Loader) loadPlugin(res *resource.Resource) (resmap.Configurable, error)
178178

179179
func (l *Loader) loadExecOrGoPlugin(resId resid.ResId) (resmap.Configurable, error) {
180180
// First try to load the plugin as an executable.
181-
pluginPath := l.absolutePluginPath(resId)
182-
if runtime.GOOS == "windows" {
183-
pluginPath = fmt.Sprintf("%s.exe", pluginPath)
181+
path, err := lookForExecutable(l.absolutePluginPath(resId))
182+
if err != nil {
183+
return execplugin.NewExecPlugin(path), nil
184184
}
185-
p := execplugin.NewExecPlugin(pluginPath)
186-
err := p.ErrIfNotExecutable()
185+
p := execplugin.NewExecPlugin(path)
186+
err = p.ErrIfNotExecutable()
187187
if err == nil {
188188
return p, nil
189189
}
@@ -249,3 +249,21 @@ func copyPlugin(c resmap.Configurable) resmap.Configurable {
249249
newNamed := newIndirect.Interface()
250250
return newNamed.(resmap.Configurable)
251251
}
252+
253+
func lookForExecutable(partialPath string) (fullPath string, err error) {
254+
if runtime.GOOS != "windows" {
255+
return partialPath, nil
256+
}
257+
258+
possibleWindowsSuffixes := []string{"exe", "bat", "ps1"}
259+
260+
for _, possibleWindowsSuffix := range possibleWindowsSuffixes {
261+
fullPath := fmt.Sprintf("%s.%s", partialPath, possibleWindowsSuffix)
262+
_, err := os.Stat(fullPath)
263+
if err == nil {
264+
return fullPath, nil
265+
}
266+
}
267+
268+
return "", fmt.Errorf("no possible excutable found, partial path: %v tried suffixes: %v", partialPath, possibleWindowsSuffixes)
269+
}

0 commit comments

Comments
 (0)