[gnome-software/uajain/fix-real-appdata-query] appstream: Also query the real appdata files during refine



commit 541632f6f58241e7ef37cab29e4521905caf75d8
Author: Umang Jain <mailumangjain gmail com>
Date:   Wed Sep 11 22:21:37 2019 +0530

    appstream: Also query the real appdata files during refine
    
    Appstream plugin tries to source two XML file for an installed
    app. The first one is the real appdata file (typically present
    at /usr/share/metainfo or similar) and another XML representation
    sourced from the `.desktop` file of the app present at
    `/usr/share/applications`.
    
    During construction of the latter XML representation, appstream
    plugin adds a fixup XML node <pkgname> into the XML. This XML
    representation was then pushed into the silo.
    
    However, during gs_plugin_refine_app, only the latter XML
    representation of the `.desktop` file was queried and the
    components from the real appdata file (at /usr/share/metainfo
    or similar) were skipped. This is evident by looking at the XbSilo
    query which includes components only with <pkgname> tags.
    
    Hence, append the XbSilo query to also include the components
    for app-refine from the real appdata. <description> tag is good
    enough to know if the component is coming from the real appdata.
    
    The bug was noticed inside Endless app-center when the list of
    all installed system apps was missing. This was due to the missing
    description in the GsApp and the gs-installed-page refuse to
    consider those GsApps are real apps.
    
    https://phabricator.endlessm.com/T27668

 lib/gs-self-test.c                 | 73 ++++++++++++++++++++++++++++++++++++++
 lib/meson.build                    |  3 +-
 plugins/core/gs-plugin-appstream.c |  1 +
 3 files changed, 76 insertions(+), 1 deletion(-)
---
diff --git a/lib/gs-self-test.c b/lib/gs-self-test.c
index 7ac66c9e..9793587c 100644
--- a/lib/gs-self-test.c
+++ b/lib/gs-self-test.c
@@ -11,6 +11,7 @@
 #include "gnome-software-private.h"
 
 #include "gs-test.h"
+#include <xmlb.h>
 
 static gboolean
 gs_app_list_filter_cb (GsApp *app, gpointer user_data)
@@ -705,6 +706,77 @@ gs_app_list_wildcard_dedupe_func (void)
        g_assert_cmpint (gs_app_list_length (list), ==, 1);
 }
 
+/* Tests if an app's appdata, not present in appstream, still makes it to the xmlb silo.
+ * This confirms that the standalone appdata will be eventually converted to be an GsApp. */
+static void
+gs_app_is_actual_app_func (void)
+{
+       g_autoptr(XbBuilder) builder = xb_builder_new ();
+       g_autoptr(XbBuilderSource) source1 = xb_builder_source_new();
+       g_autoptr(XbBuilderSource) source2 = xb_builder_source_new();
+       g_autoptr(GString) xpath = g_string_new (NULL);
+       g_autoptr(GPtrArray) components = NULL;
+       g_autoptr(XbSilo) silo = NULL;
+       const gchar *appdata;
+       const gchar *appstream;
+       g_autoptr(GFile) xmlb = NULL;
+       g_autoptr(GError) error = NULL;
+
+       appdata = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+                 "<component type=\"desktop\">\n"
+                 "<id>appA.desktop</id>\n"
+                 "<metadata_license>CC0-1.0</metadata_license>\n"
+                 "<project_license>GPL-2.0+</project_license>\n"
+                 "<name>app A</name>\n"
+                 "<summary>app A summary</summary>\n"
+                 "<description>app A description</description>\n"
+                 "</component>\n";
+
+       appstream = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+                   "<components version=\"0.8\" origin=\"org\">\n"
+                   "<component type=\"desktop\">\n"
+                   "<id>appB.desktop</id>\n"
+                   "<metadata_license>CC0-1.0</metadata_license>\n"
+                   "<project_license>GPL-2.0+</project_license>\n"
+                   "<name>app B</name>\n"
+                   "<summary>app B summary</summary>\n"
+                   "<description>app B description</description>\n"
+                   "</component>\n"
+                   "<component type=\"desktop\">\n"
+                   "<id>appC.desktop</id>\n"
+                   "<metadata_license>CC0-1.0</metadata_license>\n"
+                   "<project_license>GPL-2.0+</project_license>\n"
+                   "<name>app C</name>\n"
+                   "<summary>app C summary</summary>\n"
+                   "<description>app C description</description>\n"
+                   "</component>\n"
+                   "</components>\n";
+
+       xb_builder_source_load_xml (source1, appstream, XB_BUILDER_SOURCE_FLAG_NONE, &error);
+       g_assert_no_error (error);
+       xb_builder_import_source (builder, source1);
+
+       xb_builder_source_load_xml (source2, appdata, XB_BUILDER_SOURCE_FLAG_NONE, &error);
+       g_assert_no_error (error);
+       xb_builder_import_source (builder, source2);
+
+       /* create file if it does not exist */
+        xmlb = g_file_new_for_path ("/tmp/temp.xmlb");
+        g_file_delete (xmlb, NULL, NULL);
+        silo = xb_builder_ensure (builder, xmlb,
+                                  XB_BUILDER_COMPILE_FLAG_WATCH_BLOB,
+                                  NULL, &error);
+       g_assert_no_error (error);
+       g_assert_nonnull (silo);
+
+       xb_string_append_union (xpath, "components/component/id/..");
+       xb_string_append_union (xpath, "component/description/..");
+       components = xb_silo_query (silo, xpath->str, 0, &error);
+       g_assert_no_error (error);
+
+       g_assert_cmpint (components->len, ==, 3);
+}
+
 static void
 gs_app_list_func (void)
 {
@@ -803,6 +875,7 @@ main (int argc, char **argv)
        g_test_add_func ("/gnome-software/lib/app{list-wildcard-dedupe}", gs_app_list_wildcard_dedupe_func);
        g_test_add_func ("/gnome-software/lib/app{list-performance}", gs_app_list_performance_func);
        g_test_add_func ("/gnome-software/lib/app{list-related}", gs_app_list_related_func);
+       g_test_add_func ("/gnome-software/lib/app{actual-app}", gs_app_is_actual_app_func);
        g_test_add_func ("/gnome-software/lib/plugin", gs_plugin_func);
        g_test_add_func ("/gnome-software/lib/plugin{download-rewrite}", gs_plugin_download_rewrite_func);
 
diff --git a/lib/meson.build b/lib/meson.build
index c4a88fb5..4b17a77e 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -143,7 +143,8 @@ if get_option('tests')
       gtk,
       json_glib,
       libm,
-      libsoup
+      libsoup,
+      libxmlb,
     ],
     link_with : [
       libgnomesoftware
diff --git a/plugins/core/gs-plugin-appstream.c b/plugins/core/gs-plugin-appstream.c
index 7979806b..47be2b8b 100644
--- a/plugins/core/gs-plugin-appstream.c
+++ b/plugins/core/gs-plugin-appstream.c
@@ -721,6 +721,7 @@ gs_plugin_refine_from_id (GsPlugin *plugin,
        xb_string_append_union (xpath, "components/component/id[text()='%s']/../pkgname/..", id);
        xb_string_append_union (xpath, "components/component[@type='webapp']/id[text()='%s']/..", id);
        xb_string_append_union (xpath, "component/id[text()='%s']/../pkgname/..", id);
+       xb_string_append_union (xpath, "component/id[text()='%s']/../description/..", id);
        components = xb_silo_query (priv->silo, xpath->str, 0, &error_local);
        if (components == NULL) {
                if (g_error_matches (error_local, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))


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