2022-03-16 23:44:32 +00:00
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
2022-03-18 00:22:30 +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 {
|
2022-03-18 00:22:30 +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 {
|
|
|
|
if contains(pathExts, nameExt) { return nil }
|
|
|
|
return errNotExec
|
|
|
|
}
|
2022-03-16 23:44:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return os.ErrNotExist
|
|
|
|
}
|