2024-07-19 13:48:01 +00:00
|
|
|
//go:build windows
|
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 (
|
|
|
|
"path/filepath"
|
|
|
|
"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
|
|
|
nameExt := filepath.Ext(path)
|
2022-03-18 00:22:30 +00:00
|
|
|
pathExts := filepath.SplitList(os.Getenv("PATHEXT"))
|
|
|
|
if inPath {
|
|
|
|
if nameExt == "" {
|
|
|
|
for _, ext := range pathExts {
|
|
|
|
_, err := os.Stat(path + ext)
|
|
|
|
if err == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_, err := os.Stat(path)
|
2022-03-16 23:44:32 +00:00
|
|
|
if err == nil {
|
2024-12-29 05:52:00 +00:00
|
|
|
if Contains(pathExts, nameExt) { return nil }
|
|
|
|
return ErrNotExec
|
2022-03-16 23:44:32 +00:00
|
|
|
}
|
|
|
|
}
|
2022-03-18 00:22:30 +00:00
|
|
|
} else {
|
|
|
|
_, err := os.Stat(path)
|
|
|
|
if err == nil {
|
2024-12-29 05:52:00 +00:00
|
|
|
if Contains(pathExts, nameExt) { return nil }
|
|
|
|
return ErrNotExec
|
2022-03-18 00:22:30 +00:00
|
|
|
}
|
2022-03-16 23:44:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return os.ErrNotExist
|
|
|
|
}
|