File tree Expand file tree Collapse file tree 3 files changed +13
-76
lines changed Expand file tree Collapse file tree 3 files changed +13
-76
lines changed Original file line number Diff line number Diff line change @@ -2,27 +2,24 @@ package dbus
2
2
3
3
import (
4
4
"os"
5
- "sync"
6
- )
7
-
8
- var (
9
- homeDir string
10
- homeDirLock sync.Mutex
5
+ "os/user"
11
6
)
12
7
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.
13
16
func getHomeDir () string {
14
- homeDirLock .Lock ()
15
- defer homeDirLock .Unlock ()
16
-
17
+ homeDir := os .Getenv ("HOME" )
17
18
if homeDir != "" {
18
19
return homeDir
19
20
}
20
-
21
- homeDir = os .Getenv ("HOME" )
22
- if homeDir != "" {
23
- return homeDir
21
+ if u , err := user .Current (); err == nil {
22
+ return u .HomeDir
24
23
}
25
-
26
- homeDir = lookupHomeDir ()
27
- return homeDir
24
+ return "/"
28
25
}
Load Diff This file was deleted.
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments