Support multiple directories in GSETTINGS_SCHEMA_DIR

This adds support for specifying multiple directories in the
GSETTINGS_SCHEMA_DIR environment variable by separating the values
using G_SEARCHPATH_SEPARATOR_S (colon on UNIX-like systems).

While programs could already register multiple custom GSettings schema
directories, it was not possible to achieve the same without writing
custom code, e.g. when using the gsettings command line tool.

Fixes #1998.
This commit is contained in:
wouter bolsterlee 2020-01-10 19:39:10 +01:00 committed by Philip Withnall
parent 321fea1c5e
commit 809a9210c3
2 changed files with 13 additions and 5 deletions

View File

@ -466,10 +466,9 @@ Gvfs is also heavily distributed and relies on a session bus to be present.
<title><envar>GSETTINGS_SCHEMA_DIR</envar></title> <title><envar>GSETTINGS_SCHEMA_DIR</envar></title>
<para> <para>
This variable can be set to the name of a directory that is This variable can be set to the names of directories to consider when looking for compiled schemas for #GSettings,
considered in addition to the <filename>glib-2.0/schemas</filename> in addition to the <filename>glib-2.0/schemas</filename>
subdirectories of the XDG system data dirs when looking subdirectories of the XDG system data dirs. To specify multiple directories, use <constant>G_SEARCHPATH_SEPARATOR_S</constant> as a separator.
for compiled schemas for #GSettings.
</para> </para>
</formalpara> </formalpara>

View File

@ -345,6 +345,7 @@ initialise_schema_sources (void)
{ {
const gchar * const *dirs; const gchar * const *dirs;
const gchar *path; const gchar *path;
gchar **extra_schema_dirs;
gint i; gint i;
/* iterate in reverse: count up, then count down */ /* iterate in reverse: count up, then count down */
@ -357,7 +358,15 @@ initialise_schema_sources (void)
try_prepend_data_dir (g_get_user_data_dir ()); try_prepend_data_dir (g_get_user_data_dir ());
if ((path = g_getenv ("GSETTINGS_SCHEMA_DIR")) != NULL) if ((path = g_getenv ("GSETTINGS_SCHEMA_DIR")) != NULL)
try_prepend_dir (path); {
extra_schema_dirs = g_strsplit (path, G_SEARCHPATH_SEPARATOR_S, 0);
for (i = 0; extra_schema_dirs[i]; i++);
while (i--)
try_prepend_dir (extra_schema_dirs[i]);
g_strfreev (extra_schema_dirs);
}
g_once_init_leave (&initialised, TRUE); g_once_init_leave (&initialised, TRUE);
} }