Skip to content

Commit

Permalink
Implement lookForExecutable to search fo possible executable plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysonsantos committed Dec 9, 2020
1 parent 517c42a commit 9deab85
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions api/internal/plugins/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,12 @@ 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)
path, err := lookForExecutable(l.absolutePluginPath(resId))
if err != nil {
return execplugin.NewExecPlugin(path), nil
}
p := execplugin.NewExecPlugin(pluginPath)
err := p.ErrIfNotExecutable()
p := execplugin.NewExecPlugin(path)
err = p.ErrIfNotExecutable()
if err == nil {
return p, nil
}
Expand Down Expand Up @@ -249,3 +249,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)
}

0 comments on commit 9deab85

Please sign in to comment.