]> Cypherpunks repositories - gostls13.git/commitdiff
os/exec: use filepath.Base in Command
authorAlex Brainman <alex.brainman@gmail.com>
Fri, 7 Feb 2014 01:30:30 +0000 (12:30 +1100)
committerAlex Brainman <alex.brainman@gmail.com>
Fri, 7 Feb 2014 01:30:30 +0000 (12:30 +1100)
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

src/pkg/go/build/deps_test.go
src/pkg/os/exec/exec.go

index ab56b6554ca5a794b9bbe0a889d8ceb411a90c5b..3e7ae22a82a8bcd42eb99c4c7487388c59874049 100644 (file)
@@ -125,7 +125,7 @@ var pkgDeps = map[string][]string{
        "os":            {"L1", "os", "syscall", "time"},
        "path/filepath": {"L2", "os", "syscall"},
        "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 enables basic operating system functionality,
index ea4f692a31c3dd66b7e19c4bfc42bf717a2c5891..4680036fddcc6eefc19db1cbff5b1bbe59ceb0e9 100644 (file)
@@ -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 {