mirror of https://github.com/docker/docs.git
Merge pull request #11287 from rhatdan/homedir
If $HOME is not set, return homedir from /etc/passwd
This commit is contained in:
commit
d26e3cfd52
|
@ -3,6 +3,8 @@ package homedir
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
|
"github.com/docker/libcontainer/user"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Key returns the env var name for the user's home dir based on
|
// Key returns the env var name for the user's home dir based on
|
||||||
|
@ -18,7 +20,13 @@ func Key() string {
|
||||||
// environment variables depending on the target operating system.
|
// environment variables depending on the target operating system.
|
||||||
// Returned path should be used with "path/filepath" to form new paths.
|
// Returned path should be used with "path/filepath" to form new paths.
|
||||||
func Get() string {
|
func Get() string {
|
||||||
return os.Getenv(Key())
|
home := os.Getenv(Key())
|
||||||
|
if home == "" && runtime.GOOS != "windows" {
|
||||||
|
if u, err := user.CurrentUser(); err == nil {
|
||||||
|
return u.Home
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return home
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetShortcutString returns the string that is shortcut to user's home directory
|
// GetShortcutString returns the string that is shortcut to user's home directory
|
||||||
|
|
Loading…
Reference in New Issue