[go] os/exec: fix GOOS=windows,Cmd.Run always calls LookPath before returning

15 views
Skip to first unread message

Gerrit Bot (Gerrit)

unread,
Jul 21, 2023, 10:40:20 PM7/21/23
to goph...@pubsubhelper.golang.org, qiulaidongfeng, golang-co...@googlegroups.com

Gerrit Bot has uploaded this change for review.

View Change

os/exec: fix GOOS=windows,Cmd.Run always calls LookPath before returning

Follow up on CL 511458, see https://go-review.googlesource.com/c/go/+/511458/2..4/src/cmd/go/main.go#b270 .

Fixes #36768

Change-Id: Icc2a4dbb1219b1d69dd10a900478957b0e975847
GitHub-Last-Rev: 6f84ef7207fc3592bb6ddce1a17a183c0168d88f
GitHub-Pull-Request: golang/go#61517
---
M src/os/exec/exec.go
M src/os/exec/lp_windows.go
2 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/src/os/exec/exec.go b/src/os/exec/exec.go
index 138be29..d6b5a749 100644
--- a/src/os/exec/exec.go
+++ b/src/os/exec/exec.go
@@ -597,6 +597,15 @@
if filepath.Base(path) == path {
path = "." + string(filepath.Separator) + path
}
+ exts := pathExt()
+ if ext := filepath.Ext(path); ext != "" {
+ for _, e := range exts {
+ if strings.EqualFold(ext, e) {
+ // Assume that path has already been resolved.
+ return path, nil
+ }
+ }
+ }
if dir == "" {
return LookPath(path)
}
diff --git a/src/os/exec/lp_windows.go b/src/os/exec/lp_windows.go
index 066d38d..373a8f8 100644
--- a/src/os/exec/lp_windows.go
+++ b/src/os/exec/lp_windows.go
@@ -63,6 +63,11 @@
// As of Go 1.19, LookPath will instead return that path along with an error satisfying
// errors.Is(err, ErrDot). See the package documentation for more details.
func LookPath(file string) (string, error) {
+ return lookPath(file, pathExt())
+
+}
+
+func pathExt() []string {
var exts []string
x := os.Getenv(`PATHEXT`)
if x != "" {
@@ -78,7 +83,11 @@
} else {
exts = []string{".com", ".exe", ".bat", ".cmd"}
}
+ return exts
+}

+// lookPath implements LookPath for the given PATHEXT list.
+func lookPath(file string, exts []string) (string, error) {
if strings.ContainsAny(file, `:\/`) {
f, err := findExecutable(file, exts)
if err == nil {

To view, visit change 512155. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Icc2a4dbb1219b1d69dd10a900478957b0e975847
Gerrit-Change-Number: 512155
Gerrit-PatchSet: 1
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-CC: qiulaidongfeng <26454...@qq.com>

Gerrit Bot (Gerrit)

unread,
Jul 21, 2023, 10:51:08 PM7/21/23
to qiulaidongfeng, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Attention is currently required from: Brad Fitzpatrick, Ian Lance Taylor.

Gerrit Bot uploaded patch set #2 to this change.

View Change

os/exec: fix GOOS=windows,Cmd.Run always calls LookPath before returning

Follow up on CL 511458, see https://go-review.googlesource.com/c/go/+/511458/2..4/src/cmd/go/main.go#b270 .

Fixes #36768

Change-Id: Icc2a4dbb1219b1d69dd10a900478957b0e975847

Change-Id: Icc2a4dbb1219b1d69dd10a900478957b0e975847
GitHub-Last-Rev: 6f84ef7207fc3592bb6ddce1a17a183c0168d88f
GitHub-Pull-Request: golang/go#61517
---
M src/os/exec/exec.go
M src/os/exec/lp_windows.go
2 files changed, 18 insertions(+), 0 deletions(-)

To view, visit change 512155. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newpatchset
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Icc2a4dbb1219b1d69dd10a900478957b0e975847
Gerrit-Change-Number: 512155
Gerrit-PatchSet: 2
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
Gerrit-CC: Gopher Robot <go...@golang.org>
Gerrit-CC: qiulaidongfeng <26454...@qq.com>
Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>

Ian Lance Taylor (Gerrit)

unread,
Jul 22, 2023, 1:29:36 AM7/22/23
to Gerrit Bot, qiulaidongfeng, goph...@pubsubhelper.golang.org, Ian Lance Taylor, Brad Fitzpatrick, Gopher Robot, golang-co...@googlegroups.com

Attention is currently required from: Brad Fitzpatrick.

Patch set 2:Run-TryBot +1

View Change

    To view, visit change 512155. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Icc2a4dbb1219b1d69dd10a900478957b0e975847
    Gerrit-Change-Number: 512155
    Gerrit-PatchSet: 2
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-CC: qiulaidongfeng <26454...@qq.com>
    Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Comment-Date: Sat, 22 Jul 2023 05:29:32 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes

    Gerrit Bot (Gerrit)

    unread,
    Jul 22, 2023, 1:48:59 AM7/22/23
    to qiulaidongfeng, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

    Attention is currently required from: Brad Fitzpatrick, Ian Lance Taylor.

    Gerrit Bot uploaded patch set #3 to this change.

    View Change

    The following approvals got outdated and were removed: Run-TryBot+1 by Ian Lance Taylor, TryBot-Result-1 by Gopher Robot

    os/exec: fix GOOS=windows,Cmd.Run always calls LookPath before returning

    Follow up on CL 511458, see https://go-review.googlesource.com/c/go/+/511458/2..4/src/cmd/go/main.go#b270 .

    Fixes #36768

    Change-Id: Icc2a4dbb1219b1d69dd10a900478957b0e975847

    Change-Id: Icc2a4dbb1219b1d69dd10a900478957b0e975847
    GitHub-Last-Rev: ad2b4838e2964dfe7fea1f3c223a871dca1b53d1

    GitHub-Pull-Request: golang/go#61517
    ---
    M src/os/exec/exec.go
    M src/os/exec/lp_plan9.go
    M src/os/exec/lp_unix.go
    M src/os/exec/lp_wasm.go
    M src/os/exec/lp_windows.go
    5 files changed, 30 insertions(+), 0 deletions(-)

    To view, visit change 512155. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-MessageType: newpatchset
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Icc2a4dbb1219b1d69dd10a900478957b0e975847
    Gerrit-Change-Number: 512155
    Gerrit-PatchSet: 3
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Reviewer: Gopher Robot <go...@golang.org>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-CC: qiulaidongfeng <26454...@qq.com>
    Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>

    qiulaidongfeng (Gerrit)

    unread,
    Jul 22, 2023, 1:49:41 AM7/22/23
    to Gerrit Bot, goph...@pubsubhelper.golang.org, Gopher Robot, Ian Lance Taylor, Brad Fitzpatrick, golang-co...@googlegroups.com

    Attention is currently required from: Brad Fitzpatrick, Ian Lance Taylor.

    View Change

    1 comment:

    To view, visit change 512155. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Icc2a4dbb1219b1d69dd10a900478957b0e975847
    Gerrit-Change-Number: 512155
    Gerrit-PatchSet: 3
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Reviewer: Gopher Robot <go...@golang.org>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-CC: qiulaidongfeng <26454...@qq.com>
    Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
    Gerrit-Comment-Date: Sat, 22 Jul 2023 05:49:37 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Gopher Robot <go...@golang.org>

    Bryan Mills (Gerrit)

    unread,
    Jul 24, 2023, 4:04:24 PM7/24/23
    to Gerrit Bot, qiulaidongfeng, goph...@pubsubhelper.golang.org, Bryan Mills, Gopher Robot, Ian Lance Taylor, Brad Fitzpatrick, golang-co...@googlegroups.com

    Attention is currently required from: Brad Fitzpatrick, Ian Lance Taylor.

    View Change

    4 comments:

    • Commit Message:

      • Patch Set #3, Line 7: os/exec: fix GOOS=windows,Cmd.Run always calls LookPath before returning

        ```suggestion
        os/exec: avoid calling LookPath in cmd.Start for resolved paths
        ```

      • Patch Set #3, Line 11: Fixes #36768

        ```suggestion
        For #36768.
        ```

        (This change by itself doesn't eliminate the `os.Stat` calls — it just avoids additional `Stat` calls if we cache the `LookPath` calls on the caller side.)

    • File src/os/exec/exec.go:

      • Patch Set #3, Line 600: exts := pathExt()

        It would be nice to avoid a second call to (and allocation in) `pathExt` in the `LookPath` calls in this function.

        I think probably the simplest way to do that is to move the definition of `lookExtensions` into `lp_windows.go`, and provide a `lookExtensions` implementation for the other platforms that just passes the path through:

        ```
        // lookExtensions is a no-op on non-Windows platforms, since
        // they do not restrict executables to specific extensions.
        func lookExtensions(path, dir string) (string, error) {
        return path, nil
        }
        ```
        Then the call site within `Cmd.Start` simplifies to:
        ```
        c.Path, c.Err = lookExtensions(c.Path, c.Dir)
        if c.Err != nil {
        return c.Err
        }
        ```

        and we don't need per-OS implementations of `pathExt`, which is really only ever called on Windows.

        The Windows version of `lookExtensions` could then call the unexported `lookPath` directly:

        ```go
        func lookExtensions(path, dir string) (string, error) {

      • if filepath.Base(path) == path {
        path = "." + string(filepath.Separator) + path
        }
      • 	exts := pathExt()

        if dir == "" {
        return lookPath(path, exts)
        }
        if filepath.VolumeName(path) != "" {
        return lookPath(path, exts)
        }
        … // and so on.
        }
        ```
    • File src/os/exec/lp_windows.go:

    To view, visit change 512155. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Icc2a4dbb1219b1d69dd10a900478957b0e975847
    Gerrit-Change-Number: 512155
    Gerrit-PatchSet: 3
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Reviewer: Gopher Robot <go...@golang.org>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-CC: Bryan Mills <bcm...@google.com>
    Gerrit-CC: qiulaidongfeng <26454...@qq.com>
    Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
    Gerrit-Comment-Date: Mon, 24 Jul 2023 20:04:21 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No

    Gerrit Bot (Gerrit)

    unread,
    Jul 24, 2023, 8:47:11 PM7/24/23
    to qiulaidongfeng, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

    Attention is currently required from: Brad Fitzpatrick, Ian Lance Taylor.

    Gerrit Bot uploaded patch set #4 to this change.

    View Change

    os/exec: avoid calling LookPath in cmd.Start for resolved paths
    For #36768.


    Change-Id: Icc2a4dbb1219b1d69dd10a900478957b0e975847

    Change-Id: Icc2a4dbb1219b1d69dd10a900478957b0e975847
    GitHub-Last-Rev: ad2b4838e2964dfe7fea1f3c223a871dca1b53d1
    GitHub-Pull-Request: golang/go#61517
    ---
    M src/os/exec/exec.go
    M src/os/exec/lp_plan9.go
    M src/os/exec/lp_unix.go
    M src/os/exec/lp_wasm.go
    M src/os/exec/lp_windows.go
    5 files changed, 30 insertions(+), 0 deletions(-)

    To view, visit change 512155. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-MessageType: newpatchset
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Icc2a4dbb1219b1d69dd10a900478957b0e975847
    Gerrit-Change-Number: 512155
    Gerrit-PatchSet: 4

    Gerrit Bot (Gerrit)

    unread,
    Jul 24, 2023, 9:19:42 PM7/24/23
    to qiulaidongfeng, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

    Attention is currently required from: Brad Fitzpatrick, Ian Lance Taylor.

    Gerrit Bot uploaded patch set #5 to this change.

    View Change

    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
    ---
    M src/os/exec/exec.go
    M src/os/exec/lp_plan9.go
    M src/os/exec/lp_unix.go
    M src/os/exec/lp_wasm.go
    M src/os/exec/lp_windows.go
    5 files changed, 65 insertions(+), 32 deletions(-)

    To view, visit change 512155. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-MessageType: newpatchset
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Icc2a4dbb1219b1d69dd10a900478957b0e975847
    Gerrit-Change-Number: 512155
    Gerrit-PatchSet: 5

    qiulaidongfeng (Gerrit)

    unread,
    Jul 24, 2023, 9:23:55 PM7/24/23
    to Gerrit Bot, goph...@pubsubhelper.golang.org, Bryan Mills, Gopher Robot, Ian Lance Taylor, Brad Fitzpatrick, golang-co...@googlegroups.com

    Attention is currently required from: Brad Fitzpatrick, Bryan Mills, Ian Lance Taylor.

    View Change

    4 comments:

    • Commit Message:

      • ```suggestion […]

        Done.

      • ```suggestion […]

        Done.

    • File src/os/exec/exec.go:

      • It would be nice to avoid a second call to (and allocation in) `pathExt` in the `LookPath` calls in […]

        Done.

    • File src/os/exec/lp_windows.go:

      • Done.

    To view, visit change 512155. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Icc2a4dbb1219b1d69dd10a900478957b0e975847
    Gerrit-Change-Number: 512155
    Gerrit-PatchSet: 5
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Reviewer: Gopher Robot <go...@golang.org>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-CC: Bryan Mills <bcm...@google.com>
    Gerrit-CC: qiulaidongfeng <26454...@qq.com>
    Gerrit-Attention: Bryan Mills <bcm...@google.com>
    Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
    Gerrit-Comment-Date: Tue, 25 Jul 2023 01:23:50 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Bryan Mills <bcm...@google.com>

    Bryan Mills (Gerrit)

    unread,
    Jul 25, 2023, 4:43:10 PM7/25/23
    to Gerrit Bot, qiulaidongfeng, goph...@pubsubhelper.golang.org, Bryan Mills, Quim Muntal, Alex Brainman, Gopher Robot, Ian Lance Taylor, Brad Fitzpatrick, golang-co...@googlegroups.com

    Attention is currently required from: Brad Fitzpatrick, Ian Lance Taylor, qiulaidongfeng.

    Patch set 5:Run-TryBot +1Auto-Submit +1Code-Review +2

    View Change

    6 comments:

    • Commit Message:

      • Done.

        Please remember to mark comment threads in Gerrit as resolved when they are done.

      • Done.

        Acknowledged

    • Patchset:

    • Patchset:

    • File src/os/exec/exec.go:

      • Done.

        Acknowledged

    • File src/os/exec/lp_windows.go:

      • Done.

        Acknowledged

    To view, visit change 512155. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Icc2a4dbb1219b1d69dd10a900478957b0e975847
    Gerrit-Change-Number: 512155
    Gerrit-PatchSet: 5
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Reviewer: Bryan Mills <bcm...@google.com>
    Gerrit-Reviewer: Gopher Robot <go...@golang.org>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
    Gerrit-CC: Alex Brainman <alex.b...@gmail.com>
    Gerrit-CC: Quim Muntal <quimm...@gmail.com>
    Gerrit-CC: qiulaidongfeng <26454...@qq.com>
    Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
    Gerrit-Attention: qiulaidongfeng <26454...@qq.com>
    Gerrit-Comment-Date: Tue, 25 Jul 2023 20:43:06 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: Yes
    Comment-In-Reply-To: Bryan Mills <bcm...@google.com>
    Comment-In-Reply-To: Gopher Robot <go...@golang.org>
    Comment-In-Reply-To: qiulaidongfeng <26454...@qq.com>

    Matthew Dempsky (Gerrit)

    unread,
    Jul 26, 2023, 7:13:21 AM7/26/23
    to Gerrit Bot, qiulaidongfeng, goph...@pubsubhelper.golang.org, Gopher Robot, Bryan Mills, Quim Muntal, Alex Brainman, Ian Lance Taylor, Brad Fitzpatrick, golang-co...@googlegroups.com

    Attention is currently required from: Brad Fitzpatrick, Ian Lance Taylor, qiulaidongfeng.

    Patch set 5:Code-Review +1

    View Change

      To view, visit change 512155. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: Icc2a4dbb1219b1d69dd10a900478957b0e975847
      Gerrit-Change-Number: 512155
      Gerrit-PatchSet: 5
      Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
      Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-Reviewer: Bryan Mills <bcm...@google.com>
      Gerrit-Reviewer: Gopher Robot <go...@golang.org>
      Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
      Gerrit-Reviewer: Matthew Dempsky <mdem...@google.com>
      Gerrit-CC: Alex Brainman <alex.b...@gmail.com>
      Gerrit-CC: Quim Muntal <quimm...@gmail.com>
      Gerrit-CC: qiulaidongfeng <26454...@qq.com>
      Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
      Gerrit-Attention: qiulaidongfeng <26454...@qq.com>
      Gerrit-Comment-Date: Wed, 26 Jul 2023 11:13:17 +0000
      Gerrit-HasComments: No
      Gerrit-Has-Labels: Yes

      Gopher Robot (Gerrit)

      unread,
      Jul 26, 2023, 7:13:41 AM7/26/23
      to Gerrit Bot, qiulaidongfeng, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Matthew Dempsky, Bryan Mills, Quim Muntal, Alex Brainman, Ian Lance Taylor, Brad Fitzpatrick, golang-co...@googlegroups.com

      Gopher Robot submitted this change.

      View Change

      Approvals: Bryan Mills: Looks good to me, approved; Run TryBots; Automatically submit change Gopher Robot: TryBots succeeded Matthew Dempsky: Looks good to me, but someone else must approve
      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 <bcm...@google.com>
      TryBot-Result: Gopher Robot <go...@golang.org>
      Reviewed-by: Matthew Dempsky <mdem...@google.com>
      Reviewed-by: Bryan Mills <bcm...@google.com>
      Run-TryBot: Bryan Mills <bcm...@google.com>

      ---
      M src/os/exec/exec.go
      M src/os/exec/lp_plan9.go
      M src/os/exec/lp_unix.go
      M src/os/exec/lp_wasm.go
      M src/os/exec/lp_windows.go
      5 files changed, 65 insertions(+), 32 deletions(-)

      
      
      diff --git a/src/os/exec/exec.go b/src/os/exec/exec.go
      index 138be29..a23d1c4 100644
      --- a/src/os/exec/exec.go
      +++ b/src/os/exec/exec.go
      @@ -590,32 +590,6 @@
      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 @@
      }
      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")
      }
      diff --git a/src/os/exec/lp_plan9.go b/src/os/exec/lp_plan9.go
      index 9344b14..dffdbac 100644
      --- a/src/os/exec/lp_plan9.go
      +++ b/src/os/exec/lp_plan9.go
      @@ -64,3 +64,9 @@
      }
      return "", &Error{file, ErrNotFound}
      }
      +
      +// lookExtensions is a no-op on non-Windows platforms, since
      +// they do not restrict executables to specific extensions.
      +func lookExtensions(path, dir string) (string, error) {

      + return path, nil
      +}
      diff --git a/src/os/exec/lp_unix.go b/src/os/exec/lp_unix.go
      index fd2c6ef..3787132 100644
      --- a/src/os/exec/lp_unix.go
      +++ b/src/os/exec/lp_unix.go
      @@ -80,3 +80,9 @@
      }
      return "", &Error{file, ErrNotFound}
      }
      +
      +// lookExtensions is a no-op on non-Windows platforms, since
      +// they do not restrict executables to specific extensions.
      +func lookExtensions(path, dir string) (string, error) {

      + return path, nil
      +}
      diff --git a/src/os/exec/lp_wasm.go b/src/os/exec/lp_wasm.go
      index f2c8e9c..3c81904 100644
      --- a/src/os/exec/lp_wasm.go
      +++ b/src/os/exec/lp_wasm.go
      @@ -21,3 +21,9 @@
      // Wasm can not execute processes, so act as if there are no executables at all.
      return "", &Error{file, ErrNotFound}
      }
      +
      +// lookExtensions is a no-op on non-Windows platforms, since
      +// they do not restrict executables to specific extensions.
      +func lookExtensions(path, dir string) (string, error) {

      + return path, nil
      +}
      diff --git a/src/os/exec/lp_windows.go b/src/os/exec/lp_windows.go
      index 066d38d..7f13347 100644
      --- a/src/os/exec/lp_windows.go
      +++ b/src/os/exec/lp_windows.go
      @@ -63,6 +63,45 @@

      // As of Go 1.19, LookPath will instead return that path along with an error satisfying
      // errors.Is(err, ErrDot). See the package documentation for more details.
      func LookPath(file string) (string, error) {
      + return lookPath(file, pathExt())
      +}
      +
      +// 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
      + }

      + exts := pathExt()
      + if ext := filepath.Ext(path); ext != "" {
      + for _, e := range exts {
      + if strings.EqualFold(ext, e) {
      + // Assume that path has already been resolved.
      + return path, nil
      + }
      + }
      + }
      +	if dir == "" {
      + return lookPath(path, exts)
      + }
      + if filepath.VolumeName(path) != "" {
      + return lookPath(path, exts)
      + }
      + if len(path) > 1 && os.IsPathSeparator(path[0]) {
      + return lookPath(path, exts)
      + }
      + dirandpath := filepath.Join(dir, path)
      + // We assume that LookPath will only add file extension.
      + lp, err := lookPath(dirandpath, exts)
      + if err != nil {
      + return "", err
      + }
      + ext := strings.TrimPrefix(lp, dirandpath)
      + return path + ext, nil

      +}
      +
      +func pathExt() []string {
      var exts []string
      x := os.Getenv(`PATHEXT`)
      if x != "" {
      @@ -78,7 +117,11 @@

      } else {
      exts = []string{".com", ".exe", ".bat", ".cmd"}
      }
      + return exts
      +}

      +// lookPath implements LookPath for the given PATHEXT list.
      +func lookPath(file string, exts []string) (string, error) {
      if strings.ContainsAny(file, `:\/`) {
      f, err := findExecutable(file, exts)
      if err == nil {

      To view, visit change 512155. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-MessageType: merged
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: Icc2a4dbb1219b1d69dd10a900478957b0e975847
      Gerrit-Change-Number: 512155
      Gerrit-PatchSet: 6

      Alex Brainman (Gerrit)

      unread,
      Jul 29, 2023, 4:07:49 AM7/29/23
      to Gerrit Bot, Gopher Robot, qiulaidongfeng, goph...@pubsubhelper.golang.org, Matthew Dempsky, Bryan Mills, Quim Muntal, Ian Lance Taylor, Brad Fitzpatrick, golang-co...@googlegroups.com

      Patch set 6:Code-Review +2

      View Change

      1 comment:

      To view, visit change 512155. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: Icc2a4dbb1219b1d69dd10a900478957b0e975847
      Gerrit-Change-Number: 512155
      Gerrit-PatchSet: 6
      Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
      Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
      Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-Reviewer: Bryan Mills <bcm...@google.com>
      Gerrit-Reviewer: Gopher Robot <go...@golang.org>
      Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
      Gerrit-Reviewer: Matthew Dempsky <mdem...@google.com>
      Gerrit-CC: Quim Muntal <quimm...@gmail.com>
      Gerrit-CC: qiulaidongfeng <26454...@qq.com>
      Gerrit-Comment-Date: Sat, 29 Jul 2023 08:07:41 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: Yes

      Ian Lance Taylor (Gerrit)

      unread,
      Sep 11, 2023, 8:07:59 PM9/11/23
      to Gerrit Bot, Gopher Robot, qiulaidongfeng, goph...@pubsubhelper.golang.org, Alex Brainman, Matthew Dempsky, Bryan Mills, Quim Muntal, Ian Lance Taylor, Brad Fitzpatrick, golang-co...@googlegroups.com

      Ian Lance Taylor has created a revert of this change.

      View Change

      To view, visit change 512155. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-MessageType: revert

      Will Drakus (Gerrit)

      unread,
      Jun 8, 2024, 10:17:11 AM6/8/24
      to Gerrit Bot, Gopher Robot, qiu laidongfeng2, goph...@pubsubhelper.golang.org, Alex Brainman, Matthew Dempsky, Quim Muntal, Ian Lance Taylor, Brad Fitzpatrick, golang-co...@googlegroups.com

      Will Drakus added 1 comment

      Patchset-level comments
      File-level comment, Patchset 6 (Latest):
      Will Drakus . resolved

      Hello I’m new here

      Open in Gerrit

      Related details

      Attention set is empty
      Submit Requirements:
      • requirement satisfiedCode-Review
      • requirement satisfiedNo-Holds
      • requirement satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: Icc2a4dbb1219b1d69dd10a900478957b0e975847
      Gerrit-Change-Number: 512155
      Gerrit-PatchSet: 6
      Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
      Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
      Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-Reviewer: Bryan Mills <bcm...@google.com>
      Gerrit-Reviewer: Gopher Robot <go...@golang.org>
      Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
      Gerrit-Reviewer: Matthew Dempsky <mdem...@google.com>
      Gerrit-CC: Quim Muntal <quimm...@gmail.com>
      Gerrit-CC: Will Drakus <sushi...@gmail.com>
      Gerrit-CC: qiu laidongfeng2 <26454...@qq.com>
      Gerrit-Comment-Date: Sat, 08 Jun 2024 14:17:03 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      satisfied_requirement
      open
      diffy
      Reply all
      Reply to author
      Forward
      0 new messages