Bug 31 - Use XDG_CONFIG_HOME for config folder
Summary: Use XDG_CONFIG_HOME for config folder
Status: RESOLVED FIXED
Alias: None
Product: Asunder
Classification: Unclassified
Component: All (show other bugs)
Version: 2.7
Hardware: PC Linux
: normal
Assignee: Andrew Smith
URL:
: 52 (view as bug list)
Depends on:
Blocks:
 
Reported: 2017-03-10 10:20 EST by Andreas Rönnquist
Modified: 2018-01-05 07:58 EST (History)
3 users (show)

See Also:


Attachments
patch to load config from g_get_user_config_dir (4.32 KB, patch)
2017-03-22 11:59 EDT, Andreas Rönnquist
Details | Diff
Updated patch to fix freeing filenames and fixing tabs (4.75 KB, patch)
2017-03-23 03:14 EDT, Andreas Rönnquist
Details | Diff
Fixes cache file locations (3.45 KB, patch)
2017-03-24 06:24 EDT, Andreas Rönnquist
Details | Diff

Description Andreas Rönnquist 2017-03-10 10:20:40 EST
I've got a bug report on the Debian asunder package saying:

> config for Asunder is spreaded under four different files in home directory.
> Should not that be under ~/.config/asunder ?

(https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=857359)

and looking at the freedesktop specification at 
https://specifications.freedesktop.org/basedir-spec/0.6/ar01s03.html
it says

> $XDG_CONFIG_HOME defines the base directory relative to which user specific
> configuration files should be stored. If $XDG_CONFIG_HOME is either not set
> or empty, a default equal to $HOME/.config should be used. 

I have found the glib function g_get_user_config_dir which looks like
a good candidate for this - or to be specific something like
g_get_user_config_dir() + "/asunder/<filename>"
should probably work fine.

https://developer.gnome.org/glib/unstable/glib-Miscellaneous-Utility-Functions.html#g-get-user-config-dir

(On the debian-machines I have tested, $XDG_CONFIG_HOME, which you use is empty, but g_get_user_config_dir returns ($HOME)/.config )
Would you accept patches for fixing this?
Comment 1 Andrew Smith 2017-03-10 19:02:19 EST
Hi Andreas

Do you know what 4 files they're talking about? I'm pretty sure it's just one.

I considered fixing this before, but the problem is it would take quite a bit of extra code to make sure that the new version of Asunder first loads the settings from old ~/.asunder before it switches to using the new file.

As far as I can tell there's no benefit whatsoever from using the new file location and I don't want to piss the users off by resetting their settings.

Do you have any suggestions for how to deal with that?

Andrew
Comment 2 Andreas Rönnquist 2017-03-11 03:18:12 EST
(In reply to Andrew Smith from comment #1)
> Hi Andreas
> 
> Do you know what 4 files they're talking about? I'm pretty sure it's just
> one.

I have .asunder, .asunder_album_artist, .asunder_album_genre and .asunder_album_title in my $HOME.


> I considered fixing this before, but the problem is it would take quite a
> bit of extra code to make sure that the new version of Asunder first loads
> the settings from old ~/.asunder before it switches to using the new file.
> 
> As far as I can tell there's no benefit whatsoever from using the new file
> location and I don't want to piss the users off by resetting their settings.

Yeah, surely it would be really bad to simply reset the user settings, there would have to be some kind of migration from the old to the new position, and that means some amount of code, yes...
Comment 3 Andrew Smith 2017-03-21 19:58:15 EDT
(In reply to Andreas Rönnquist from comment #2)
> I have .asunder, .asunder_album_artist, .asunder_album_genre and
> .asunder_album_title in my $HOME.
> 
Embarassingly I have no idea where those files are coming from. I wonder if libcddb creates them maybe? Sounds like a stretch but I have no recollection of ever working with these files.

> Yeah, surely it would be really bad to simply reset the user settings, there
> would have to be some kind of migration from the old to the new position,
> and that means some amount of code, yes...

Well, you asked if I would accept patches to deal with it - I certainly would if you wrote that code.
Comment 4 Andreas Rönnquist 2017-03-22 11:59:00 EDT
Created attachment 6 [details]
patch to load config from g_get_user_config_dir

I have made this patch, it loads in order from

1. g_get_config_dir
2. XDG_CONFIG_HOME
3. HOME/.asunder

but always saves to the g_get_config_dir location.
Please try it out - I am thinking if there should be
some dialog or something like that the first time the
config gets moved, but it might not be necessary.
Comment 5 Andrew Smith 2017-03-22 18:59:13 EDT
Thanks Andreas, looks very good. I also don't think a dialog is necessary.

Can you please fix a couple of things:

1) Since you're using g_build_filename(), those strings need to be later freed with g_free()
2) There are some tabs in your patch, please replace with spaces.
Comment 6 Andreas Rönnquist 2017-03-23 03:14:06 EDT
Created attachment 7 [details]
Updated patch to fix freeing filenames and fixing tabs

Here you go - this should look a bit better.
Comment 7 Andrew Smith 2017-03-23 17:55:47 EDT
Thanks!

I've checked it in with minor changes.

I found where the other .asunder* files are created, it's in completion.c

Currently it uses XDG_CACHE_HOME but of course on most systems that's not set to anything just as XDG_CONFIG_HOME is not set to anything. So they end up where they are.

Any chance you could modify completion_filename() to do as get_prefs_save_config_path() does and create ~/.cache/asunder/ before returning ~/.cache/asunder/asunder...?

I can do it if you don't have the time.
Comment 8 Andreas Rönnquist 2017-03-24 06:24:57 EDT
Created attachment 8 [details]
Fixes cache file locations

Alright, I have put together this, please take a look at it.
Comment 9 Andrew Smith 2017-03-24 18:48:26 EDT
Awesome, thanks! I've checked it in.

Your patches will be in the next release and I'll be adding you to the credits.
Comment 10 Oliver Kahrmann 2018-01-05 07:58:44 EST
*** Bug 52 has been marked as a duplicate of this bug. ***

Note You need to log in before you can comment on or make changes to this bug.