mirror of https://github.com/docker/cli.git
Merge pull request #3264 from coryb/fix-data-race
fix innocuous data-race when config.Load called in parallel
This commit is contained in:
commit
48cbe0bfa1
|
@ -104,14 +104,18 @@ func LoadFromReader(configData io.Reader) (*configfile.ConfigFile, error) {
|
||||||
return &configFile, err
|
return &configFile, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO remove this temporary hack, which is used to warn about the deprecated ~/.dockercfg file
|
|
||||||
var printLegacyFileWarning bool
|
|
||||||
|
|
||||||
// Load reads the configuration files in the given directory, and sets up
|
// Load reads the configuration files in the given directory, and sets up
|
||||||
// the auth config information and returns values.
|
// the auth config information and returns values.
|
||||||
// FIXME: use the internal golang config parser
|
// FIXME: use the internal golang config parser
|
||||||
func Load(configDir string) (*configfile.ConfigFile, error) {
|
func Load(configDir string) (*configfile.ConfigFile, error) {
|
||||||
printLegacyFileWarning = false
|
cfg, _, err := load(configDir)
|
||||||
|
return cfg, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO remove this temporary hack, which is used to warn about the deprecated ~/.dockercfg file
|
||||||
|
// so we can remove the bool return value and collapse this back into `Load`
|
||||||
|
func load(configDir string) (*configfile.ConfigFile, bool, error) {
|
||||||
|
printLegacyFileWarning := false
|
||||||
|
|
||||||
if configDir == "" {
|
if configDir == "" {
|
||||||
configDir = Dir()
|
configDir = Dir()
|
||||||
|
@ -127,11 +131,11 @@ func Load(configDir string) (*configfile.ConfigFile, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, filename)
|
err = errors.Wrap(err, filename)
|
||||||
}
|
}
|
||||||
return configFile, err
|
return configFile, printLegacyFileWarning, err
|
||||||
} else if !os.IsNotExist(err) {
|
} else if !os.IsNotExist(err) {
|
||||||
// if file is there but we can't stat it for any reason other
|
// if file is there but we can't stat it for any reason other
|
||||||
// than it doesn't exist then stop
|
// than it doesn't exist then stop
|
||||||
return configFile, errors.Wrap(err, filename)
|
return configFile, printLegacyFileWarning, errors.Wrap(err, filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Can't find latest config file so check for the old one
|
// Can't find latest config file so check for the old one
|
||||||
|
@ -140,16 +144,16 @@ func Load(configDir string) (*configfile.ConfigFile, error) {
|
||||||
printLegacyFileWarning = true
|
printLegacyFileWarning = true
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
if err := configFile.LegacyLoadFromReader(file); err != nil {
|
if err := configFile.LegacyLoadFromReader(file); err != nil {
|
||||||
return configFile, errors.Wrap(err, filename)
|
return configFile, printLegacyFileWarning, errors.Wrap(err, filename)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return configFile, nil
|
return configFile, printLegacyFileWarning, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadDefaultConfigFile attempts to load the default config file and returns
|
// LoadDefaultConfigFile attempts to load the default config file and returns
|
||||||
// an initialized ConfigFile struct if none is found.
|
// an initialized ConfigFile struct if none is found.
|
||||||
func LoadDefaultConfigFile(stderr io.Writer) *configfile.ConfigFile {
|
func LoadDefaultConfigFile(stderr io.Writer) *configfile.ConfigFile {
|
||||||
configFile, err := Load(Dir())
|
configFile, printLegacyFileWarning, err := load(Dir())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(stderr, "WARNING: Error loading config file: %v\n", err)
|
fmt.Fprintf(stderr, "WARNING: Error loading config file: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue