Added support for HOME environment variable on Windows

This commit is contained in:
Rod Cloutier
2016-10-23 21:35:40 -04:00
parent a7db9bccb5
commit 1027f35805

View File

@@ -24,6 +24,13 @@ import (
// HomeDir returns the home directory for the current user
func HomeDir() string {
if runtime.GOOS == "windows" {
// First prefer the HOME environmental variable
if home := os.Getenv("HOME"); len(home) > 0 {
if _, err := os.Stat(home); err == nil {
return home
}
}
if homeDrive, homePath := os.Getenv("HOMEDRIVE"), os.Getenv("HOMEPATH"); len(homeDrive) > 0 && len(homePath) > 0 {
homeDir := homeDrive + homePath
if _, err := os.Stat(homeDir); err == nil {