From ce11b28d837a020ee8620cf22a31d6e52961d1c1 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 5 May 2023 21:10:18 +0200 Subject: [PATCH] cli/config/credentials: skip unneeded exec.LookPath() defaultCredentialsStore() on Linux does an exec.LookPath() for "pass", but if a custom credential-store is passed to DetectDefaultStore, the result of that won't be used. This patch changes the logic to return early if a custom credential-store is passed. Signed-off-by: Sebastiaan van Stijn --- cli/config/credentials/default_store.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/cli/config/credentials/default_store.go b/cli/config/credentials/default_store.go index 402235bff0..9378de48ef 100644 --- a/cli/config/credentials/default_store.go +++ b/cli/config/credentials/default_store.go @@ -5,17 +5,20 @@ import ( ) // DetectDefaultStore return the default credentials store for the platform if -// the store executable is available. +// no user-defined store is passed, and the store executable is available. func DetectDefaultStore(store string) string { - platformDefault := defaultCredentialsStore() - - // user defined or no default for platform - if store != "" || platformDefault == "" { + if store != "" { + // use user-defined return store } - if _, err := exec.LookPath(remoteCredentialsPrefix + platformDefault); err == nil { - return platformDefault + platformDefault := defaultCredentialsStore() + if platformDefault == "" { + return "" } - return "" + + if _, err := exec.LookPath(remoteCredentialsPrefix + platformDefault); err != nil { + return "" + } + return platformDefault }