From 8a30653ed5276179cc4dc0978af13ea2068c7d4e Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 24 Oct 2019 16:11:04 +0200 Subject: [PATCH] config: don't call homedir on init() This patch changes the package to lazily obtain the user's home- directory on first use, instead of when initializing the package. Signed-off-by: Sebastiaan van Stijn --- cli/config/config.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/cli/config/config.go b/cli/config/config.go index 6e4d73dfad..b81626664a 100644 --- a/cli/config/config.go +++ b/cli/config/config.go @@ -6,6 +6,7 @@ import ( "os" "path/filepath" "strings" + "sync" "github.com/docker/cli/cli/config/configfile" "github.com/docker/cli/cli/config/credentials" @@ -23,10 +24,15 @@ const ( ) var ( - configDir = os.Getenv("DOCKER_CONFIG") + initConfigDir sync.Once + configDir string ) -func init() { +func setConfigDir() { + if configDir != "" { + return + } + configDir = os.Getenv("DOCKER_CONFIG") if configDir == "" { configDir = filepath.Join(homedir.Get(), configFileDir) } @@ -34,6 +40,7 @@ func init() { // Dir returns the directory the configuration file is stored in func Dir() string { + initConfigDir.Do(setConfigDir) return configDir }