Skip to content

Commit d141499

Browse files
egonelbregopherbot
authored andcommitted
cmd/toolstash: fix windows executable name handling
Change-Id: I1ff643fae4c48b4f68b452eb6881fca99832930c Reviewed-on: https://go-review.googlesource.com/c/tools/+/650915 Reviewed-by: Junyang Shao <[email protected]> Reviewed-by: Michael Pratt <[email protected]> Auto-Submit: Sean Liao <[email protected]> Commit-Queue: Sean Liao <[email protected]> Reviewed-by: Sean Liao <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 5f02a3e commit d141499

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

cmd/toolstash/main.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ func main() {
225225
return
226226
}
227227

228-
tool = cmd[0]
228+
tool = exeName(cmd[0])
229229
if i := strings.LastIndexAny(tool, `/\`); i >= 0 {
230230
tool = tool[i+1:]
231231
}
@@ -530,7 +530,7 @@ func runCmd(cmd []string, keepLog bool, logName string) (output []byte, err erro
530530
}()
531531
}
532532

533-
xcmd := exec.Command(cmd[0], cmd[1:]...)
533+
xcmd := exec.Command(exeName(cmd[0]), cmd[1:]...)
534534
if !keepLog {
535535
return xcmd.CombinedOutput()
536536
}
@@ -571,9 +571,10 @@ func save() {
571571
if !shouldSave(name) {
572572
continue
573573
}
574-
src := filepath.Join(binDir, name)
574+
bin := exeName(name)
575+
src := filepath.Join(binDir, bin)
575576
if _, err := os.Stat(src); err == nil {
576-
cp(src, filepath.Join(stashDir, name))
577+
cp(src, filepath.Join(stashDir, bin))
577578
}
578579
}
579580

@@ -641,3 +642,10 @@ func cp(src, dst string) {
641642
log.Fatal(err)
642643
}
643644
}
645+
646+
func exeName(name string) string {
647+
if runtime.GOOS == "windows" {
648+
return name + ".exe"
649+
}
650+
return name
651+
}

0 commit comments

Comments
 (0)