From 270daf31ea007147e1b04770e501688472750a7e Mon Sep 17 00:00:00 2001 From: Tim Scheuermann Date: Fri, 11 Oct 2019 23:36:21 +0200 Subject: [PATCH] Revert "Call the os.UserHomeDir in Home" This reverts commit d3b6bc503a583bd2d841a9fba439b9f7e4056ff0. --- utils/homedir.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/utils/homedir.go b/utils/homedir.go index 5a5d0fd2..9a67a7b0 100644 --- a/utils/homedir.go +++ b/utils/homedir.go @@ -6,7 +6,7 @@ package utils import ( "errors" - "os" + "os/user" "path/filepath" ) @@ -37,5 +37,14 @@ func ExpandHomeDir(path string) (string, error) { // Home returns the home directory for the executing user. // An error is returned if a home directory cannot be detected. func Home() (string, error) { - return os.UserHomeDir() + currentUser, err := user.Current() + if err != nil { + return "", err + } + + if currentUser.HomeDir == "" { + return "", errors.New("cannot find user-specific home dir") + } + + return currentUser.HomeDir, nil }