Skip to content

Commit b336526

Browse files
committed
os: change UserConfigDir on Darwin to ~/Library/Application Support
The old code used ~/Library/Preferences, which is documented by Apple as: This directory contains app-specific preference files. You should not create files in this directory yourself. Instead, use the NSUserDefaults class or CFPreferences API to get and set preference values for your app. It looks like we missed everything after the first sentence; it's definitely not the right choice for files that Go programs and users should be touching directly. Instead, use ~/Library/Application Support, which is documented as: Use this directory to store all app data files except those associated with the user’s documents. For example, you might use this directory to store app-created data files, configuration files, templates, or other fixed or modifiable resources that are managed by the app. An app might use this directory to store a modifiable copy of resources contained initially in the app’s bundle. A game might use this directory to store new levels purchased by the user and downloaded from a server. This seems in line with what UserConfigDir is for, so use it. The documentation quotes above are obtained from the surprisingly long link below: https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html Fixes #32475. Change-Id: Ic27a6c92d76a5d7a4d4b8eac5cd8472f67a533a4 Reviewed-on: https://go-review.googlesource.com/c/go/+/181177 Run-TryBot: Daniel Martí <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Andrew Bonventre <[email protected]>
1 parent 9eb4031 commit b336526

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/cmd/go/testdata/script/env_write.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ env AppData=$HOME/windowsappdata
55
env home=$HOME/plan9home
66
go env GOENV
77
[aix] stdout $HOME/.config/go/env
8-
[darwin] stdout $HOME/Library/Preferences/go/env
8+
[darwin] stdout $HOME/Library/Application Support/go/env
99
[freebsd] stdout $HOME/.config/go/env
1010
[linux] stdout $HOME/.config/go/env
1111
[netbsd] stdout $HOME/.config/go/env

src/os/file.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ func UserCacheDir() (string, error) {
406406
// On Unix systems, it returns $XDG_CONFIG_HOME as specified by
407407
// https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html if
408408
// non-empty, else $HOME/.config.
409-
// On Darwin, it returns $HOME/Library/Preferences.
409+
// On Darwin, it returns $HOME/Library/Application Support.
410410
// On Windows, it returns %AppData%.
411411
// On Plan 9, it returns $home/lib.
412412
//
@@ -427,7 +427,7 @@ func UserConfigDir() (string, error) {
427427
if dir == "" {
428428
return "", errors.New("$HOME is not defined")
429429
}
430-
dir += "/Library/Preferences"
430+
dir += "/Library/Application Support"
431431

432432
case "plan9":
433433
dir = Getenv("home")

0 commit comments

Comments
 (0)