mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-09 14:50:56 +00: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"
|
_ "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
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user