mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
If $HOME is not set, return homedir from /etc/passwd
Docker-DCO-1.1-Signed-off-by: Dan Walsh <dwalsh@redhat.com> (github: rhatdan)
This commit is contained in:
parent
c5af44e6d0
commit
42aec0c771
1 changed files with 9 additions and 1 deletions
|
@ -3,6 +3,8 @@ package homedir
|
|||
import (
|
||||
"os"
|
||||
"runtime"
|
||||
|
||||
"github.com/docker/libcontainer/user"
|
||||
)
|
||||
|
||||
// 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.
|
||||
// Returned path should be used with "path/filepath" to form new paths.
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue