diff options
| author | Alex Brainman <alex.brainman@gmail.com> | 2014-02-07 12:30:30 +1100 |
|---|---|---|
| committer | Alex Brainman <alex.brainman@gmail.com> | 2014-02-07 12:30:30 +1100 |
| commit | aac872e11806b7a66ab51f5efab7496a36e4f3da (patch) | |
| tree | c48222ead4ce3e1e019f110e38a020695b603643 /src/pkg/os/exec/exec.go | |
| parent | 546081fd01aad2446b9cd50444662c6438e7fb2e (diff) | |
| download | go-aac872e11806b7a66ab51f5efab7496a36e4f3da.tar.xz | |
os/exec: use filepath.Base in Command
filepath.Base covers all scenarios
(for example paths like d:hello.txt)
on windows
LGTM=iant, bradfitz
R=golang-codereviews, iant, bradfitz
CC=golang-codereviews
https://golang.org/cl/59740050
Diffstat (limited to 'src/pkg/os/exec/exec.go')
| -rw-r--r-- | src/pkg/os/exec/exec.go | 12 |
1 files changed, 2 insertions, 10 deletions
diff --git a/src/pkg/os/exec/exec.go b/src/pkg/os/exec/exec.go index ea4f692a31..4680036fdd 100644 --- a/src/pkg/os/exec/exec.go +++ b/src/pkg/os/exec/exec.go @@ -12,6 +12,7 @@ import ( "errors" "io" "os" + "path/filepath" "strconv" "sync" "syscall" @@ -111,7 +112,7 @@ func Command(name string, arg ...string) *Cmd { Path: name, Args: append([]string{name}, arg...), } - if !containsPathSeparator(name) { + if filepath.Base(name) == name { if lp, err := LookPath(name); err != nil { cmd.lookPathErr = err } else { @@ -121,15 +122,6 @@ func Command(name string, arg ...string) *Cmd { return cmd } -func containsPathSeparator(s string) bool { - for i := 0; i < len(s); i++ { - if os.IsPathSeparator(s[i]) { - return true - } - } - return false -} - // interfaceEqual protects against panics from doing equality tests on // two interfaces with non-comparable underlying types. func interfaceEqual(a, b interface{}) bool { |
