[PR #357] Use XDG specification environment variables #1667

Open
opened 2026-03-14 15:26:40 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/aome510/spotify-player/pull/357
Author: @LucasFA
Created: 2/5/2024
Status: 🔄 Open

Base: masterHead: xdg-config


📝 Commits (1)

  • 5165c33 feat!: use XDG spec environment variables

📊 Changes

2 files changed (+19 additions, -6 deletions)

View changed files

📝 README.md (+2 -2)
📝 spotify_player/src/config/mod.rs (+17 -4)

📄 Description

I noticed a while back that the default XDG base specification locations are hard coded. This PR changes the project to use the corresponding environment variables.

This is a now obsolete message, but let's keep it for context This was when considering to use the dirs-next crate: ~~As I comment in the commit message~~, it is a BREAKING CHANGE for users with the XDG_CONFIG_HOME variable set to one different from the default. Note that while the spec seems relatively Linux-centric, the dirs-next crate also uses recommended guidelines in both mac OS and Windows and so would ~~be breaking for possibly absolutely~~ affect all users. See the table:
Linux	 $XDG_CONFIG_HOME or $HOME/.config	/home/alice/.config
macOS	 $HOME/Library/Application Support	/Users/Alice/Library/Application Support
Windows	 {FOLDERID_RoamingAppData}	        C:\Users\Alice\AppData\Roaming

Obviously breaking all users' config is breaking for any release, so I thought about renaming the current files to whatever they would become after the new location, but that might just break other users, for all I know. (I'm looking at you, NixOS)

Then this is some contextual information from what other projects do:

Instead of doing that, a more reasonable solution is simply using the old config location in case it exists, or otherwise default to the new location. I think this is what git did ( https://git-scm.com/docs/git-config#Documentation/git-config.txt-XDGCONFIGHOMEgitconfig ), only they go on to read the non-compliant file anyway.

It seem that while the convention is clearly defined in Linux, the situation is not so clear in MacOS, and somewhat in Windows. In Mac, ome people strongly prefer the platform recommended locations, and other strongly prefer the XDG ~/.config location. There's precendent: https://github.com/rust-lang/rfcs/pull/1615#issuecomment-221361170, https://github.com/dirs-dev/directories-rs/issues/47. Neovim seems to clump all Unix together, so they also use ~/.config for MacOS. On the opposite end is the `dirs-next` crate, which doesn't honor the XDG environment variables in MacOS: [docs](https://docs.rs/dirs-next/2.0.0/dirs_next/fn.cache_dir.html)

Current status

This PR just detects if the XDG_CONFIG_HOME and XDG_CACHE_HOME environment variable are set. For compatibililty, if XDG_CONFIG_HOME is set but the old location exists, keep current behaviour. Cache is migrated to XDG_CACHE_HOME always.

Given that the cache folder is not routinely accessed, this should not affect any users negatively.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/aome510/spotify-player/pull/357 **Author:** [@LucasFA](https://github.com/LucasFA) **Created:** 2/5/2024 **Status:** 🔄 Open **Base:** `master` ← **Head:** `xdg-config` --- ### 📝 Commits (1) - [`5165c33`](https://github.com/aome510/spotify-player/commit/5165c335c19cb624e42e79beb1deb91f5935c8dc) feat!: use XDG spec environment variables ### 📊 Changes **2 files changed** (+19 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `README.md` (+2 -2) 📝 `spotify_player/src/config/mod.rs` (+17 -4) </details> ### 📄 Description I noticed a while back that the default XDG base specification locations are hard coded. This PR changes the project to use the corresponding environment variables. <details> <summary> This is a now obsolete message, but let's keep it for context </summary> This was when considering to use the dirs-next crate: ~~As I comment in the commit message~~, it is a BREAKING CHANGE for users with the XDG_CONFIG_HOME variable set to one different from the default. Note that while the spec seems relatively Linux-centric, the dirs-next crate also uses recommended guidelines in both mac OS and Windows and so would ~~be breaking for possibly absolutely~~ affect all users. See the table: ``` Linux $XDG_CONFIG_HOME or $HOME/.config /home/alice/.config macOS $HOME/Library/Application Support /Users/Alice/Library/Application Support Windows {FOLDERID_RoamingAppData} C:\Users\Alice\AppData\Roaming ``` Obviously breaking all users' config is breaking for any release, so I thought about renaming the current files to whatever they would become after the new location, but that might just break other users, for all I know. (I'm looking at you, NixOS) </details> Then this is some contextual information from what other projects do: <details> Instead of doing that, a more reasonable solution is simply using the old config location in case it exists, or otherwise default to the new location. I think this is what git did ( https://git-scm.com/docs/git-config#Documentation/git-config.txt-XDGCONFIGHOMEgitconfig ), only they go on to read the non-compliant file anyway. <br> <br> It seem that while the convention is clearly defined in Linux, the situation is not so clear in MacOS, and somewhat in Windows. In Mac, ome people strongly prefer the platform recommended locations, and other strongly prefer the XDG ~/.config location. There's precendent: https://github.com/rust-lang/rfcs/pull/1615#issuecomment-221361170, https://github.com/dirs-dev/directories-rs/issues/47. Neovim seems to clump all Unix together, so they also use ~/.config for MacOS. On the opposite end is the `dirs-next` crate, which doesn't honor the XDG environment variables in MacOS: [docs](https://docs.rs/dirs-next/2.0.0/dirs_next/fn.cache_dir.html) </details> ## Current status This PR just detects if the XDG_CONFIG_HOME and XDG_CACHE_HOME environment variable are set. For compatibililty, if XDG_CONFIG_HOME is set but the old location exists, keep current behaviour. Cache is migrated to XDG_CACHE_HOME always. Given that the cache folder is not routinely accessed, this should not affect any users negatively. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotify-player#1667
No description provided.