Browse code

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 <justin.cormack@docker.com>

Justin Cormack authored on 2017/07/10 22:10:43
Showing 3 changed files
1 1
deleted file mode 100644
... ...
@@ -1,39 +0,0 @@
1
-package homedir
2
-
3
-import (
4
-	"os"
5
-	"runtime"
6
-
7
-	"github.com/opencontainers/runc/libcontainer/user"
8
-)
9
-
10
-// Key returns the env var name for the user's home dir based on
11
-// the platform being run on
12
-func Key() string {
13
-	if runtime.GOOS == "windows" {
14
-		return "USERPROFILE"
15
-	}
16
-	return "HOME"
17
-}
18
-
19
-// Get returns the home directory of the current user with the help of
20
-// environment variables depending on the target operating system.
21
-// Returned path should be used with "path/filepath" to form new paths.
22
-func Get() string {
23
-	home := os.Getenv(Key())
24
-	if home == "" && runtime.GOOS != "windows" {
25
-		if u, err := user.CurrentUser(); err == nil {
26
-			return u.Home
27
-		}
28
-	}
29
-	return home
30
-}
31
-
32
-// GetShortcutString returns the string that is shortcut to user's home directory
33
-// in the native shell of the platform running on.
34
-func GetShortcutString() string {
35
-	if runtime.GOOS == "windows" {
36
-		return "%USERPROFILE%" // be careful while using in format functions
37
-	}
38
-	return "~"
39
-}
40 1
new file mode 100644
... ...
@@ -0,0 +1,34 @@
0
+// +build !windows
1
+
2
+package homedir
3
+
4
+import (
5
+	"os"
6
+
7
+	"github.com/opencontainers/runc/libcontainer/user"
8
+)
9
+
10
+// Key returns the env var name for the user's home dir based on
11
+// the platform being run on
12
+func Key() string {
13
+	return "HOME"
14
+}
15
+
16
+// Get returns the home directory of the current user with the help of
17
+// environment variables depending on the target operating system.
18
+// Returned path should be used with "path/filepath" to form new paths.
19
+func Get() string {
20
+	home := os.Getenv(Key())
21
+	if home == "" {
22
+		if u, err := user.CurrentUser(); err == nil {
23
+			return u.Home
24
+		}
25
+	}
26
+	return home
27
+}
28
+
29
+// GetShortcutString returns the string that is shortcut to user's home directory
30
+// in the native shell of the platform running on.
31
+func GetShortcutString() string {
32
+	return "~"
33
+}
0 34
new file mode 100644
... ...
@@ -0,0 +1,24 @@
0
+package homedir
1
+
2
+import (
3
+	"os"
4
+)
5
+
6
+// Key returns the env var name for the user's home dir based on
7
+// the platform being run on
8
+func Key() string {
9
+	return "USERPROFILE"
10
+}
11
+
12
+// Get returns the home directory of the current user with the help of
13
+// environment variables depending on the target operating system.
14
+// Returned path should be used with "path/filepath" to form new paths.
15
+func Get() string {
16
+	return os.Getenv(Key())
17
+}
18
+
19
+// GetShortcutString returns the string that is shortcut to user's home directory
20
+// in the native shell of the platform running on.
21
+func GetShortcutString() string {
22
+	return "%USERPROFILE%" // be careful while using in format functions
23
+}