MCPcopy Create free account
hub / github.com/dim-an/cod / FindExecutable

Function FindExecutable

util/find_path.go:39–61  ·  view source on GitHub ↗
(name, dir, pathVar string)

Source from the content-addressed store, hash-verified

37}
38
39func 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
63func GetPathVar(environ []string) string {
64 for _, e := range environ {

Callers 1

CanonizeExecutablePathFunction · 0.92

Calls 1

checkExecutableFunction · 0.85

Tested by

no test coverage detected