Skip to content

Commit

Permalink
Make source a bit more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
muesli committed Mar 12, 2020
1 parent fb05931 commit 105f35d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
12 changes: 12 additions & 0 deletions paths_darwin.go
Expand Up @@ -14,11 +14,14 @@ func (s *Scope) appendPaths(path string, parts ...string) string {
// dataDir returns the full path to the data directory.
func (s *Scope) dataDir() (string, error) {
def := "/Library/Application Support"

switch s.Type {
case System:
return def, nil

case User:
return expandUser("~" + def), nil

case CustomHome:
return filepath.Join(s.CustomHome, def), nil
}
Expand All @@ -29,11 +32,14 @@ func (s *Scope) dataDir() (string, error) {
// cacheDir returns the full path to the cache directory.
func (s *Scope) cacheDir() (string, error) {
def := "/Library/Caches"

switch s.Type {
case System:
return def, nil

case User:
return expandUser("~" + def), nil

case CustomHome:
return filepath.Join(s.CustomHome, def), nil
}
Expand All @@ -44,11 +50,14 @@ func (s *Scope) cacheDir() (string, error) {
// configDir returns the full path to the config dir.
func (s *Scope) configDir() (string, error) {
def := "/Library/Preferences"

switch s.Type {
case System:
return def, nil

case User:
return expandUser("~" + def), nil

case CustomHome:
return filepath.Join(s.CustomHome, def), nil
}
Expand All @@ -59,11 +68,14 @@ func (s *Scope) configDir() (string, error) {
// logDir returns the full path to the log dir.
func (s *Scope) logDir() (string, error) {
def := "/Library/Logs"

switch s.Type {
case System:
return def, nil

case User:
return expandUser("~" + def), nil

case CustomHome:
return filepath.Join(s.CustomHome, def), nil
}
Expand Down
8 changes: 8 additions & 0 deletions paths_unix.go
Expand Up @@ -19,12 +19,14 @@ func (s *Scope) dataDir() (string, error) {
switch s.Type {
case System:
return "/usr/share", nil

case User:
path := os.Getenv("XDG_DATA_HOME")
if path == "" {
return expandUser("~/.local/share"), nil
}
return path, nil

case CustomHome:
return filepath.Join(s.CustomHome, ".local/share"), nil
}
Expand All @@ -37,12 +39,14 @@ func (s *Scope) cacheDir() (string, error) {
switch s.Type {
case System:
return "/var/cache", nil

case User:
path := os.Getenv("XDG_CACHE_HOME")
if path == "" {
return expandUser("~/.cache"), nil
}
return path, nil

case CustomHome:
return filepath.Join(s.CustomHome, ".cache"), nil
}
Expand All @@ -55,12 +59,14 @@ func (s *Scope) configDir() (string, error) {
switch s.Type {
case System:
return "/etc", nil

case User:
path := os.Getenv("XDG_CONFIG_HOME")
if path == "" {
return expandUser("~/.config"), nil
}
return path, nil

case CustomHome:
return filepath.Join(s.CustomHome, ".config"), nil
}
Expand All @@ -73,8 +79,10 @@ func (s *Scope) logDir() (string, error) {
switch s.Type {
case System:
return "/var/log", nil

case User:
fallthrough

case CustomHome:
return s.dataDir()
}
Expand Down
3 changes: 3 additions & 0 deletions paths_windows.go
Expand Up @@ -51,10 +51,13 @@ func (s *Scope) dataDir() (string, error) {
switch s.Type {
case System:
rfid = rfidProgramData

case User:
rfid = rfidLocalAppData

case CustomHome:
return s.CustomHome, nil

default:
return "", ErrInvalidScope
}
Expand Down

0 comments on commit 105f35d

Please sign in to comment.