From b33652642286cf4c3fc8b10cdda97bd58059ba3e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Mart=C3=AD?= <mvdan@mvdan.cc>
Date: Fri, 7 Jun 2019 10:39:21 +0100
Subject: [PATCH] os: change UserConfigDir on Darwin to ~/Library/Application
 Support
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

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í <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
---
 src/cmd/go/testdata/script/env_write.txt | 2 +-
 src/os/file.go                           | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/cmd/go/testdata/script/env_write.txt b/src/cmd/go/testdata/script/env_write.txt
index bdc348c9538..e944d09e96e 100644
--- a/src/cmd/go/testdata/script/env_write.txt
+++ b/src/cmd/go/testdata/script/env_write.txt
@@ -5,7 +5,7 @@ env AppData=$HOME/windowsappdata
 env home=$HOME/plan9home
 go env GOENV
 [aix] stdout $HOME/.config/go/env
-[darwin] stdout $HOME/Library/Preferences/go/env
+[darwin] stdout $HOME/Library/Application Support/go/env
 [freebsd] stdout $HOME/.config/go/env
 [linux] stdout $HOME/.config/go/env
 [netbsd] stdout $HOME/.config/go/env
diff --git a/src/os/file.go b/src/os/file.go
index f835537d51a..96df3fb5e90 100644
--- a/src/os/file.go
+++ b/src/os/file.go
@@ -406,7 +406,7 @@ func UserCacheDir() (string, error) {
 // On Unix systems, it returns $XDG_CONFIG_HOME as specified by
 // https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html if
 // non-empty, else $HOME/.config.
-// On Darwin, it returns $HOME/Library/Preferences.
+// On Darwin, it returns $HOME/Library/Application Support.
 // On Windows, it returns %AppData%.
 // On Plan 9, it returns $home/lib.
 //
@@ -427,7 +427,7 @@ func UserConfigDir() (string, error) {
 		if dir == "" {
 			return "", errors.New("$HOME is not defined")
 		}
-		dir += "/Library/Preferences"
+		dir += "/Library/Application Support"
 
 	case "plan9":
 		dir = Getenv("home")
-- 
GitLab