Skip to content
This repository has been archived by the owner on May 11, 2020. It is now read-only.

Commit

Permalink
Prevent race condition when reading env
Browse files Browse the repository at this point in the history
  • Loading branch information
emersion committed Jan 8, 2019
1 parent 65e6cfc commit 8d7e66f
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions appdir_xdg.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,35 @@ type dirs struct {

func (d *dirs) UserConfig() string {
baseDir := filepath.Join(os.Getenv("HOME"), ".config")
if os.Getenv("XDG_CONFIG_HOME") != "" {
baseDir = os.Getenv("XDG_CONFIG_HOME")
if d := os.Getenv("XDG_CONFIG_HOME"); d != "" {
baseDir = d
}

return filepath.Join(baseDir, d.name)
}

func (d *dirs) UserCache() string {
baseDir := filepath.Join(os.Getenv("HOME"), ".cache")
if os.Getenv("XDG_CACHE_HOME") != "" {
baseDir = os.Getenv("XDG_CACHE_HOME")
if d := os.Getenv("XDG_CACHE_HOME"); d != "" {
baseDir = d
}

return filepath.Join(baseDir, d.name)
}

func (d *dirs) UserLogs() string {
baseDir := filepath.Join(os.Getenv("HOME"), ".local", "state")
if os.Getenv("XDG_STATE_HOME") != "" {
baseDir = os.Getenv("XDG_STATE_HOME")
if d := os.Getenv("XDG_STATE_HOME"); d != "" {
baseDir = d
}

return filepath.Join(baseDir, d.name)
}

func (d *dirs) UserData() string {
baseDir := filepath.Join(os.Getenv("HOME"), ".local", "share")
if os.Getenv("XDG_DATA_HOME") != "" {
baseDir = os.Getenv("XDG_DATA_HOME")
if d := os.Getenv("XDG_DATA_HOME"); d != "" {
baseDir = d
}

return filepath.Join(baseDir, d.name)
Expand Down

0 comments on commit 8d7e66f

Please sign in to comment.