diff --git a/exec.go b/exec.go index 1b4df4f..0d9e3d4 100644 --- a/exec.go +++ b/exec.go @@ -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) { diff --git a/execfile_unix.go b/execfile_unix.go index e4ab109..d19e7fe 100644 --- a/execfile_unix.go +++ b/execfile_unix.go @@ -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 } diff --git a/execfile_windows.go b/execfile_windows.go index b94782a..6689ecb 100644 --- a/execfile_windows.go +++ b/execfile_windows.go @@ -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 }