Skip to content

Commit d797c2b

Browse files
committed
Use HOME variable to retrieve user home directory
1 parent 9c7e101 commit d797c2b

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

profile.go

+10-12
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@ var profileFolder_ string
1919
var config_ *sqlkv.SqlKv
2020
var profileDb_ *sql.DB
2121

22-
func userHomeDir() string {
23-
u, err := user.Current()
24-
if err != nil {
25-
panic(err)
26-
}
27-
return u.HomeDir
28-
}
29-
3022
func profileOpen() error {
3123
if profileDb_ != nil {
3224
return nil
@@ -74,11 +66,17 @@ func profileFolder() string {
7466
}
7567

7668
if homeDir_ == "" {
77-
u, err := user.Current()
78-
if err != nil {
79-
panic(err)
69+
// By default, use $HOME as it seems to be different from HomeDir in some
70+
// systems. In particular it's necessary to pass Homebrew's tests.
71+
homeDir_ = os.Getenv("HOME")
72+
73+
if homeDir_ == "" {
74+
u, err := user.Current()
75+
if err != nil {
76+
panic(err)
77+
}
78+
homeDir_ = u.HomeDir
8079
}
81-
homeDir_ = u.HomeDir
8280
}
8381

8482
output := filepath.Join(homeDir_, ".config", APPNAME)

profile_test.go

-7
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@ import (
66
"testing"
77
)
88

9-
func Test_userHomeDir(t *testing.T) {
10-
homeDir := userHomeDir()
11-
if len(homeDir) == 0 {
12-
t.Fail()
13-
}
14-
}
15-
169
func Test_profileOpenClose(t *testing.T) {
1710
if profileDb_ != nil {
1811
t.Error("profileDb_ should be nil")

0 commit comments

Comments
 (0)