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>
This commit is contained in:
Sebastiaan van Stijn 2023-06-20 15:14:56 +02:00
parent db381fb21b
commit 0aca7f2a0d
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
2 changed files with 3 additions and 2 deletions

View file

@ -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

View file

@ -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