Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve macOS config base directory defaults #13

Merged
merged 3 commits into from
Feb 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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