瀏覽代碼

pkg/homedir: use os.UserHomeDir()

Use os.UserHomeDir() instead of writing our own, but keep the fallback
on Linux.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 2 年之前
父節點
當前提交
0aca7f2a0d
共有 2 個文件被更改,包括 3 次插入2 次删除
  1. 1 1
      pkg/homedir/homedir_unix.go
  2. 2 1
      pkg/homedir/homedir_windows.go

+ 1 - 1
pkg/homedir/homedir_unix.go

@@ -22,7 +22,7 @@ func Key() string {
 //
 // If needing to do nss lookups, do not disable cgo or set osusergo.
 func Get() string {
-	home := os.Getenv(Key())
+	home, _ := os.UserHomeDir()
 	if home == "" {
 		if u, err := user.Current(); err == nil {
 			return u.HomeDir

+ 2 - 1
pkg/homedir/homedir_windows.go

@@ -14,7 +14,8 @@ 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.UserHomeDir()
+	return home
 }
 
 // GetShortcutString returns the string that is shortcut to user's home directory