Shift up the preference of the USERPROFILE variable
Mike Brancato
5 years ago
140 | 140 | return home, nil |
141 | 141 | } |
142 | 142 | |
143 | // Prefer standard environment variable USERPROFILE | |
144 | if home := os.Getenv("USERPROFILE"); home != "" { | |
145 | return home, nil | |
146 | } | |
147 | ||
143 | 148 | drive := os.Getenv("HOMEDRIVE") |
144 | 149 | path := os.Getenv("HOMEPATH") |
145 | 150 | home := drive + path |
146 | 151 | if drive == "" || path == "" { |
147 | home = os.Getenv("USERPROFILE") | |
148 | } | |
149 | if home == "" { | |
150 | return "", errors.New("HOMEDRIVE, HOMEPATH, and USERPROFILE are blank") | |
152 | return "", errors.New("HOMEDRIVE, HOMEPATH, or USERPROFILE are blank") | |
151 | 153 | } |
152 | 154 | |
153 | 155 | return home, nil |