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
base: master
Are you sure you want to change the base?
Make settings directory follow xdg specification #472
Conversation
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.
There was a problem hiding this 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())); |
There was a problem hiding this comment.
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.)
if (System.getenv("XDG_CONFIG_DIR") != null) { | ||
dir = System.getenv("XDG_CONFIG_DIR") |
There was a problem hiding this comment.
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.)
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 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 Alright! I have been poking at some code to implement |
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 whatevergetUserDataDirectory
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
.