treesheets icon indicating copy to clipboard operation
treesheets copied to clipboard

Please use $XDG_CONFIG_HOME on unix

Open ptman opened this issue 4 years ago • 17 comments

And other XDG dirs: https://www.freedesktop.org/wiki/Software/xdg-user-dirs/ https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html

ptman avatar May 14 '20 08:05 ptman

Use them where? For what? How universal are these things on Linux? I have not heard about any of this before.

aardappel avatar May 14 '20 18:05 aardappel

Quite widely used. Take a look in your $HOME/.config/ (the default location for $XDG_CONFIG_HOME). There must be an almost infinite amount of things I haven't heard of either.

ptman avatar May 14 '20 19:05 ptman

It is rather standardized in systemd-based distributions (which nowadays translates to Debian/RHEL/SUSE and their derivatives like Ubuntu/Fedora/CentoOS/etc).

savchenko avatar May 18 '20 00:05 savchenko

Would be nice to reduce clutter in the home folder. It is roughly analogous to using %APPDATA% on Windows instead of dumping files on the desktop.

Some examples:

  • git uses $XDG_CONFIG_HOME (the "fairly recently" line was written in 2012).
  • All currently maintained GNOME and KDE apps should be using it for a few years now.
  • VSCode uses $HOME/.config (proper support for XDG still pending).

A typical order of locations to check would be:

  1. $XDG_CONFIG_HOME/TreeSheets/ (with the file being named simply config);
  2. if $XDG_CONFIG_HOME is undefined, $HOME/.config/Treesheets/;
  3. if above two locations do not exist, use ~/.TreeSheets

I am not that familiar with wxWidget but it appears to support using XDG dirs since 3.1.1.

jn64 avatar May 28 '20 12:05 jn64

Well, I don't determine the path or filename of the config data on Linux, that is all in wxWidgets. On Windows it goes into the registry, for example. So sounds like if you would build with 3.1.1 you'd automatically get the functionality requested?

The new TreeSheets CI builds with tip of tree wxWidgets, so should be more recent than 3.1.1: https://github.com/aardappel/treesheets/actions/runs/116985613 Not sure about the Snap build etc.

aardappel avatar May 28 '20 15:05 aardappel

Using Linux TreeSheets g++-9 build from the above link, it still creates ~/.TreeSheets (I deleted it to simulate first run). Maybe you need to set this as it's stated

This [classic file layout] is the default behaviour for compatibility reasons.

jn64 avatar May 28 '20 17:05 jn64

Let's see if this helps (untested): https://github.com/aardappel/treesheets/commit/c72a884a5109dd5804333aae7eb7674f5ae35c8f

CI builds: https://github.com/aardappel/treesheets/actions/runs/118487009

aardappel avatar May 29 '20 00:05 aardappel

Ok, new version of that same commit, since our Travis CI isn't set up to build with versions that new: https://github.com/aardappel/treesheets/commit/6f1f5b272b9e4818a92f6511f615988a8e205559

aardappel avatar May 29 '20 01:05 aardappel

Ok, with Linux TreeSheets g++-9 build 6f1f5b2, the config file is now created at $XDG_CONFIG_HOME/TreeSheets.conf

It ignores if ~/.TreeSheets already exists and always creates at the new location. IMO that is an acceptable breaking change for bleeding edge software like TS, and preferable for new TS users on mainstream distros in the long run.

However, with TreeSheets-6f1f5b2-x86_64.AppImage, it still creates the config file at ~/.TreeSheets.

jn64 avatar May 29 '20 06:05 jn64

I think in order to provide a migration path, existing configs should be looked up in both the old location and $XDG_CONFIG_HOME before deciding to create a new config in $XDG_CONFIG_HOME.

ptman avatar May 29 '20 08:05 ptman

@jn64 Yes, I was thinking this means Linux users will have their config reset. I guess they can manually move it to the new location if needed. TreeSheets is not that rich in config options that it will matter for most.

Funny you call TreeSheets "bleeding edge", it's been in development since 2008 and has been largely stable for the last 5+ years.

Not sure why the AppImage still does the old thing.. presumably whatever code wxWidgets has to detect XDG location doesn't work inside an AppImage? So far my impression of AppImage is that quite a lot of things work differently from a regular Linux environment. @probonopd may know why. AppImage created here if anyone wants to improve it: https://github.com/aardappel/treesheets/blob/6f1f5b272b9e4818a92f6511f615988a8e205559/.travis.yml#L89-L117

aardappel avatar May 29 '20 15:05 aardappel

@ptman if you look at the code in https://github.com/aardappel/treesheets/commit/6f1f5b272b9e4818a92f6511f615988a8e205559 you'll see that I have absolutely no control over how these config locations are used.. There's no option to look up in both.

aardappel avatar May 29 '20 15:05 aardappel

Well if "bleeding edge" is the wrong word I just mean it's a "dev version" and I accept the risk that such changes can happen. Thanks for the change!

jn64 avatar May 29 '20 16:05 jn64

Not sure why the AppImage still does the old thing..

https://github.com/aardappel/treesheets/releases/tag/continuous is working or me (it launches). What exactly would you like to see changed with the AppImage?

The AppRun file inside the TreeSheets AppImage exports XDG_DATA_DIRS as we can see:

me@host:~$ Downloads/TreeSheets-6f1f5b2-x86_64.AppImage --appimage-extract AppRun
squashfs-root/AppRun
me@host:~$ strings squashfs-root/AppRun | grep XDG_
XDG_DATA_DIRS
XDG_DATA_DIRS=%s/usr/share/:%s

The code responsible for this is at

https://github.com/AppImage/AppImageKit/blob/fef038a6283701f6976589bf7becf975b020d453/src/AppRun.c#L180-L181

Would you like to see another behavior?

probonopd avatar May 30 '20 08:05 probonopd

Hi @probonopd, the issue is about where TreeSheets puts its config file (via wxWidgets).

  1. Previously, it puts it at ~/.TreeSheets

  2. After 6f1f5b2, the normal Linux builds of TreeSheets put it at $XDG_CONFIG_HOME/TreeSheets.conf. This is the desired behaviour and all is well.

  3. Except, the AppImage still puts it at ~/.TreeSheets. So the question is why isn't it behaving like 2).


Note: XDG_CONFIG_HOME not XDG_DATA_DIRS

jn64 avatar May 30 '20 08:05 jn64

Are you sure that XDG_CONFIG_HOME is set to something?

probonopd avatar May 30 '20 09:05 probonopd

In my env yes (because I've had it set for a long time and other programs work as expected). If you mean in the AppImage I don't know.

At any rate 2) happened, and my environment didn't change between 2) and 3).

jn64 avatar May 30 '20 09:05 jn64