Skip to content

Commit 975fd36

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

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

api/internal/plugins/loader/loader.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,8 @@ 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)
184-
}
185-
p := execplugin.NewExecPlugin(pluginPath)
181+
path, _ := lookForExecutable(l.absolutePluginPath(resId))
182+
p := execplugin.NewExecPlugin(path)
186183
err := p.ErrIfNotExecutable()
187184
if err == nil {
188185
return p, nil
@@ -249,3 +246,21 @@ func copyPlugin(c resmap.Configurable) resmap.Configurable {
249246
newNamed := newIndirect.Interface()
250247
return newNamed.(resmap.Configurable)
251248
}
249+
250+
func lookForExecutable(partialPath string) (fullPath string, err error) {
251+
if runtime.GOOS != "windows" {
252+
return partialPath, nil
253+
}
254+
255+
possibleWindowsSuffixes := []string{"exe", "bat", "ps1"}
256+
257+
for _, possibleWindowsSuffix := range possibleWindowsSuffixes {
258+
fullPath := fmt.Sprintf("%s.%s", partialPath, possibleWindowsSuffix)
259+
_, err := os.Stat(fullPath)
260+
if err == nil {
261+
return fullPath, nil
262+
}
263+
}
264+
265+
return "", fmt.Errorf("no possible excutable found, partial path: %v tried suffixes: %v", partialPath, possibleWindowsSuffixes)
266+
}

0 commit comments

Comments
 (0)