`g_settings_get_child` not compatible with `g_settings_schema_source_new_from_directory`
I am trying to patch a library to use hard-coded paths with g_settings_schema_source_new_from_directory
as we cannot override XDG_DATA_DIRS
environment variable. Unfortunately, the library uses g_settings_get_child
, which does not appear to inherit the schema source correctly.
Here is a simplified source code reproducing the issue with schemas from gsettings-desktop-schemas
package:
#include <glib.h>
#include <gio/gio.h>
int main(int argc, char const *argv[]) {
GSettingsSchemaSource *schema_source = g_settings_schema_source_new_from_directory("/projects/installed/gsettings-desktop-schemas/share/glib-2.0/schemas", NULL, TRUE, NULL);
GSettingsSchema *schema = g_settings_schema_source_lookup(schema_source, "org.gnome.system.proxy", FALSE);
if (schema == NULL) {
g_error("Unable to find schema.");
return 1;
}
GSettings* settings = g_settings_new_full(schema, NULL, NULL);
GVariant* value = g_settings_get_value(settings, "autoconfig-url");
// This correctly prints empty string
g_print("autoconfig-url: %s\n", g_variant_get_string(value, NULL));
GSettingsSchema *http_schema = g_settings_schema_source_lookup(schema_source, "org.gnome.system.proxy.http", FALSE);
if (http_schema == NULL) {
g_error("Unable to find http_schema.");
return 1;
}
GSettings* http_settings_direct = g_settings_new_full(http_schema, NULL, NULL);
GVariant* host_value_direct = g_settings_get_value(http_settings_direct, "host");
// This works okay too
g_print("Direct host: %s\n", g_variant_get_string(host_value_direct, NULL));
GSettings* http_settings_child = g_settings_get_child (settings, "http");
GVariant* host_value_child = g_settings_get_value(http_settings_child, "host");
// This fails with “No GSettings schemas are installed on the system”
g_print("Host from child: %s\n", g_variant_get_string(host_value_child, NULL));
// unrefs omitted here for brevity
return 0;
}
I am building it with gcc $(pkg-config --cflags --libs glib-2.0 gio-2.0) test.c -o test
and running it with env -i G_MESSAGES_DEBUG=all test
. If I add XDG_DATA_DIRS=/projects/installed/gsettings-desktop-schemas/share
, then the host from child is printed correctly, so the schema path is correct.
I am using Glib 2.60.6.