Skip to content

Commit 81cf7b8

Browse files
authored
Merge pull request #19 from chrisdeeming/patch-2
Use `os.UserHomeDir` for getting user profile directory
2 parents 8c75d8f + b7bd398 commit 81cf7b8

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

discovery_windows.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
// see https://github.com/composer/windows-setup/blob/master/src/composer.iss
2929
func (s *PHPStore) doDiscover() {
3030
systemDir := systemDir()
31-
userProfileDir := userProfileDir()
31+
userHomeDir := userHomeDir()
3232

3333
// XAMPP
3434
s.addFromDir(filepath.Join(systemDir, "xampp", "php"), nil, "XAMPP")
@@ -48,8 +48,8 @@ func (s *PHPStore) doDiscover() {
4848
s.discoverFromDir(filepath.Join(systemDir, "mamp", "bin", "php"), nil, regexp.MustCompile("^php[\\d\\.]+$"), "MAMP")
4949

5050
// Herd
51-
if userProfileDir != "" {
52-
s.discoverFromDir(filepath.Join(userProfileDir, ".config", "herd", "bin"), nil, regexp.MustCompile("^php\\d{2}$"), "Herd")
51+
if userHomeDir != "" {
52+
s.discoverFromDir(filepath.Join(userHomeDir, ".config", "herd", "bin"), nil, regexp.MustCompile("^php\\d{2}$"), "Herd")
5353
}
5454
}
5555

@@ -61,6 +61,10 @@ func systemDir() string {
6161
return filepath.VolumeName(cwd) + "\\"
6262
}
6363

64-
func userProfileDir() string {
65-
return os.Getenv("USERPROFILE")
64+
func userHomeDir() string {
65+
userHomeDir, err := os.UserHomeDir()
66+
if err != nil {
67+
return ""
68+
}
69+
return userHomeDir
6670
}

0 commit comments

Comments
 (0)