Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.

Commit 98b8652

Browse files
committed
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 <github@gone.nl> (cherry picked from commit 8a30653ed5276179cc4dc0978af13ea2068c7d4e) Signed-off-by: Sebastiaan van Stijn <github@gone.nl> Upstream-commit: 8434242c743c051a56381c280eeec7518a9662dd Component: cli
1 parent 50d22f0 commit 98b8652

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

components/cli/cli/config/config.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77
"path/filepath"
88
"strings"
9+
"sync"
910

1011
"github.com/docker/cli/cli/config/configfile"
1112
"github.com/docker/cli/cli/config/credentials"
@@ -23,17 +24,23 @@ const (
2324
)
2425

2526
var (
26-
configDir = os.Getenv("DOCKER_CONFIG")
27+
initConfigDir sync.Once
28+
configDir string
2729
)
2830

29-
func init() {
31+
func setConfigDir() {
32+
if configDir != "" {
33+
return
34+
}
35+
configDir = os.Getenv("DOCKER_CONFIG")
3036
if configDir == "" {
3137
configDir = filepath.Join(homedir.Get(), configFileDir)
3238
}
3339
}
3440

3541
// Dir returns the directory the configuration file is stored in
3642
func Dir() string {
43+
initConfigDir.Do(setConfigDir)
3744
return configDir
3845
}
3946

0 commit comments

Comments
 (0)