Add lookup.GetPath and lookup.GetPaths functions

Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
Evan Lezar
2022-05-10 14:48:01 +02:00
parent 117f68fa6e
commit 1d2e1bd403
2 changed files with 70 additions and 12 deletions

View File

@@ -25,24 +25,13 @@ import (
log "github.com/sirupsen/logrus"
)
const (
envPath = "PATH"
)
var defaultPaths = []string{"/usr/local/sbin", "/usr/local/bin", "/usr/sbin", "/usr/bin", "/sbin", "/bin"}
type executable struct {
file
}
// NewExecutableLocator creates a locator to fine executable files in the path. A logger can also be specified.
func NewExecutableLocator(logger *log.Logger, root string) Locator {
pathEnv := os.Getenv(envPath)
paths := filepath.SplitList(pathEnv)
if root != "" {
paths = append(paths, defaultPaths...)
}
paths := GetPaths(root)
var prefixes []string
for _, dir := range paths {