homedir.go 325 B

1234567891011121314151617181920212223242526272829
  1. package dbus
  2. import (
  3. "os"
  4. "sync"
  5. )
  6. var (
  7. homeDir string
  8. homeDirLock sync.Mutex
  9. )
  10. func getHomeDir() string {
  11. homeDirLock.Lock()
  12. defer homeDirLock.Unlock()
  13. if homeDir != "" {
  14. return homeDir
  15. }
  16. homeDir = os.Getenv("HOME")
  17. if homeDir != "" {
  18. return homeDir
  19. }
  20. homeDir = lookupHomeDir()
  21. return homeDir
  22. }