[glib: 1/2] Support multiple directories in GSETTINGS_SCHEMA_DIR



commit 809a9210c338b384ab511f419af8a4d8ce967a7b
Author: wouter bolsterlee <wouter bolsterl ee>
Date:   Fri Jan 10 19:39:10 2020 +0100

    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.

 docs/reference/gio/overview.xml |  7 +++----
 gio/gsettingsschema.c           | 11 ++++++++++-
 2 files changed, 13 insertions(+), 5 deletions(-)
---
diff --git a/docs/reference/gio/overview.xml b/docs/reference/gio/overview.xml
index 960cd2fc1..9d013267e 100644
--- a/docs/reference/gio/overview.xml
+++ b/docs/reference/gio/overview.xml
@@ -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>
 
       <para>
-        This variable can be set to the name of a directory that is
-        considered in addition to the <filename>glib-2.0/schemas</filename>
-        subdirectories of the XDG system data dirs when looking
-        for compiled schemas for #GSettings.
+        This variable can be set to the names of directories to consider when looking for compiled schemas 
for #GSettings,
+        in addition to the <filename>glib-2.0/schemas</filename>
+        subdirectories of the XDG system data dirs. To specify multiple directories, use 
<constant>G_SEARCHPATH_SEPARATOR_S</constant> as a separator.
       </para>
     </formalpara>
 
diff --git a/gio/gsettingsschema.c b/gio/gsettingsschema.c
index 7b1915bdd..0b94f76f6 100644
--- a/gio/gsettingsschema.c
+++ b/gio/gsettingsschema.c
@@ -345,6 +345,7 @@ initialise_schema_sources (void)
     {
       const gchar * const *dirs;
       const gchar *path;
+      gchar **extra_schema_dirs;
       gint i;
 
       /* 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 ());
 
       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);
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]