Skip to content

Use FHS/XDG paths for UserDefaults on Linux & BSD-y OSes #1399

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

Merged
merged 5 commits into from
Jan 25, 2018
Merged

Use FHS/XDG paths for UserDefaults on Linux & BSD-y OSes #1399

merged 5 commits into from
Jan 25, 2018

Conversation

millenomi
Copy link
Contributor

On FHS/XDG systems, the paths for UserDefaults are now:

  • /usr/local/etc for AnyUser preferences (replaces /Library/Preferences)
  • $XDG_CONFIG_DIR for CurrentUser preferences (replaces $HOME/Library/Preferences)

($XDG_CONFIG_DIR is typically, and defaults to, $HOME/.config/.)

@millenomi
Copy link
Contributor Author

@swift-ci Please test.

@@ -1198,7 +1198,7 @@ static CFStringRef _CFXDGCreateHome(void) {
}

/// a single base directory relative to which user-specific data files should be written. This directory is defined by the environment variable $XDG_DATA_HOME.
CF_SWIFT_EXPORT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should still only be exported on non-Darwin platforms. We may need another version of this CF_EXPORT macro.


#include <assert.h>

CONST_STRING_DECL(_kCFKnownLocationUserAny, " == _kCFKnownLocationUserAny");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, the == at the start is something unusual. In most cases the string is equal to the key name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah — the idea here was to make sure it couldn't be a valid username. Since we're switching to an enum, this problem goes away.

- Current: $HOME/Library/Preferences
*/

if (user == _kCFKnownLocationUserAny) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're just going to do an == check, perhaps we should just declare an enum?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that makes sense. It'll be the enum plus a NULLable username string argument.

See CFKnownLocations.c for a summary of what paths are returned.
*/

extern CFURLRef _Nullable _CFKnownLocationCreatePreferencesURLForUser(CFKnownLocationUser user);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need to make sure this is only exported on non-Darwin platforms.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok!

@@ -327,8 +327,6 @@ CF_EXPORT _Nullable CFErrorRef CFReadStreamCopyError(CFReadStreamRef stream);

CF_EXPORT _Nullable CFErrorRef CFWriteStreamCopyError(CFWriteStreamRef stream);

CF_SWIFT_EXPORT Boolean _CFBundleSupportsFHSBundles(void);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This removal is a merge issue and incorrect.

@millenomi
Copy link
Contributor Author

@swift-ci Please test.

@millenomi
Copy link
Contributor Author

I'm going to have a proposal for CF_SWIFT_EXPORT as a separate patch, and then rebase this one.

@achivetta
Copy link

Out of curiosity, why /usr/local/etc rather than /etc?

@millenomi
Copy link
Contributor Author

/etc is for system-level configuration (think /System/Library/ on macOS). There is some confusion between the two, and the FHS actually allows linking /usr/local/etc to /etc/local so that all configuration files are in /etc, but the intent is that this directory be e.g. never replaced by a system update if it's modified (think /Library on macOS.)

@millenomi
Copy link
Contributor Author

@parkera This has been rebased on master and has fixes for your review comments.

@swift-ci Please test.

@millenomi
Copy link
Contributor Author

@swift-ci Please test.

@millenomi
Copy link
Contributor Author

@swift-ci Please test and merge.

@swift-ci swift-ci merged commit 5a6f4c6 into swiftlang:master Jan 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants