38 lines
1 KiB
Go
38 lines
1 KiB
Go
package executables
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
"velvettear/badger/internal/log"
|
|
)
|
|
|
|
// unexported function(s)
|
|
func locateSystemExecutables() []Executable {
|
|
executables := []Executable{}
|
|
for _, executableName := range MandatoryExecutables {
|
|
executable, error := locateSystemExecutable(executableName)
|
|
if error != nil {
|
|
log.Debug("encountered an error locating system executable '"+executableName+"'", error.Error())
|
|
continue
|
|
}
|
|
executables = append(executables, executable)
|
|
}
|
|
return executables
|
|
}
|
|
|
|
func locateSystemExecutable(executableName string) (Executable, error) {
|
|
executable := Executable{Name: executableName}
|
|
if len(executable.Name) == 0 {
|
|
return executable, errors.New("no executable name given")
|
|
}
|
|
result, _ := spawnProcess("which", executable.Name)
|
|
stats, error := os.Stat(result)
|
|
if error != nil {
|
|
return executable, error
|
|
}
|
|
executable.Path = result
|
|
if stats.Mode()&0100 != 0 {
|
|
return executable, errors.New("file '" + executable.Name + "' (" + executable.Path + ") is not executable")
|
|
}
|
|
return executable, nil
|
|
}
|