mirror of
https://gitlab.com/pulsechaincom/go-pulse.git
synced 2025-01-03 17:24:28 +00:00
common: Fix HomeDir detection
I am working on porting geth to [Ubuntu Core](https://developer.ubuntu.com/en/snappy/https://developer.ubuntu.com/en/snappy/). I am testing geth on a Raspberry PI and for Ubuntu Core the $HOME directory is unique for each application. See [here](https://developer.ubuntu.com/en/snappy/guides/filesystem-layout) for more information of their filesystem layout. For some reason in Go `usr.HomeDir` returns a different value than `$HOME` in Ubuntu Core. Adding this at the end of `HomeDir()` ```go fmt.Printf("at HomeDir, user.HomeDir = %s and $HOME is %s\n", usr.HomeDir, os.Getenv("HOME")) ``` gives the following output ``` at HomeDir, user.HomeDir = /home/ubuntu and $HOME is /home/ubuntu/apps/geth.sideload/IJcODREBYbHO ``` With this commit, I propose giving precedence to the `$HOME` environment variable as is also suggested by the [homedir](https://github.com/mitchellh/go-homedir/blob/master/homedir.go) project.
This commit is contained in:
parent
32226f1b0c
commit
e2fdd33541
@ -63,13 +63,14 @@ func AbsolutePath(Datadir string, filename string) string {
|
|||||||
return filepath.Join(Datadir, filename)
|
return filepath.Join(Datadir, filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
func HomeDir() (home string) {
|
func HomeDir() string {
|
||||||
if usr, err := user.Current(); err == nil {
|
if home := os.Getenv("HOME"); home != "" {
|
||||||
home = usr.HomeDir
|
return home
|
||||||
} else {
|
|
||||||
home = os.Getenv("HOME")
|
|
||||||
}
|
}
|
||||||
return
|
if usr, err := user.Current(); err == nil {
|
||||||
|
return usr.HomeDir
|
||||||
|
}
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func DefaultDataDir() string {
|
func DefaultDataDir() string {
|
||||||
|
Loading…
Reference in New Issue
Block a user