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

XDG directory functions do not respect XDG variables on macOS #2434

Closed
uncenter opened this issue Oct 19, 2024 · 10 comments
Closed

XDG directory functions do not respect XDG variables on macOS #2434

uncenter opened this issue Oct 19, 2024 · 10 comments

Comments

@uncenter
Copy link

Due to long standing difficulties with (a/the) maintainer of dirs-rs, they refuse to recognize XDG environment variables explicitly defined by the user on macOS: dirs-dev/directories-rs#47. config_directory() will always go to /Users/<username>/Library/Application Support on macOS, even if you have set XDG_CONFIG_HOME. I would suggest using https://github.com/lunacookies/etcetera instead, though there may be other alternatives that also respect user preferences.

@laniakea64
Copy link
Contributor

Changing the behavior of the existing functions would break just's backwards-compatibility guarantee. This would need to be a new function (maybe named xdg_config_directory()?)

@uncenter
Copy link
Author

Yeah that's sound good, we should still update the documentation for the normal config_directory() functions to clarify that they return the path for the operating system specification - right now they are literally called "XDG Directories", that name (and description) would be fitting for xdg_config_directory() instead :)

@uncenter
Copy link
Author

Well, dirs is used for other features like global justfile locating:

just/src/search.rs

Lines 14 to 19 in 4f31853

fn global_justfile_paths() -> Vec<PathBuf> {
let mut paths = Vec::new();
if let Some(config_dir) = dirs::config_dir() {
paths.push(config_dir.join("just").join(DEFAULT_JUSTFILE_NAME));
}

But since that wouldn't affect the backwards compatability of the justfiles themselves would that be a change that could be made at some point as well?

@casey
Copy link
Owner

casey commented Oct 30, 2024

Regarding #2439, I see the benefit, but it seems unfortunate to add a bunch more functions that are very close to existing functions.

An alternative option would be to add a setting, like set use-xdg-directories, which would change the behavior of directory functions to respect the XDG variables.

@soc

This comment was marked as off-topic.

@uncenter

This comment was marked as off-topic.

@soc

This comment was marked as off-topic.

@casey
Copy link
Owner

casey commented Dec 20, 2024

I'm going to hide as off topic all comments related to what dirs should or shouldn't do. This is the repo for just, and discussion of what other libraries should or shouldn't do is off topic.

I'm actually not sure just should make any changes here.

If users want to use the value of the $XDG_* variables, they can do env('XDG_CONFIG_HOME'), which is short and explicit, and if they don't, they can use the provided functions, like home_directory().

In any case, the documentation should be changed to reflect what the current functions actually do, which is provide paths to system directories.

@casey
Copy link
Owner

casey commented Dec 20, 2024

Updated the readme in #2535.

@casey
Copy link
Owner

casey commented Dec 20, 2024

I think since just provides an easy way to get environment variables, I'm going to close this for now.

I think it's not a bad situation that the functions always return system-specified locations, and users that want the XDG locations can use env.

If we want, we could additionally document the names of the corresponding XDG_* environment variables are for each existing function.

@casey casey closed this as completed Dec 20, 2024
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 a pull request may close this issue.

4 participants