Skip to content

Commit

Permalink
Merge pull request #13 from adrg/improve-macos-config-paths
Browse files Browse the repository at this point in the history
Improve macOS config base directory defaults
  • Loading branch information
adrg committed Feb 22, 2021
2 parents 28f7229 + b5336d9 commit b9ccb1f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 22 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ present in the environment.

#### XDG Base Directory

| | Unix | macOS | Windows |
| :-------------- | :---------------------------------- | :------------------------------ | :-------------------------------------- |
| XDG_DATA_HOME | `~/.local/share` | `~/Library/Application Support` | `%LOCALAPPDATA%` |
| XDG_DATA_DIRS | `/usr/local/share`<br/>`/usr/share` | `/Library/Application Support` | `%APPDATA%\Roaming`<br/>`%PROGRAMDATA%` |
| XDG_CONFIG_HOME | `~/.config` | `~/Library/Preferences` | `%LOCALAPPDATA%` |
| XDG_CONFIG_DIRS | `/etc/xdg` | `/Library/Preferences` | `%PROGRAMDATA%` |
| XDG_CACHE_HOME | `~/.cache` | `~/Library/Caches` | `%LOCALAPPDATA%\cache` |
| XDG_RUNTIME_DIR | `/run/user/UID` | `~/Library/Application Support` | `%LOCALAPPDATA%` |
| | Unix | macOS | Windows |
| :-------------- | :---------------------------------- | :------------------------------------------------------------------------------------ | :-------------------------------------- |
| XDG_DATA_HOME | `~/.local/share` | `~/Library/Application Support` | `%LOCALAPPDATA%` |
| XDG_DATA_DIRS | `/usr/local/share`<br/>`/usr/share` | `/Library/Application Support` | `%APPDATA%\Roaming`<br/>`%PROGRAMDATA%` |
| XDG_CONFIG_HOME | `~/.config` | `~/Library/Application Support` | `%LOCALAPPDATA%` |
| XDG_CONFIG_DIRS | `/etc/xdg` | `~/Library/Preferences`<br/>`/Library/Application Support`<br/>`/Library/Preferences` | `%PROGRAMDATA%` |
| XDG_CACHE_HOME | `~/.cache` | `~/Library/Caches` | `%LOCALAPPDATA%\cache` |
| XDG_RUNTIME_DIR | `/run/user/UID` | `~/Library/Application Support` | `%LOCALAPPDATA%` |

#### XDG user directories

Expand Down
19 changes: 13 additions & 6 deletions paths_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,23 @@ import (
)

func initBaseDirs(home string) {
homeAppSupport := filepath.Join(home, "Library", "Application Support")
rootAppSupport := "/Library/Application Support"

// Initialize base directories.
baseDirs.dataHome = xdgPath(envDataHome, filepath.Join(home, "Library", "Application Support"))
baseDirs.data = xdgPaths(envDataDirs, "/Library/Application Support")
baseDirs.configHome = xdgPath(envConfigHome, filepath.Join(home, "Library", "Preferences"))
baseDirs.config = xdgPaths(envConfigDirs, "/Library/Preferences")
baseDirs.dataHome = xdgPath(envDataHome, homeAppSupport)
baseDirs.data = xdgPaths(envDataDirs, rootAppSupport)
baseDirs.configHome = xdgPath(envConfigHome, homeAppSupport)
baseDirs.config = xdgPaths(envConfigDirs,
filepath.Join(home, "Library", "Preferences"),
rootAppSupport,
"/Library/Preferences",
)
baseDirs.cacheHome = xdgPath(envCacheHome, filepath.Join(home, "Library", "Caches"))
baseDirs.runtime = xdgPath(envRuntimeDir, filepath.Join(home, "Library", "Application Support"))
baseDirs.runtime = xdgPath(envRuntimeDir, homeAppSupport)

// Initialize non-standard directories.
baseDirs.stateHome = xdgPath(envStateHome, filepath.Join(home, "Library", "Application Support"))
baseDirs.stateHome = xdgPath(envStateHome, homeAppSupport)
baseDirs.applications = []string{
"/Applications",
}
Expand Down
22 changes: 14 additions & 8 deletions paths_darwin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,33 @@ import (

func TestDefaultBaseDirs(t *testing.T) {
home := xdg.Home
homeAppSupport := filepath.Join(home, "Library", "Application Support")
rootAppSupport := "/Library/Application Support"

testDirs(t,
&envSample{
name: "XDG_DATA_HOME",
expected: filepath.Join(home, "Library", "Application Support"),
expected: homeAppSupport,
actual: &xdg.DataHome,
},
&envSample{
name: "XDG_DATA_DIRS",
expected: []string{"/Library/Application Support"},
expected: []string{rootAppSupport},
actual: &xdg.DataDirs,
},
&envSample{
name: "XDG_CONFIG_HOME",
expected: filepath.Join(home, "Library", "Preferences"),
expected: homeAppSupport,
actual: &xdg.ConfigHome,
},
&envSample{
name: "XDG_CONFIG_DIRS",
expected: []string{"/Library/Preferences"},
actual: &xdg.ConfigDirs,
name: "XDG_CONFIG_DIRS",
expected: []string{
filepath.Join(home, "Library", "Preferences"),
rootAppSupport,
"/Library/Preferences",
},
actual: &xdg.ConfigDirs,
},
&envSample{
name: "XDG_CACHE_HOME",
Expand All @@ -40,12 +46,12 @@ func TestDefaultBaseDirs(t *testing.T) {
},
&envSample{
name: "XDG_RUNTIME_DIR",
expected: filepath.Join(home, "Library", "Application Support"),
expected: homeAppSupport,
actual: &xdg.RuntimeDir,
},
&envSample{
name: "XDG_STATE_HOME",
expected: filepath.Join(home, "Library", "Application Support"),
expected: homeAppSupport,
actual: &xdg.StateHome,
},
&envSample{
Expand Down

0 comments on commit b9ccb1f

Please sign in to comment.