From ad72a1f5a30d8f4a438c491583c30ff778143854 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Tue, 23 May 2023 19:09:23 +1000 Subject: [PATCH] Cache binary paths Turns out that with our secureexec package (which we only use on windows due to a windows security thing), --- pkg/secureexec/secureexec_windows.go | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 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) - if err != nil { - bin = name + path := getPath(name) + + return exec.Command(path, args...) +} + +func getPath(name string) string { + if path, ok := pathCache[name]; ok { + return path } - return exec.Command(bin, args...) + path, err := safeexec.LookPath(name) + if err != nil { + pathCache[name] = name + return name + } + + pathCache[name] = path + return path }