Skip to content

Commit 44f0084

Browse files
n
Change-Id: Ie084691584b08e17944079f182cc353a98191780
1 parent d82fe30 commit 44f0084

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/os/exec/exec.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,9 @@ type Cmd struct {
333333
// and https://go.dev/issue/43724 for more context.
334334
lookPathErr error
335335

336-
// calledLookExtensions indicates whether
337-
// lookExtensions has been called in Cmd.Command.
338-
calledLookExtensions bool
336+
// cacheLookExtensions cache the result of calling lookExtensions,
337+
// use it only on windows.
338+
cacheLookExtensions string
339339
}
340340

341341
// A ctxResult reports the result of watching the Context associated with a
@@ -440,11 +440,8 @@ func Command(name string, arg ...string) *Cmd {
440440
// Note that we cannot add an extension here for relative paths, because
441441
// cmd.Dir may be set after we return from this function and that may cause
442442
// the command to resolve to a different extension.
443-
cmd.calledLookExtensions = true
444443
lp, err := lookExtensions(name, "")
445-
if lp != "" {
446-
cmd.Path = lp
447-
}
444+
cmd.cacheLookExtensions = lp
448445
if err != nil {
449446
cmd.Err = err
450447
}
@@ -646,7 +643,10 @@ func (c *Cmd) Start() error {
646643
return c.Err
647644
}
648645
lp := c.Path
649-
if runtime.GOOS == "windows" && !c.calledLookExtensions {
646+
if c.cacheLookExtensions == "" {
647+
lp = c.cacheLookExtensions
648+
}
649+
if runtime.GOOS == "windows" && c.cacheLookExtensions == "" {
650650
// If c.Path is relative, we had to wait until now
651651
// to resolve it in case c.Dir was changed.
652652
// (If it is absolute, we already resolved its extension in Command

0 commit comments

Comments
 (0)