MCPcopy Index your code
hub / github.com/GoEdgeLab/EdgeNode / LookPath

Function LookPath

internal/utils/exec/look_linux.go:15–58  ·  view source on GitHub ↗

LookPath customize our LookPath() function, to work in broken $PATH environment variable

(file string)

Source from the content-addressed store, hash-verified

13
14// LookPath customize our LookPath() function, to work in broken $PATH environment variable
15func LookPath(file string) (string, error) {
16 result, err := exec.LookPath(file)
17 if err == nil && len(result) > 0 {
18 return result, nil
19 }
20
21 // add common dirs contains executable files these may be excluded in $PATH environment variable
22 var binPaths = []string{
23 "/usr/sbin",
24 "/usr/bin",
25 "/usr/local/sbin",
26 "/usr/local/bin",
27 }
28
29 for _, binPath := range binPaths {
30 var fullPath = binPath + string(os.PathSeparator) + file
31
32 stat, err := os.Stat(fullPath)
33 if err != nil {
34 continue
35 }
36 if stat.IsDir() {
37 return "", syscall.EISDIR
38 }
39
40 var mode = stat.Mode()
41 if mode.IsDir() {
42 return "", syscall.EISDIR
43 }
44 err = syscall.Faccessat(unix.AT_FDCWD, fullPath, unix.X_OK, unix.AT_EACCESS)
45 if err == nil || (err != syscall.ENOSYS && err != syscall.EPERM) {
46 return fullPath, err
47 }
48 if mode&0111 != 0 {
49 return fullPath, nil
50 }
51 return "", fs.ErrPermission
52 }
53
54 return "", &exec.Error{
55 Name: file,
56 Err: exec.ErrNotFound,
57 }
58}
59

Callers

nothing calls this directly

Calls 1

StatMethod · 0.65

Tested by

no test coverage detected