mirror of https://github.com/Hilbis/Hilbish
refactor: dont return exec name since it isnt needed
parent
fd6ab59735
commit
c3f3b5c6a4
14
exec.go
14
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) {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue