After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 741335 - Possible differences in use of XDG_DATA_DIRS versus XDG base directory specification
Possible differences in use of XDG_DATA_DIRS versus XDG base directory specif...
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gsettings
unspecified
Other Linux
: Normal enhancement
: ---
Assigned To: Allison Karlitskaya (desrt)
gtkdev
Depends on:
Blocks:
 
 
Reported: 2014-12-10 13:08 UTC by Christian Luginbühl
Modified: 2017-07-12 19:57 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gsettings: check $XDG_DATA_HOME for schemas (2.05 KB, patch)
2017-05-19 20:18 UTC, Ryan Hendrickson
committed Details | Review

Description Christian Luginbühl 2014-12-10 13:08:48 UTC
I was playing around with .gschema.xml files while developing a gedit plugin. A plugin can be installed locally, but when trying to save settings using the gsettings facilities one seems to be forced to be root to install the .gschema.xml file.

I was therefore looking for a good way to work around this, but found a possible difference in the use of XDG_DATA_DIRS in gsettings versus how the XDG base directory specification sees the use of it (see https://developer.gnome.org/basedir-spec/). 

This is at least what I understand reading the specification and what I would like to start a discussion here.

The XDG base specification states: 

### START CITATION ###
Referencing this specification
------------------------------

Other specifications may reference this specification by specifying the location of a data file as $XDG_DATA_DIRS/subdir/filename. This implies that:

    Such file should be installed to $datadir/subdir/filename with $datadir defaulting to /usr/share.

    A user specific version of the data file may be created in $XDG_DATA_HOME/subdir/filename, taking into account the default value for $XDG_DATA_HOME if $XDG_DATA_HOME is not set.

    Lookups of the data file should search for ./subdir/filename relative to all base directories specified by $XDG_DATA_HOME and $XDG_DATA_DIRS . If an environment variable is either not set or empty, its default value as defined by this specification should be used instead. 
### END CITATION ###

The last paragraph tells me, that whenever a specification talks about looking in a XDG_DATA_DIRS subdirectory, also XDG_BASE_HOME (defaulting to "$HOME/.local.share/" if unset) should be taken into account. 

Expected:
---------

When I put my .gschema.xml files in $HOME/.local/share/glib-2.0/schemas/ and compile them using 'glib-compile-schemas' I would expect 'gsettings list-schemas' to list these too.

Actual:
-------

gsettings does not list these, as this CLI output shows:

$ echo $XDG_DATA_HOME

$ echo $XDG_DATA_DIRS
/usr/share/xubuntu:/usr/share/xfce4:/usr/local/share/:/usr/share/
$ pwd
/home/dinkel/.local/share/glib-2.0/schemas
$ ls
org.gnome.gedit.plugins.whitespace-remover.gschema.xml
$ glib-compile-schemas .
$ ls
gschemas.compiled  org.gnome.gedit.plugins.whitespace-remover.gschema.xml
$ gsettings list-schemas | grep 'whitespace-remover'
$ export XDG_DATA_HOME=$HOME/.local/share/
$ echo $XDG_DATA_HOME
/home/dinkel/.local/share/
$ gsettings list-schemas | grep 'whitespace-remover'

Note:
-----

When adding $XDG_DATA_HOME as a new directory to the $XDG_DATA_DIRS directories everything seems to work perfectly well:

$ export XDG_DATA_DIRS=$XDG_DATA_HOME:$XDG_DATA_DIRS
$ echo $XDG_DATA_DIRS
/home/dinkel/.local/share/:/usr/share/xubuntu:/usr/share/xfce4:/usr/local/share/:/usr/share/
$ gsettings list-schemas | grep 'whitespace-remover'
org.gnome.gedit.plugins.whitespace-remover

It is my understanding that a fix towards first looking into $XDG_DATA_HOME (or '$HOME/.local/share/' if not set) would conform to the specification and eases plugin development not only for gedit but also for Gnome3 shell extensions (which according to google suffer too from the current limitation).
Comment 1 Ryan Hendrickson 2017-05-19 20:18:06 UTC
Created attachment 352186 [details] [review]
gsettings: check $XDG_DATA_HOME for schemas

This certainly seems like a bug to me! I scanned glib's source, and unless I missed something, every use of XDG_DATA_DIRS is accompanied by a use of XDG_DATA_HOME except in this one place, initializing schema sources. So, please accept this lovingly crafted patch to address said exception and fix the issue.
Comment 2 Philip Withnall 2017-05-22 08:17:34 UTC
Review of attachment 352186 [details] [review]:

Looks good to me, thanks.
Comment 3 Philip Withnall 2017-05-22 08:18:47 UTC
Attachment 352186 [details] pushed as 151d3b0 - gsettings: check $XDG_DATA_HOME for schemas
Comment 4 Daniel Boles 2017-07-12 18:38:40 UTC
Review of attachment 352186 [details] [review]:

::: gio/gsettingsschema.c
@@ +325,3 @@
+try_prepend_data_dir (const gchar *directory)
+{
+  const gchar *dirname = g_build_filename (directory, "glib-2.0", "schemas", NULL);

This function returns a non-const gchar*, and trying to free this const one led to a compiler warning about constness being cast away. I fixed that here: https://git.gnome.org/browse/glib/commit/?id=5eededccda6236cd307b0f0bcc852e495e9fd8f8
Comment 5 Ryan Hendrickson 2017-07-12 19:57:25 UTC
Ah, good catch, thank you for fixing!