Browse Source

Merge pull request #20780 from runcom/revert-sudo-user

Revert sudo user
David Calavera 9 years ago
parent
commit
a5d98b82ea
3 changed files with 3 additions and 29 deletions
  1. 3 13
      cliconfig/config.go
  2. 0 3
      docs/reference/commandline/cli.md
  3. 0 13
      pkg/homedir/homedir.go

+ 3 - 13
cliconfig/config.go

@@ -17,6 +17,7 @@ import (
 const (
 const (
 	// ConfigFileName is the name of config file
 	// ConfigFileName is the name of config file
 	ConfigFileName = "config.json"
 	ConfigFileName = "config.json"
+	configFileDir  = ".docker"
 	oldConfigfile  = ".dockercfg"
 	oldConfigfile  = ".dockercfg"
 
 
 	// This constant is only used for really old config files when the
 	// This constant is only used for really old config files when the
@@ -29,20 +30,9 @@ var (
 	configDir = os.Getenv("DOCKER_CONFIG")
 	configDir = os.Getenv("DOCKER_CONFIG")
 )
 )
 
 
-func getDefaultConfigDir(confFile string) string {
-	confDir := filepath.Join(homedir.Get(), confFile)
-	// if the directory doesn't exist, maybe we called docker with sudo
-	if _, err := os.Stat(confDir); err != nil {
-		if os.IsNotExist(err) {
-			return filepath.Join(homedir.GetWithSudoUser(), confFile)
-		}
-	}
-	return confDir
-}
-
 func init() {
 func init() {
 	if configDir == "" {
 	if configDir == "" {
-		configDir = getDefaultConfigDir(".docker")
+		configDir = filepath.Join(homedir.Get(), configFileDir)
 	}
 	}
 }
 }
 
 
@@ -189,7 +179,7 @@ func Load(configDir string) (*ConfigFile, error) {
 	}
 	}
 
 
 	// Can't find latest config file so check for the old one
 	// Can't find latest config file so check for the old one
-	confFile := getDefaultConfigDir(oldConfigfile)
+	confFile := filepath.Join(homedir.Get(), oldConfigfile)
 	if _, err := os.Stat(confFile); err != nil {
 	if _, err := os.Stat(confFile); err != nil {
 		return &configFile, nil //missing file is not an error
 		return &configFile, nil //missing file is not an error
 	}
 	}

+ 0 - 3
docs/reference/commandline/cli.md

@@ -78,9 +78,6 @@ For example:
 Instructs Docker to use the configuration files in your `~/testconfigs/`
 Instructs Docker to use the configuration files in your `~/testconfigs/`
 directory when running the `ps` command.
 directory when running the `ps` command.
 
 
-> **Note**: If you run docker commands with `sudo`, Docker first looks for a configuration
-> file in `/root/.docker/`, before looking in `~/.docker/` for the user that did the sudo call.
-
 Docker manages most of the files in the configuration directory
 Docker manages most of the files in the configuration directory
 and you should not modify them. However, you *can modify* the
 and you should not modify them. However, you *can modify* the
 `config.json` file to control certain aspects of how the `docker`
 `config.json` file to control certain aspects of how the `docker`

+ 0 - 13
pkg/homedir/homedir.go

@@ -29,19 +29,6 @@ func Get() string {
 	return home
 	return home
 }
 }
 
 
-// GetWithSudoUser returns the home directory of the user who called sudo (if
-// available, retrieved from $SUDO_USER). It fallbacks to Get if any error occurs.
-// Returned path should be used with "path/filepath" to form new paths.
-func GetWithSudoUser() string {
-	sudoUser := os.Getenv("SUDO_USER")
-	if sudoUser != "" {
-		if user, err := user.LookupUser(sudoUser); err == nil {
-			return user.Home
-		}
-	}
-	return Get()
-}
-
 // GetShortcutString returns the string that is shortcut to user's home directory
 // GetShortcutString returns the string that is shortcut to user's home directory
 // in the native shell of the platform running on.
 // in the native shell of the platform running on.
 func GetShortcutString() string {
 func GetShortcutString() string {