Skip to content

Commit

Permalink
config: Add fallback in case HOME env var is not set (#1794)
Browse files Browse the repository at this point in the history
Co-authored-by: Sean McGrail <549813+skmcgrail@users.noreply.github.com>
  • Loading branch information
RanVaknin and skmcgrail authored Aug 12, 2022
1 parent 0ba2869 commit 7f6503c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
8 changes: 8 additions & 0 deletions .changelog/f6aec06ae77b40118322f509f6ad4096.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "f6aec06a-e77b-4011-8322-f509f6ad4096",
"type": "feature",
"description": "Add alternative mechanism for determning the users `$HOME` or `%USERPROFILE%` location when the environment variables are not present.",
"modules": [
"config"
]
}
15 changes: 13 additions & 2 deletions config/shared_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"io/ioutil"
"os"
"os/user"
"path/filepath"
"strings"
"time"
Expand Down Expand Up @@ -1149,8 +1150,18 @@ func (e CredentialRequiresARNError) Error() string {

func userHomeDir() string {
// Ignore errors since we only care about Windows and *nix.
homedir, _ := os.UserHomeDir()
return homedir
home, _ := os.UserHomeDir()

if len(home) > 0 {
return home
}

currUser, _ := user.Current()
if currUser != nil {
home = currUser.HomeDir
}

return home
}

func oneOrNone(bs ...bool) bool {
Expand Down

0 comments on commit 7f6503c

Please sign in to comment.