mirror of
https://github.com/syncthing/syncthing.git
synced 2024-11-16 10:28:49 -07:00
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:
parent
192117dc11
commit
23593c3d20
11
main.go
11
main.go
@ -11,6 +11,7 @@ import (
|
||||
_ "net/http/pprof"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/user"
|
||||
"path"
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
@ -561,9 +562,13 @@ func expandTilde(p string) string {
|
||||
}
|
||||
|
||||
func getHomeDir() string {
|
||||
home := os.Getenv("HOME")
|
||||
if home == "" {
|
||||
usr, err := user.Current()
|
||||
if err != nil {
|
||||
fatalln(err)
|
||||
}
|
||||
|
||||
if usr.HomeDir == "" {
|
||||
fatalln("No home directory?")
|
||||
}
|
||||
return home
|
||||
return usr.HomeDir
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user