[gnome-software/gnome-3-32] Always use the old AppStream component type names



commit 23c10e78b3c370b8f5dc2554befbd7bde5d8b38f
Author: Richard Hughes <richard hughsie com>
Date:   Wed Jun 12 14:46:55 2019 +0100

    Always use the old AppStream component type names
    
    The upstream specification 'broke API' (which is partially my fault for using
    the types before they were accepted upstream) which means we need to convert
    'legacy' AppData files to avoid having to use a union query when finding
    components.
    
    I chose to use the old names rather than fixing up all the different places
    where we refer to a 'webapp' or 'console' type app.

 plugins/core/gs-plugin-appstream.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
---
diff --git a/plugins/core/gs-plugin-appstream.c b/plugins/core/gs-plugin-appstream.c
index 4b587d56..dfdb95ec 100644
--- a/plugins/core/gs-plugin-appstream.c
+++ b/plugins/core/gs-plugin-appstream.c
@@ -56,6 +56,16 @@ gs_plugin_destroy (GsPlugin *plugin)
        g_rw_lock_clear (&priv->silo_lock);
 }
 
+static const gchar *
+gs_plugin_appstream_convert_component_kind (const gchar *kind)
+{
+       if (g_strcmp0 (kind, "web-application") == 0)
+               return "webapp";
+       if (g_strcmp0 (kind, "console-application") == 0)
+               return "console";
+       return kind;
+}
+
 static gboolean
 gs_plugin_appstream_upgrade_cb (XbBuilderFixup *self,
                                XbBuilderNode *bn,
@@ -74,6 +84,11 @@ gs_plugin_appstream_upgrade_cb (XbBuilderFixup *self,
                xb_builder_node_set_element (bn, "component");
        } else if (g_strcmp0 (xb_builder_node_get_element (bn), "metadata") == 0) {
                xb_builder_node_set_element (bn, "custom");
+       } else if (g_strcmp0 (xb_builder_node_get_element (bn), "component") == 0) {
+               const gchar *type_old = xb_builder_node_get_attr (bn, "type");
+               const gchar *type_new = gs_plugin_appstream_convert_component_kind (type_old);
+               if (type_old != type_new)
+                       xb_builder_node_set_attr (bn, "type", type_new);
        }
        return TRUE;
 }
@@ -145,7 +160,7 @@ gs_plugin_appstream_load_appdata_fn (GsPlugin *plugin,
        }
 
        /* fix up any legacy installed files */
-       fixup = xb_builder_fixup_new ("AppStreamUpgrade",
+       fixup = xb_builder_fixup_new ("AppStreamUpgrade2",
                                      gs_plugin_appstream_upgrade_cb,
                                      plugin, NULL);
        xb_builder_fixup_set_max_depth (fixup, 3);
@@ -359,7 +374,7 @@ gs_plugin_appstream_load_appstream_fn (GsPlugin *plugin,
        xb_builder_source_add_fixup (source, fixup1);
 
        /* fix up any legacy installed files */
-       fixup2 = xb_builder_fixup_new ("AppStreamUpgrade",
+       fixup2 = xb_builder_fixup_new ("AppStreamUpgrade2",
                                       gs_plugin_appstream_upgrade_cb,
                                       plugin, NULL);
        xb_builder_fixup_set_max_depth (fixup2, 3);


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