Docker-DCO-1.1-Signed-off-by: Dan Walsh <dwalsh@redhat.com> (github: rhatdan)
| ... | ... |
@@ -3,6 +3,8 @@ package homedir |
| 3 | 3 |
import ( |
| 4 | 4 |
"os" |
| 5 | 5 |
"runtime" |
| 6 |
+ |
|
| 7 |
+ "github.com/docker/libcontainer/user" |
|
| 6 | 8 |
) |
| 7 | 9 |
|
| 8 | 10 |
// Key returns the env var name for the user's home dir based on |
| ... | ... |
@@ -18,7 +20,13 @@ func Key() string {
|
| 18 | 18 |
// environment variables depending on the target operating system. |
| 19 | 19 |
// Returned path should be used with "path/filepath" to form new paths. |
| 20 | 20 |
func Get() string {
|
| 21 |
- return os.Getenv(Key()) |
|
| 21 |
+ home := os.Getenv(Key()) |
|
| 22 |
+ if home == "" && runtime.GOOS != "windows" {
|
|
| 23 |
+ if u, err := user.CurrentUser(); err == nil {
|
|
| 24 |
+ return u.Home |
|
| 25 |
+ } |
|
| 26 |
+ } |
|
| 27 |
+ return home |
|
| 22 | 28 |
} |
| 23 | 29 |
|
| 24 | 30 |
// GetShortcutString returns the string that is shortcut to user's home directory |