Commit aac872e1 authored by Alex Brainman's avatar Alex Brainman

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
parent 546081fd
...@@ -125,7 +125,7 @@ var pkgDeps = map[string][]string{ ...@@ -125,7 +125,7 @@ var pkgDeps = map[string][]string{
"os": {"L1", "os", "syscall", "time"}, "os": {"L1", "os", "syscall", "time"},
"path/filepath": {"L2", "os", "syscall"}, "path/filepath": {"L2", "os", "syscall"},
"io/ioutil": {"L2", "os", "path/filepath", "time"}, "io/ioutil": {"L2", "os", "path/filepath", "time"},
"os/exec": {"L2", "os", "syscall"}, "os/exec": {"L2", "os", "path/filepath", "syscall"},
"os/signal": {"L2", "os", "syscall"}, "os/signal": {"L2", "os", "syscall"},
// OS enables basic operating system functionality, // OS enables basic operating system functionality,
......
...@@ -12,6 +12,7 @@ import ( ...@@ -12,6 +12,7 @@ import (
"errors" "errors"
"io" "io"
"os" "os"
"path/filepath"
"strconv" "strconv"
"sync" "sync"
"syscall" "syscall"
...@@ -111,7 +112,7 @@ func Command(name string, arg ...string) *Cmd { ...@@ -111,7 +112,7 @@ func Command(name string, arg ...string) *Cmd {
Path: name, Path: name,
Args: append([]string{name}, arg...), Args: append([]string{name}, arg...),
} }
if !containsPathSeparator(name) { if filepath.Base(name) == name {
if lp, err := LookPath(name); err != nil { if lp, err := LookPath(name); err != nil {
cmd.lookPathErr = err cmd.lookPathErr = err
} else { } else {
...@@ -121,15 +122,6 @@ func Command(name string, arg ...string) *Cmd { ...@@ -121,15 +122,6 @@ func Command(name string, arg ...string) *Cmd {
return 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 // interfaceEqual protects against panics from doing equality tests on
// two interfaces with non-comparable underlying types. // two interfaces with non-comparable underlying types.
func interfaceEqual(a, b interface{}) bool { func interfaceEqual(a, b interface{}) bool {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment