summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2023-05-23 19:19:49 +1000
committerGitHub <noreply@github.com>2023-05-23 19:19:49 +1000
commit1a4cf84b58762c2dbded967a0f718fd572a9f8cd (patch)
treee60c387127f332320d9188155f6ca61d5afc888f /pkg
parentec5075104afe0eaafe8ec99e6fbb69b982ae0229 (diff)
parentad72a1f5a30d8f4a438c491583c30ff778143854 (diff)
Merge pull request #2661 from jesseduffield/cache-binary-paths
Cache binary paths
Diffstat (limited to 'pkg')
-rw-r--r--pkg/secureexec/secureexec_windows.go20
1 files changed, 17 insertions, 3 deletions
diff --git a/pkg/secureexec/secureexec_windows.go b/pkg/secureexec/secureexec_windows.go
index 51e8634b4..ed4339cd3 100644
--- a/pkg/secureexec/secureexec_windows.go
+++ b/pkg/secureexec/secureexec_windows.go
@@ -21,11 +21,25 @@ import (
// you call `git status` from the command line directly but no harm in playing it
// safe.
+var pathCache = map[string]string{}
+
func Command(name string, args ...string) *exec.Cmd {
- bin, err := safeexec.LookPath(name)
+ path := getPath(name)
+
+ return exec.Command(path, args...)
+}
+
+func getPath(name string) string {
+ if path, ok := pathCache[name]; ok {
+ return path
+ }
+
+ path, err := safeexec.LookPath(name)
if err != nil {
- bin = name
+ pathCache[name] = name
+ return name
}
- return exec.Command(bin, args...)
+ pathCache[name] = path
+ return path
}