Skip to content

Commit

Permalink
Merge pull request #1131 from arixmkii/internal_look_path_impl
Browse files Browse the repository at this point in the history
LookPath like impelementations for OS specific executable searches
  • Loading branch information
openshift-merge-robot authored Feb 14, 2023
2 parents 9c1b8d9 + 0c2ecb0 commit 3009dfe
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1332,9 +1332,13 @@ 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
if abspath, err := filepath.Abs(filepath.Join(path, name)); 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 3009dfe

Please sign in to comment.