Update getHomeDir() to use "os/user"

os.Getenv("HOME") doesn't work properly on Windows (and maybe other systems?) and the package "os/user" gives us a convenient way to find the home directory for every OS.
This commit is contained in:
filoozom 2014-03-02 16:07:12 +01:00
parent 192117dc11
commit 23593c3d20

11
main.go
View File

@ -11,6 +11,7 @@ import (
_ "net/http/pprof" _ "net/http/pprof"
"os" "os"
"os/exec" "os/exec"
"os/user"
"path" "path"
"runtime" "runtime"
"runtime/debug" "runtime/debug"
@ -561,9 +562,13 @@ func expandTilde(p string) string {
} }
func getHomeDir() string { func getHomeDir() string {
home := os.Getenv("HOME") usr, err := user.Current()
if home == "" { if err != nil {
fatalln(err)
}
if usr.HomeDir == "" {
fatalln("No home directory?") fatalln("No home directory?")
} }
return home return usr.HomeDir
} }