Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #277 from mesosphere/fix-275
Browse files Browse the repository at this point in the history
records: Find user's home directory through env
  • Loading branch information
tsenart committed Sep 23, 2015
2 parents c9248fb + 4b99d6c commit 777b8df
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions records/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"io/ioutil"
"net"
"os/user"
"os"
"path/filepath"
"strings"
"time"
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 777b8df

Please # to comment.