refactor: dont return exec name since it isnt needed

windows-fixes
TorchedSammy 2022-03-16 18:44:54 -04:00
parent fd6ab59735
commit c3f3b5c6a4
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
3 changed files with 16 additions and 17 deletions

14
exec.go
View File

@ -139,7 +139,7 @@ func execCommand(cmd, old string) error {
return interp.NewExitStatus(exitcode)
}
err, execName := lookpath(args[0])
err := lookpath(args[0])
if err == errNotExec {
hooks.Em.Emit("command.no-perm", args[0])
return interp.NewExitStatus(126)
@ -148,8 +148,6 @@ func execCommand(cmd, old string) error {
return interp.NewExitStatus(127)
}
args[0] = execName // windows, thanks
return interp.DefaultExecHandler(2 * time.Second)(ctx, args)
}
runner, _ := interp.New(
@ -161,7 +159,7 @@ func execCommand(cmd, old string) error {
return err
}
func lookpath(file string) (error, string) { // custom lookpath function so we know if a command is found *and* is executable
func lookpath(file string) error { // custom lookpath function so we know if a command is found *and* is executable
skip := []string{"./", "/", "../", "~/"}
for _, s := range skip {
if strings.HasPrefix(file, s) {
@ -170,15 +168,15 @@ func lookpath(file string) (error, string) { // custom lookpath function so we k
}
for _, dir := range filepath.SplitList(os.Getenv("PATH")) {
path := filepath.Join(dir, file)
err, execName := findExecutable(path)
err := findExecutable(path)
if err == errNotExec {
return err, ""
return err
} else if err == nil {
return nil, execName
return execName, nil
}
}
return os.ErrNotExist, ""
return os.ErrNotExist
}
func splitInput(input string) ([]string, string) {

View File

@ -7,13 +7,13 @@ import (
"os"
)
func findExecutable(path string) (error, string) {
func findExecutable(path string) error {
f, err := os.Stat(path)
if err != nil {
return err, ""
return err
}
if m := f.Mode(); !m.IsDir() && m & 0111 != 0 {
return nil, filepath.Base(path)
return nil
}
return errNotExec, ""
return errNotExec
}

View File

@ -3,24 +3,25 @@
package main
import (
"fmt"
"path/filepath"
"os"
)
func findExecutable(path string) (error, string) {
func findExecutable(path string) error {
nameExt := filepath.Ext(path)
if nameExt == "" {
for _, ext := range filepath.SplitList(os.Getenv("PATHEXT")) {
_, err := os.Stat(path + ext)
if err != nil {
return nil, filepath.Base(path + ext)
if err == nil {
return nil
}
}
} else {
_, err := os.Stat(path)
return err, ""
return err
}
return errNotExec, ""
return errNotExec
}