From 4b99d6cc16c2be170525cd572f6564b673ac90d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Senart?= Date: Wed, 23 Sep 2015 12:18:43 +0200 Subject: [PATCH] records: Find user's home directory through env As reported in https://github.com/golang/go/issues/6376, `os/user.Current` doesn't work with cross-compilation. This commit replaces its use with `os.Getenv` of the `$HOME` and `$USERPROFILE` environment variables. Fixes #275 --- records/config.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/records/config.go b/records/config.go index 8595e0c6..d78e6130 100644 --- a/records/config.go +++ b/records/config.go @@ -5,7 +5,7 @@ import ( "fmt" "io/ioutil" "net" - "os/user" + "os" "path/filepath" "strings" "time" @@ -177,14 +177,13 @@ func readConfig(file string) (*Config, error) { c := NewConfig() workingDir := "." - usr, err := user.Current() - if err != nil { - // this can happen (on Linux) if you're running mesos-dns as a non-root user. - logging.Error.Println("Failed to determine current user, translating ~/ to ./, error was", err) - } else { - workingDir = usr.HomeDir + for _, name := range []string{"HOME", "USERPROFILE"} { // *nix, windows + if dir := os.Getenv(name); dir != "" { + workingDir = dir + } } + var err error c.File, err = filepath.Abs(strings.Replace(file, "~/", workingDir+"/", 1)) if err != nil { return nil, fmt.Errorf("cannot find configuration file")