Skip to content

Commit a9f532d

Browse files
committed
fix: nil pointer panic in getDefaultInstallDir on containerized Linux
1 parent 525e844 commit a9f532d

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

internal/settings/defaults.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ package settings
2020

2121
import (
2222
"fmt"
23-
"os/user"
23+
"os"
2424
"runtime"
2525
)
2626

@@ -48,13 +48,19 @@ func getDefaultInstallDir() string {
4848
return "/Applications"
4949
case Windows:
5050
// https://superuser.com/questions/1327037/what-choices-do-i-have-about-where-to-install-software-on-windows-10
51-
usr, _ := user.Current() // safe to ignore cache errors
52-
return fmt.Sprintf(`%s\AppData\Local\Programs`, usr.HomeDir)
51+
homeDir, err := os.UserHomeDir()
52+
if err != nil {
53+
return ""
54+
}
55+
return fmt.Sprintf(`%s\AppData\Local\Programs`, homeDir)
5356
case Linux:
5457
// https://unix.stackexchange.com/questions/127076/into-which-directory-should-i-install-programs-in-linux
55-
usr, _ := user.Current() // safe to ignore cache errors
5658
// Use path in users home folder to not require sudo permissions for installation
57-
return fmt.Sprintf(`%s/.local/bin`, usr.HomeDir)
59+
homeDir, err := os.UserHomeDir()
60+
if err != nil {
61+
return ""
62+
}
63+
return fmt.Sprintf(`%s/.local/bin`, homeDir)
5864
default:
5965
return ""
6066
}

0 commit comments

Comments
 (0)