Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config: Add fallback in case HOME env var is not set #1794

Merged
merged 2 commits into from Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changelog/f6aec06ae77b40118322f509f6ad4096.json
@@ -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
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