From 0586d52a00d035dcd8272ecb547c931dd10547a4 Mon Sep 17 00:00:00 2001 From: Dan Walsh Date: Tue, 10 Mar 2015 09:55:55 -0400 Subject: [PATCH] If $HOME is not set, return homedir from /etc/passwd Docker-DCO-1.1-Signed-off-by: Dan Walsh (github: rhatdan) --- homedir/homedir.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/homedir/homedir.go b/homedir/homedir.go index 3ffb297..61137a8 100644 --- a/homedir/homedir.go +++ b/homedir/homedir.go @@ -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