Skip to content

Commit 958b2d1

Browse files
authored
Merge pull request godbus#304 from kolyshkin/homedir
homedir: revamp
2 parents 587048b + 230c6f2 commit 958b2d1

File tree

3 files changed

+13
-76
lines changed

3 files changed

+13
-76
lines changed

homedir.go

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,24 @@ package dbus
22

33
import (
44
"os"
5-
"sync"
6-
)
7-
8-
var (
9-
homeDir string
10-
homeDirLock sync.Mutex
5+
"os/user"
116
)
127

8+
// Get returns the home directory of the current user, which is usually the
9+
// value of HOME environment variable. In case it is not set or empty, os/user
10+
// package is used.
11+
//
12+
// If linking statically with cgo enabled against glibc, make sure the
13+
// osusergo build tag is used.
14+
//
15+
// If needing to do nss lookups, do not disable cgo or set osusergo.
1316
func getHomeDir() string {
14-
homeDirLock.Lock()
15-
defer homeDirLock.Unlock()
16-
17+
homeDir := os.Getenv("HOME")
1718
if homeDir != "" {
1819
return homeDir
1920
}
20-
21-
homeDir = os.Getenv("HOME")
22-
if homeDir != "" {
23-
return homeDir
21+
if u, err := user.Current(); err == nil {
22+
return u.HomeDir
2423
}
25-
26-
homeDir = lookupHomeDir()
27-
return homeDir
24+
return "/"
2825
}

homedir_dynamic.go

Lines changed: 0 additions & 15 deletions
This file was deleted.

homedir_static.go

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)