aboutsummaryrefslogtreecommitdiff
path: root/src/os/exec/exec.go
diff options
context:
space:
mode:
authorqiulaidongfeng <2645477756@qq.com>2023-07-25 01:19:30 +0000
committerGopher Robot <gobot@golang.org>2023-07-26 11:13:35 +0000
commit616193510f45c6c588af9cb022dfdee52400d0ca (patch)
tree3ccf4cfa5e123f3c47cdd9d2649c5118a06fbf6e /src/os/exec/exec.go
parent7fed33815cf57bf8d6b6ddfbd2ce0f5d8180b4f6 (diff)
downloadgo-616193510f45c6c588af9cb022dfdee52400d0ca.tar.xz
os/exec: avoid calling LookPath in cmd.Start for resolved paths
Follow up on CL 511458, see https://go-review.googlesource.com/c/go/+/511458/2..4/src/cmd/go/main.go#b270 . For #36768. Change-Id: Icc2a4dbb1219b1d69dd10a900478957b0e975847 Change-Id: Icc2a4dbb1219b1d69dd10a900478957b0e975847 GitHub-Last-Rev: bac7e66496806d505270c5b90d53672d80a1ca29 GitHub-Pull-Request: golang/go#61517 Reviewed-on: https://go-review.googlesource.com/c/go/+/512155 Auto-Submit: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com>
Diffstat (limited to 'src/os/exec/exec.go')
-rw-r--r--src/os/exec/exec.go36
1 files changed, 4 insertions, 32 deletions
diff --git a/src/os/exec/exec.go b/src/os/exec/exec.go
index 138be29ecf..a23d1c4a2d 100644
--- a/src/os/exec/exec.go
+++ b/src/os/exec/exec.go
@@ -590,32 +590,6 @@ func (c *Cmd) Run() error {
return c.Wait()
}
-// lookExtensions finds windows executable by its dir and path.
-// It uses LookPath to try appropriate extensions.
-// lookExtensions does not search PATH, instead it converts `prog` into `.\prog`.
-func lookExtensions(path, dir string) (string, error) {
- if filepath.Base(path) == path {
- path = "." + string(filepath.Separator) + path
- }
- if dir == "" {
- return LookPath(path)
- }
- if filepath.VolumeName(path) != "" {
- return LookPath(path)
- }
- if len(path) > 1 && os.IsPathSeparator(path[0]) {
- return LookPath(path)
- }
- dirandpath := filepath.Join(dir, path)
- // We assume that LookPath will only add file extension.
- lp, err := LookPath(dirandpath)
- if err != nil {
- return "", err
- }
- ext := strings.TrimPrefix(lp, dirandpath)
- return path + ext, nil
-}
-
// Start starts the specified command but does not wait for it to complete.
//
// If Start returns successfully, the c.Process field will be set.
@@ -649,13 +623,11 @@ func (c *Cmd) Start() error {
}
return c.Err
}
- if runtime.GOOS == "windows" {
- lp, err := lookExtensions(c.Path, c.Dir)
- if err != nil {
- return err
- }
- c.Path = lp
+ lp, err := lookExtensions(c.Path, c.Dir)
+ if err != nil {
+ return err
}
+ c.Path = lp
if c.Cancel != nil && c.ctx == nil {
return errors.New("exec: command with a non-nil Cancel was not created with CommandContext")
}