2024-07-19 13:48:01 +00:00
|
|
|
//go:build unix
|
2022-03-16 23:44:32 +00:00
|
|
|
|
2024-12-29 01:43:33 +00:00
|
|
|
package util
|
2022-03-16 23:44:32 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
2024-12-29 01:43:33 +00:00
|
|
|
func FindExecutable(path string, inPath, dirs bool) error {
|
2022-03-16 23:44:32 +00:00
|
|
|
f, err := os.Stat(path)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-03-18 00:22:30 +00:00
|
|
|
if dirs {
|
|
|
|
if m := f.Mode(); m & 0111 != 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if m := f.Mode(); !m.IsDir() && m & 0111 != 0 {
|
|
|
|
return nil
|
|
|
|
}
|
2022-03-16 23:44:32 +00:00
|
|
|
}
|
2024-12-29 05:12:06 +00:00
|
|
|
return ErrNotExec
|
2022-03-16 23:44:32 +00:00
|
|
|
}
|