os/exec: cleanup and remove duplicated code

Change-Id: Ia2f61427b1cc09064ac4c0563bccbd9b98767a0e
Reviewed-on: https://go-review.googlesource.com/18118
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Hiroshi Ioka 2015-12-26 16:50:01 +09:00 committed by Brad Fitzpatrick
parent c1e8892060
commit 80423f1e64
4 changed files with 29 additions and 60 deletions

View file

@ -9,6 +9,7 @@ package exec
import (
"errors"
"os"
"path/filepath"
"strings"
)
@ -42,16 +43,13 @@ func LookPath(file string) (string, error) {
}
return "", &Error{file, err}
}
pathenv := os.Getenv("PATH")
if pathenv == "" {
return "", &Error{file, ErrNotFound}
}
for _, dir := range strings.Split(pathenv, ":") {
path := os.Getenv("PATH")
for _, dir := range filepath.SplitList(path) {
if dir == "" {
// Unix shell semantics: path element "" means "."
dir = "."
}
path := dir + "/" + file
path := filepath.Join(dir, file)
if err := findExecutable(path); err == nil {
return path, nil
}