summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2023-05-23 19:09:23 +1000
committerJesse Duffield <jessedduffield@gmail.com>2023-05-23 19:15:33 +1000
commitad72a1f5a30d8f4a438c491583c30ff778143854 (patch)
tree58b607536ee27079f6448c91937169f7a100f508 /pkg
parentb30ec538fb59ea0a0bb6a8a65456d433f3989075 (diff)
Cache binary paths
Turns out that with our secureexec package (which we only use on windows due to a windows security thing),
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
}