Fix "Couldn't find home directory" on OSX - fixes #15
This commit is contained in:
parent
ee6b39aa6c
commit
af9c447146
1 changed files with 14 additions and 4 deletions
18
fs/config.go
18
fs/config.go
|
@ -56,11 +56,21 @@ type ConfigInfo struct {
|
||||||
func configHome() string {
|
func configHome() string {
|
||||||
// Find users home directory
|
// Find users home directory
|
||||||
usr, err := user.Current()
|
usr, err := user.Current()
|
||||||
if err != nil {
|
if err == nil {
|
||||||
log.Printf("Couldn't find home directory: %v", err)
|
return usr.HomeDir
|
||||||
return ""
|
|
||||||
}
|
}
|
||||||
return usr.HomeDir
|
// Fall back to reading $HOME - work around user.Current() not
|
||||||
|
// working for cross compiled binaries on OSX.
|
||||||
|
// https://github.com/golang/go/issues/6376
|
||||||
|
home := os.Getenv("HOME")
|
||||||
|
if home != "" {
|
||||||
|
return home
|
||||||
|
}
|
||||||
|
log.Printf("Couldn't find home directory or read HOME environment variable.")
|
||||||
|
log.Printf("Defaulting to storing config in current directory.")
|
||||||
|
log.Printf("Use -config flag to workaround.")
|
||||||
|
log.Printf("Error was: %v", err)
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loads the config file
|
// Loads the config file
|
||||||
|
|
Loading…
Reference in a new issue