[gnome-software/wip/hughsie/libxmlb: 13/13] Ensure the flatpak <id> matches the <bundle>
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/hughsie/libxmlb: 13/13] Ensure the flatpak <id> matches the <bundle>
- Date: Tue, 16 Oct 2018 16:46:49 +0000 (UTC)
commit 0dfb40d756804311792baf03e5c7c58451359c12
Author: Richard Hughes <richard hughsie com>
Date: Tue Oct 16 12:14:00 2018 +0100
Ensure the flatpak <id> matches the <bundle>
For instance, com.github.fabiocolacio.marker can't decide if the app ID should
contain a trailing .desktop or not.
plugins/core/gs-appstream.c | 19 +++++++++++++++++++
plugins/core/gs-appstream.h | 2 ++
plugins/flatpak/gs-flatpak.c | 30 ++++++++++++++++++++++++++++++
3 files changed, 51 insertions(+)
---
diff --git a/plugins/core/gs-appstream.c b/plugins/core/gs-appstream.c
index 5bfb0e0b..a2ef9d14 100644
--- a/plugins/core/gs-appstream.c
+++ b/plugins/core/gs-appstream.c
@@ -1374,6 +1374,25 @@ gs_appstream_component_add_keyword (XbBuilderNode *component, const gchar *str)
}
}
+void
+gs_appstream_component_add_provide (XbBuilderNode *component, const gchar *str)
+{
+ g_autoptr(XbBuilderNode) provide = NULL;
+ g_autoptr(XbBuilderNode) provides = NULL;
+
+ /* create <provides> if it does not already exist */
+ provides = xb_builder_node_get_child (component, "provides", NULL);
+ if (provides == NULL)
+ provides = xb_builder_node_insert (component, "provides", NULL);
+
+ /* create <id>str</id> if it does not already exist */
+ provide = xb_builder_node_get_child (provides, "id", str);
+ if (provide == NULL) {
+ provide = xb_builder_node_insert (provides, "id", NULL);
+ xb_builder_node_set_text (provide, str, -1);
+ }
+}
+
void
gs_appstream_component_add_category (XbBuilderNode *component, const gchar *str)
{
diff --git a/plugins/core/gs-appstream.h b/plugins/core/gs-appstream.h
index 44ba1132..99d89464 100644
--- a/plugins/core/gs-appstream.h
+++ b/plugins/core/gs-appstream.h
@@ -84,6 +84,8 @@ void gs_appstream_component_add_category (XbBuilderNode *component,
const gchar *str);
void gs_appstream_component_add_icon (XbBuilderNode *component,
const gchar *str);
+void gs_appstream_component_add_provide (XbBuilderNode *component,
+ const gchar *str);
G_END_DECLS
diff --git a/plugins/flatpak/gs-flatpak.c b/plugins/flatpak/gs-flatpak.c
index 76a5b83f..ab8e2962 100644
--- a/plugins/flatpak/gs-flatpak.c
+++ b/plugins/flatpak/gs-flatpak.c
@@ -205,6 +205,31 @@ gs_flatpak_add_flatpak_keyword_cb (XbBuilderSource *self,
return TRUE;
}
+static gboolean
+gs_flatpak_fix_id_desktop_suffix_cb (XbBuilderSource *self,
+ XbBuilderNode *bn,
+ gpointer user_data,
+ GError **error)
+{
+ if (g_strcmp0 (xb_builder_node_get_element (bn), "component") == 0) {
+ g_auto(GStrv) split = NULL;
+ g_autoptr(XbBuilderNode) id = xb_builder_node_get_child (bn, "id", NULL);
+ g_autoptr(XbBuilderNode) bundle = xb_builder_node_get_child (bn, "bundle", NULL);
+ if (id == NULL || bundle == NULL)
+ return TRUE;
+ split = g_strsplit (xb_builder_node_get_text (bundle), "/", -1);
+ if (g_strv_length (split) != 4)
+ return TRUE;
+ if (g_strcmp0 (xb_builder_node_get_text (id), split[1]) != 0) {
+ g_debug ("fixing up <id>%s</id> to %s",
+ xb_builder_node_get_text (id), split[1]);
+ gs_appstream_component_add_provide (bn, xb_builder_node_get_text (id));
+ xb_builder_node_set_text (id, split[1], -1);
+ }
+ }
+ return TRUE;
+}
+
static gboolean
gs_flatpak_set_origin_cb (XbBuilderSource *self,
XbBuilderNode *bn,
@@ -315,6 +340,11 @@ gs_flatpak_add_apps_from_xremote (GsFlatpak *self,
gs_flatpak_add_flatpak_keyword_cb,
self, NULL);
+ /* ensure the <id> matches the flatpak ref ID */
+ xb_builder_source_add_node_func (source, "FixIdDesktopSuffix",
+ gs_flatpak_fix_id_desktop_suffix_cb,
+ self, NULL);
+
/* override the *AppStream* origin */
xb_builder_source_add_node_func (source, "SetOrigin",
gs_flatpak_set_origin_cb,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]