From b7bd398077b75dea9b5a6b68edd95796d3c2f6cb Mon Sep 17 00:00:00 2001 From: Chris Deeming Date: Mon, 15 Apr 2024 03:08:54 +0100 Subject: [PATCH] Use `os.UserHomeDir` for getting user profile directory --- discovery_windows.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/discovery_windows.go b/discovery_windows.go index d86173f..f1cbe10 100644 --- a/discovery_windows.go +++ b/discovery_windows.go @@ -28,7 +28,7 @@ import ( // see https://github.com/composer/windows-setup/blob/master/src/composer.iss func (s *PHPStore) doDiscover() { systemDir := systemDir() - userProfileDir := userProfileDir() + userHomeDir := userHomeDir() // XAMPP s.addFromDir(filepath.Join(systemDir, "xampp", "php"), nil, "XAMPP") @@ -48,8 +48,8 @@ func (s *PHPStore) doDiscover() { s.discoverFromDir(filepath.Join(systemDir, "mamp", "bin", "php"), nil, regexp.MustCompile("^php[\\d\\.]+$"), "MAMP") // Herd - if userProfileDir != "" { - s.discoverFromDir(filepath.Join(userProfileDir, ".config", "herd", "bin"), nil, regexp.MustCompile("^php\\d{2}$"), "Herd") + if userHomeDir != "" { + s.discoverFromDir(filepath.Join(userHomeDir, ".config", "herd", "bin"), nil, regexp.MustCompile("^php\\d{2}$"), "Herd") } } @@ -61,6 +61,10 @@ func systemDir() string { return filepath.VolumeName(cwd) + "\\" } -func userProfileDir() string { - return os.Getenv("USERPROFILE") +func userHomeDir() string { + userHomeDir, err := os.UserHomeDir() + if err != nil { + return "" + } + return userHomeDir }