Skip to content

Commit

Permalink
Default to HOME env var if unable to get via os.User
Browse files Browse the repository at this point in the history
Fixes the situation where strongbox is compiled without CGO and statically
linked. On Linux user.Current() isn't implemented, so we attempt to
figure out HOME via env vars.
  • Loading branch information
george-angel committed Feb 13, 2018
1 parent 5e18852 commit e4525e7
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions strongbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,20 @@ func main() {
flag.Parse()

// Set up keyring file name
home := ""
u, err := user.Current()
if err != nil {
log.Fatal(err)
// Possibly compiled without CGO and syscall isn't implemented,
// try to grab the environmet variable
home = os.Getenv("HOME")
if home == "" {
log.Fatal("Could not call os/user.Current() or find $HOME. Please recoming with CGO enabled or set $HOME")
}
} else {
home = u.HomeDir
}
kr = &fileKeyRing{fileName: filepath.Join(u.HomeDir, ".strongbox_keyring")}

kr = &fileKeyRing{fileName: filepath.Join(home, ".strongbox_keyring")}

// only a single flag has been set
if flag.NFlag() != 1 {
Expand Down

0 comments on commit e4525e7

Please sign in to comment.