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

Commit 4911428

Browse files
Merge pull request #2508 from thaJeztah/19.03_backport_config_dont_init
[19.03 backport] config: don't call homedir on init() Upstream-commit: 1705e47cdf5a5f66a565278b2a13377a3a7f7d3c Component: cli
2 parents 1e21179 + 98b8652 commit 4911428

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)