(name, dir, pathVar string)
| 37 | } |
| 38 | |
| 39 | func FindExecutable(name, dir, pathVar string) (string, error) { |
| 40 | if strings.ContainsRune(name, os.PathSeparator) { |
| 41 | path := name |
| 42 | if !filepath.IsAbs(path) { |
| 43 | path = filepath.Join(dir, path) |
| 44 | } |
| 45 | return path, nil |
| 46 | } |
| 47 | for _, pathDir := range filepath.SplitList(pathVar) { |
| 48 | if pathDir == "" { |
| 49 | pathDir = "." |
| 50 | } |
| 51 | path := filepath.Join(pathDir, name) |
| 52 | if !filepath.IsAbs(path) { |
| 53 | path = filepath.Join(dir, path) |
| 54 | } |
| 55 | err := checkExecutable(path) |
| 56 | if err == nil { |
| 57 | return path, nil |
| 58 | } |
| 59 | } |
| 60 | return "", fmt.Errorf("%w: %s", ErrBinaryNotFound, name) |
| 61 | } |
| 62 | |
| 63 | func GetPathVar(environ []string) string { |
| 64 | for _, e := range environ { |
no test coverage detected