Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit d26f376

Browse files
authored
Merge pull request #24 from mbrancato/master
Shift up the preference of the USERPROFILE variable
2 parents 3864e76 + 32e698a commit d26f376

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

homedir.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,16 @@ func dirWindows() (string, error) {
141141
return home, nil
142142
}
143143

144+
// Prefer standard environment variable USERPROFILE
145+
if home := os.Getenv("USERPROFILE"); home != "" {
146+
return home, nil
147+
}
148+
144149
drive := os.Getenv("HOMEDRIVE")
145150
path := os.Getenv("HOMEPATH")
146151
home := drive + path
147152
if drive == "" || path == "" {
148-
home = os.Getenv("USERPROFILE")
149-
}
150-
if home == "" {
151-
return "", errors.New("HOMEDRIVE, HOMEPATH, and USERPROFILE are blank")
153+
return "", errors.New("HOMEDRIVE, HOMEPATH, or USERPROFILE are blank")
152154
}
153155

154156
return home, nil

0 commit comments

Comments
 (0)