From 2b8f131599842d7d6249815412a261df6fa65d15 Mon Sep 17 00:00:00 2001 From: Ryan Lortie Date: Wed, 8 Apr 2015 21:55:58 -0400 Subject: [PATCH] gsettings: stay compatible with installed schemas Bug 747209 introduced an error when multiple or tags are found for a single key in a GSettings schema. This check should have been present from the start, but it was left out because the schema compiler doesn't include these items in the cache file. Even still -- part of the schema compiler's job is validation, and it should be enforcing proper syntax here. Repeated and tags are a semi-common problem when intltool has been misconfigured in the build system of a package, but it's possible to imagine mistakes being made by hand as well. The idea is that these problems would be caught during the build of a package and maintainers would be forced to fix their build systems. An unintended side-effect of this change, however, is that the schema compiler started ignoring already-installed schemas that contained these problems, when rebuilding the cache. This means that the installation of _any_ application would cause the regeneration of the entire cache, with these already-installed applications being excluded. Without the schema in the cache, the application would crash on next startup. The validation check in the gsettings m4 macro passes --strict to the compiler, which is not used when rebuilding the cache after installation. Pass this flag down into the parser and only throw the error in case --strict was given. This will result in the (desired) build failure without also causing already-installed apps to stop functioning. This means that we will not get even a warning about the invalid schema file in the already-installed case, but that's fine. There is no sense spamming the user with these messages when they are already quite fatal for the developer at build time. https://bugzilla.gnome.org/show_bug.cgi?id=747472 --- gio/glib-compile-schemas.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gio/glib-compile-schemas.c b/gio/glib-compile-schemas.c index 4e0604b80..a09ceae95 100644 --- a/gio/glib-compile-schemas.c +++ b/gio/glib-compile-schemas.c @@ -1063,6 +1063,8 @@ override_state_end (KeyState **key_state, /* Handling of toplevel state {{{1 */ typedef struct { + gboolean strict; /* TRUE if --strict was given */ + GHashTable *schema_table; /* string -> SchemaState */ GHashTable *flags_table; /* string -> EnumState */ GHashTable *enum_table; /* string -> EnumState */ @@ -1381,7 +1383,7 @@ start_element (GMarkupParseContext *context, else if (strcmp (element_name, "summary") == 0) { - if (state->key_state->summary_seen) + if (state->key_state->summary_seen && state->strict) g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, _("Only one <%s> element allowed inside <%s>"), element_name, container); @@ -1394,7 +1396,7 @@ start_element (GMarkupParseContext *context, else if (strcmp (element_name, "description") == 0) { - if (state->key_state->description_seen) + if (state->key_state->description_seen && state->strict) g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, _("Only one <%s> element allowed inside <%s>"), element_name, container); @@ -1721,6 +1723,8 @@ parse_gschema_files (gchar **files, const gchar *filename; GError *error = NULL; + state.strict = strict; + state.enum_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, enum_state_free);