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

Make settings directory follow xdg specification #472

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yoshiyoshyosh
Copy link

@yoshiyoshyosh yoshiyoshyosh commented Jul 7, 2022

Would close #273

This commit changes getUserDataDirectory to return $XDG_CONFIG_HOME/chatty/, or (user.home)/.config/chatty/ if $XDG_CONFIG_HOME doesn't exist.
In addition, this commit will cause Chatty to, on startup, detect if the legacy settings directory exists ((user.home)/.chatty) and, if it does, move it to whatever getUserDataDirectory returns. It does this on startup such that the new settings directory can be taken into effect without needing to restart the client.

This commit should be treated as a first-draft implementation of the idea. It works for a basic end-user case, but may suffer from Hyrum's Law if anyone is using scripts to read their settings directory. Should there be a deprecation notification? Perhaps just stick it in the auto-opening release notes in big bold text? Should there be support for both the legacy and XDG directory, and let current users move it if they wish, while having new users use the XDG path? There's many factors to consider when migrating to XDG standards after having a legacy directory for so long.

This was tested on a Linux environment with both XDG_CONFIG_HOME set and unset. Windows environments would also get the (user.home)/.chatty directory moved to (user.home)/.config/chatty.

This commit changes `getUserDataDirectory` to return `$XDG_CONFIG_HOME/chatty`, or `$HOME/.config/chatty` if `$XDG_CONFIG_HOME` doesn't exist.
In addition, this commit will cause Chatty to, on startup, detect if the legacy settings directory exists ($HOME/.chatty) and, if it does, move it to whatever `getUserDataDirectory` returns. It does this on startup such that the new settings directory can be taken into effect without needing to restart the client, making for a seamless transition.
Copy link

@Freso Freso left a comment

Choose a reason for hiding this comment

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

I really like the idea of this, but I noted a couple of small issues that should probably be considered before going ahead. :)

// Check if the legacy settings directory exists and move it to follow XDG specifications
File legacySettingsDir = new File(System.getProperty("user.home") + File.separator + ".chatty");
if (legacySettingsDir.exists()) {
legacySettingsDir.renameTo(new File(getUserDataDirectory()));
Copy link

Choose a reason for hiding this comment

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

What will happen here if ~/.chatty is a link and $XDG_CONFIG_HOME/chatty already exists?

# ls -Ald ~/.chatty
lrwxrwxrwx 1 freso freso 14 15 jul  2018 /home/freso/.chatty -> .config/chatty/

Maybe this could check for whether getUserDataDirectory() already exists? Or check that legacySettingsDir is, in fact, a directory? (Or both?)

(Alternatively, this move could also be dropped and instead there could be logic to also search ~/.chatty if it exists and {$XDG_CONFIG_HOME,~/.config}/chatty do not? That would require users to move manually but would also mean no unexpected/unsupervised changes to their $HOME directories. New users should get the $XDG_CONFIG_HOME directory though.)

Comment on lines +245 to +246
if (System.getenv("XDG_CONFIG_DIR") != null) {
dir = System.getenv("XDG_CONFIG_DIR")
Copy link

Choose a reason for hiding this comment

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

This should be XDG_CONFIG_HOME. (There is no XDG_CONFIG_DIR in the specification and XDG_CONFIG_DIRS is not really appropriate here, though ideally that should also be searched… but that’s a whole different subject to tackle than what this PR sets out to do.)

Suggested change
if (System.getenv("XDG_CONFIG_DIR") != null) {
dir = System.getenv("XDG_CONFIG_DIR")
if (System.getenv("XDG_CONFIG_HOME") != null) {
dir = System.getenv("XDG_CONFIG_HOME")

@Freso
Copy link

Freso commented Sep 5, 2023

Would close #273

This only fixes the $XDG_CONFIG_HOME part of #273 – not the CACHE or DATA parts.

@yoshiyoshyosh
Copy link
Author

yoshiyoshyosh commented Sep 7, 2023

@Freso forgot that I had this pull request open--though it seems that the code surrounding the settings directory has changed a bit. I might (?) look at this again and modify it to reflect the new code (and to /actually/ follow XDG instead of... whatever I was doing), but I am very much not skilled at java, so it'd at least be a while before I sit down and rework this idea :)

@yoshiyoshyosh yoshiyoshyosh marked this pull request as draft September 10, 2023 18:34
@Freso
Copy link

Freso commented Sep 17, 2023

@yoshiyoshyosh Alright! I have been poking at some code to implement $XDG_CACHE_HOME. I can probably continue on from that work to do $XDG_CONFIG_HOME too. Maybe I’ll do $XDG_DATA_HOME too, we’ll see. 🤔

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.

Chatty config-, cache- and data-directories on Linux
2 participants