Skip to content

Commit

Permalink
FindHelperBinary will try LookPath of absolute path
Browse files Browse the repository at this point in the history
exec.LookPath seems to handle absolute paths gracefully. On Windows this
allows to additionally check for all known executable alternatives
when only name is provided.

Signed-off-by: Arthur Sengileyev <[email protected]>
  • Loading branch information
arixmkii committed Feb 3, 2023
1 parent 17f7e40 commit ba89abf
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1332,9 +1332,14 @@ func (c *Config) FindHelperBinary(name string, searchPATH bool) (string, error)
path = filepath.Join(bindirPath, strings.TrimPrefix(path, bindirPrefix+string(filepath.Separator)))
}
}
fullpath := filepath.Join(path, name)
if fi, err := os.Stat(fullpath); err == nil && fi.Mode().IsRegular() {
return fullpath, nil
// Absolute path will force exec.LookPath to check for binary existence instead of lookup everywhere in PATH
abspath, err := filepath.Abs(filepath.Join(path, name))
if err == nil {
// exec.LookPath from absolute path on Unix is equal to os.Stat + IsNotDir + check for executable bits in FileMode
// exec.LookPath from absolute path on Windows is equal to os.Stat + IsNotDir for `file.ext` or loops through extensions from PATHEXT for `file`
if lp, err := exec.LookPath(abspath); err == nil {
return lp, nil
}
}
}
if searchPATH {
Expand Down

0 comments on commit ba89abf

Please sign in to comment.