[gnome-software/wip/hughsie/prefer-desktop-for-pkgname-search: 3/3] Ensure all applications with addons are shown in the updates panel



commit acb56be099acc905cbd0b0c5e92915a8d508a0db
Author: Richard Hughes <richard hughsie com>
Date:   Wed Jun 12 13:44:40 2019 +0100

    Ensure all applications with addons are shown in the updates panel
    
    Prefer 'desktop' applications when matching the package name to the AppStream
    ID, as addons are not shown in the updates panel and applications are.
    
    Also, only match against one component rather than inheriting properties from
    all components that match the package name.

 plugins/core/gs-plugin-appstream.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)
---
diff --git a/plugins/core/gs-plugin-appstream.c b/plugins/core/gs-plugin-appstream.c
index dfdb95ec..4d36a032 100644
--- a/plugins/core/gs-plugin-appstream.c
+++ b/plugins/core/gs-plugin-appstream.c
@@ -766,16 +766,19 @@ gs_plugin_refine_from_pkgname (GsPlugin *plugin,
        /* find all apps when matching any prefixes */
        for (guint j = 0; j < sources->len; j++) {
                const gchar *pkgname = g_ptr_array_index (sources, j);
-               g_autofree gchar *xpath = NULL;
                g_autoptr(GRWLockReaderLocker) locker = NULL;
-               g_autoptr(GPtrArray) components = NULL;
+               g_autoptr(GString) xpath = g_string_new (NULL);
+               g_autoptr(XbNode) component = NULL;
 
                locker = g_rw_lock_reader_locker_new (&priv->silo_lock);
 
-               xpath = g_strdup_printf ("components/component/pkgname[text()='%s']/..",
-                                        pkgname);
-               components = xb_silo_query (priv->silo, xpath, 0, &error_local);
-               if (components == NULL) {
+               /* prefer actual apps and then fallback to anything else */
+               xb_string_append_union (xpath, 
"components/component[@type='desktop']/pkgname[text()='%s']/..", pkgname);
+               xb_string_append_union (xpath, 
"components/component[@type='console']/pkgname[text()='%s']/..", pkgname);
+               xb_string_append_union (xpath, 
"components/component[@type='webapp']/pkgname[text()='%s']/..", pkgname);
+               xb_string_append_union (xpath, "components/component/pkgname[text()='%s']/..", pkgname);
+               component = xb_silo_query_first (priv->silo, xpath->str, &error_local);
+               if (component == NULL) {
                        if (g_error_matches (error_local, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
                                continue;
                        if (g_error_matches (error_local, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT))
@@ -783,13 +786,9 @@ gs_plugin_refine_from_pkgname (GsPlugin *plugin,
                        g_propagate_error (error, g_steal_pointer (&error_local));
                        return FALSE;
                }
-               for (guint i = 0; i < components->len; i++) {
-                       XbNode *component = g_ptr_array_index (components, i);
-                       if (!gs_appstream_refine_app (plugin, app, priv->silo,
-                                                     component, flags, error))
-                               return FALSE;
-                       gs_plugin_appstream_set_compulsory_quirk (app, component);
-               }
+               if (!gs_appstream_refine_app (plugin, app, priv->silo, component, flags, error))
+                       return FALSE;
+               gs_plugin_appstream_set_compulsory_quirk (app, component);
        }
 
        /* success */


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