gsettings: check $XDG_DATA_HOME for schemas

Add $XDG_DATA_HOME/glib-2.0/schemas as a schema source, after (higher
priority than) $XDG_DATA_DIRS/glib-2.0/schemas but before
$GSETTINGS_SCHEMA_DIR. This is per the XDG Base Directory Specification,
which states that user specific versions of data in $XDG_DATA_DIRS can
be created in $XDG_DATA_HOME.

https://bugzilla.gnome.org/show_bug.cgi?id=741335
This commit is contained in:
Ryan Hendrickson 2017-05-19 15:44:14 -04:00 committed by Philip Withnall
parent 3de1fac392
commit 151d3b01e6
2 changed files with 11 additions and 6 deletions

View File

@ -321,6 +321,14 @@ try_prepend_dir (const gchar *directory)
schema_sources = source; schema_sources = source;
} }
static void
try_prepend_data_dir (const gchar *directory)
{
const gchar *dirname = g_build_filename (directory, "glib-2.0", "schemas", NULL);
try_prepend_dir (dirname);
g_free (dirname);
}
static void static void
initialise_schema_sources (void) initialise_schema_sources (void)
{ {
@ -340,13 +348,9 @@ initialise_schema_sources (void)
for (i = 0; dirs[i]; i++); for (i = 0; dirs[i]; i++);
while (i--) while (i--)
{ try_prepend_data_dir (dirs[i]);
gchar *dirname;
dirname = g_build_filename (dirs[i], "glib-2.0", "schemas", NULL); try_prepend_data_dir (g_get_user_data_dir ());
try_prepend_dir (dirname);
g_free (dirname);
}
if ((path = g_getenv ("GSETTINGS_SCHEMA_DIR")) != NULL) if ((path = g_getenv ("GSETTINGS_SCHEMA_DIR")) != NULL)
try_prepend_dir (path); try_prepend_dir (path);

View File

@ -2613,6 +2613,7 @@ main (int argc, char *argv[])
backend_set = g_getenv ("GSETTINGS_BACKEND") != NULL; backend_set = g_getenv ("GSETTINGS_BACKEND") != NULL;
g_setenv ("XDG_DATA_DIRS", ".", TRUE); g_setenv ("XDG_DATA_DIRS", ".", TRUE);
g_setenv ("XDG_DATA_HOME", ".", TRUE);
g_setenv ("GSETTINGS_SCHEMA_DIR", ".", TRUE); g_setenv ("GSETTINGS_SCHEMA_DIR", ".", TRUE);
if (!backend_set) if (!backend_set)