From b8ebf7be046401911c9138ed35c8b8209c91225b Mon Sep 17 00:00:00 2001 From: Justin Cormack Date: Mon, 10 Jul 2017 14:10:43 +0100 Subject: [PATCH] Split homedir files by operating system libcontainer/user does not build at all on Windows any more, and this was breaking the client on Windows with upstream `runc`. As these functions are not used anyway, just split out and stop checking `runtime`. Signed-off-by: Justin Cormack Upstream-commit: b7bd959294b5dc5b6e18b3fed5dde18f4f7f1d20 Component: engine --- .../homedir/{homedir.go => homedir_unix.go} | 11 +++------ .../engine/pkg/homedir/homedir_windows.go | 24 +++++++++++++++++++ 2 files changed, 27 insertions(+), 8 deletions(-) rename components/engine/pkg/homedir/{homedir.go => homedir_unix.go} (77%) create mode 100644 components/engine/pkg/homedir/homedir_windows.go diff --git a/components/engine/pkg/homedir/homedir.go b/components/engine/pkg/homedir/homedir_unix.go similarity index 77% rename from components/engine/pkg/homedir/homedir.go rename to components/engine/pkg/homedir/homedir_unix.go index 8154e83f0c..f2a20ea8f8 100644 --- a/components/engine/pkg/homedir/homedir.go +++ b/components/engine/pkg/homedir/homedir_unix.go @@ -1,8 +1,9 @@ +// +build !windows + package homedir import ( "os" - "runtime" "github.com/opencontainers/runc/libcontainer/user" ) @@ -10,9 +11,6 @@ import ( // Key returns the env var name for the user's home dir based on // the platform being run on func Key() string { - if runtime.GOOS == "windows" { - return "USERPROFILE" - } return "HOME" } @@ -21,7 +19,7 @@ func Key() string { // Returned path should be used with "path/filepath" to form new paths. func Get() string { home := os.Getenv(Key()) - if home == "" && runtime.GOOS != "windows" { + if home == "" { if u, err := user.CurrentUser(); err == nil { return u.Home } @@ -32,8 +30,5 @@ func Get() string { // GetShortcutString returns the string that is shortcut to user's home directory // in the native shell of the platform running on. func GetShortcutString() string { - if runtime.GOOS == "windows" { - return "%USERPROFILE%" // be careful while using in format functions - } return "~" } diff --git a/components/engine/pkg/homedir/homedir_windows.go b/components/engine/pkg/homedir/homedir_windows.go new file mode 100644 index 0000000000..fafdb2bbf9 --- /dev/null +++ b/components/engine/pkg/homedir/homedir_windows.go @@ -0,0 +1,24 @@ +package homedir + +import ( + "os" +) + +// Key returns the env var name for the user's home dir based on +// the platform being run on +func Key() string { + return "USERPROFILE" +} + +// Get returns the home directory of the current user with the help of +// 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()) +} + +// GetShortcutString returns the string that is shortcut to user's home directory +// in the native shell of the platform running on. +func GetShortcutString() string { + return "%USERPROFILE%" // be careful while using in format functions +}