@@ -19,49 +19,22 @@ const (
1919 // ConfigFileName is the name of config file
2020 ConfigFileName = "config.json"
2121 configFileDir = ".docker"
22- oldConfigfile = ".dockercfg" // Deprecated: remove once we stop printing deprecation warning
2322 contextsDir = "contexts"
2423)
2524
2625var (
2726 initConfigDir = new (sync.Once )
2827 configDir string
29- homeDir string
3028)
3129
32- // resetHomeDir is used in testing to reset the "homeDir" package variable to
33- // force re-lookup of the home directory between tests.
34- func resetHomeDir () {
35- homeDir = ""
36- }
37-
38- func getHomeDir () string {
39- if homeDir == "" {
40- homeDir = homedir .Get ()
41- }
42- return homeDir
43- }
44-
45- // resetConfigDir is used in testing to reset the "configDir" package variable
46- // and its sync.Once to force re-lookup between tests.
47- func resetConfigDir () {
48- configDir = ""
49- initConfigDir = new (sync.Once )
50- }
51-
52- func setConfigDir () {
53- if configDir != "" {
54- return
55- }
56- configDir = os .Getenv ("DOCKER_CONFIG" )
57- if configDir == "" {
58- configDir = filepath .Join (getHomeDir (), configFileDir )
59- }
60- }
61-
6230// Dir returns the directory the configuration file is stored in
6331func Dir () string {
64- initConfigDir .Do (setConfigDir )
32+ initConfigDir .Do (func () {
33+ configDir = os .Getenv ("DOCKER_CONFIG" )
34+ if configDir == "" {
35+ configDir = filepath .Join (homedir .Get (), configFileDir )
36+ }
37+ })
6538 return configDir
6639}
6740
@@ -96,55 +69,43 @@ func LoadFromReader(configData io.Reader) (*configfile.ConfigFile, error) {
9669
9770// Load reads the configuration files in the given directory, and sets up
9871// the auth config information and returns values.
99- // FIXME: use the internal golang config parser
10072func Load (configDir string ) (* configfile.ConfigFile , error ) {
101- cfg , _ , err := load (configDir )
102- return cfg , err
103- }
104-
105- // TODO remove this temporary hack, which is used to warn about the deprecated ~/.dockercfg file
106- // so we can remove the bool return value and collapse this back into `Load`
107- func load (configDir string ) (* configfile.ConfigFile , bool , error ) {
108- printLegacyFileWarning := false
109-
11073 if configDir == "" {
11174 configDir = Dir ()
11275 }
76+ return load (configDir )
77+ }
11378
79+ func load (configDir string ) (* configfile.ConfigFile , error ) {
11480 filename := filepath .Join (configDir , ConfigFileName )
11581 configFile := configfile .New (filename )
11682
117- // Try happy path first - latest config file
118- if file , err := os .Open (filename ); err == nil {
119- defer file .Close ()
120- err = configFile .LoadFromReader (file )
121- if err != nil {
122- err = errors .Wrap (err , filename )
83+ file , err := os .Open (filename )
84+ if err != nil {
85+ if os .IsNotExist (err ) {
86+ //
87+ // if file is there but we can't stat it for any reason other
88+ // than it doesn't exist then stop
89+ return configFile , nil
12390 }
124- return configFile , printLegacyFileWarning , err
125- } else if ! os .IsNotExist (err ) {
12691 // if file is there but we can't stat it for any reason other
12792 // than it doesn't exist then stop
128- return configFile , printLegacyFileWarning , errors . Wrap ( err , filename )
93+ return configFile , nil
12994 }
130-
131- // Can't find latest config file so check for the old one
132- filename = filepath .Join (getHomeDir (), oldConfigfile )
133- if _ , err := os .Stat (filename ); err == nil {
134- printLegacyFileWarning = true
95+ defer file .Close ()
96+ err = configFile .LoadFromReader (file )
97+ if err != nil {
98+ err = errors .Wrap (err , filename )
13599 }
136- return configFile , printLegacyFileWarning , nil
100+ return configFile , err
137101}
138102
139103// LoadDefaultConfigFile attempts to load the default config file and returns
140104// an initialized ConfigFile struct if none is found.
141105func LoadDefaultConfigFile (stderr io.Writer ) * configfile.ConfigFile {
142- configFile , printLegacyFileWarning , err := load (Dir ())
106+ configFile , err := load (Dir ())
143107 if err != nil {
144- fmt .Fprintf (stderr , "WARNING: Error loading config file: %v\n " , err )
145- }
146- if printLegacyFileWarning {
147- _ , _ = fmt .Fprintln (stderr , "WARNING: Support for the legacy ~/.dockercfg configuration file and file-format has been removed and the configuration file will be ignored" )
108+ _ , _ = fmt .Fprintf (stderr , "WARNING: Error loading config file: %v\n " , err )
148109 }
149110 if ! configFile .ContainsAuth () {
150111 configFile .CredentialsStore = credentials .DetectDefaultStore (configFile .CredentialsStore )
0 commit comments