[gnome-software/wip/hughsie/vnd.flatpak.ref] Fix showing wildcard applications from all plugins



commit 6b0a0f6c19f0690704c295226756e86f3d3ccc9c
Author: Richard Hughes <richard hughsie com>
Date:   Fri Sep 16 09:56:47 2016 +0100

    Fix showing wildcard applications from all plugins
    
    Allow duplicating a wildcarded GsAppp with an actual useful GsApp as the former
    will be filtered out by the plugin loader.

 src/gs-app-list.c  |   31 ++++++++++++++++++++++++++++---
 src/gs-self-test.c |   13 +++++++++++++
 2 files changed, 41 insertions(+), 3 deletions(-)
---
diff --git a/src/gs-app-list.c b/src/gs-app-list.c
index 349b4f4..72693ed 100644
--- a/src/gs-app-list.c
+++ b/src/gs-app-list.c
@@ -65,6 +65,33 @@ gs_app_list_lookup (GsAppList *list, const gchar *unique_id)
        return g_hash_table_lookup (list->hash_by_id, unique_id);
 }
 
+static gboolean
+gs_app_list_check_for_duplicate (GsAppList *list, GsApp *app)
+{
+       GsApp *app_old;
+       const gchar *id;
+       const gchar *id_old = NULL;
+
+       /* does not exist */
+       id = gs_app_get_unique_id (app);
+       app_old = g_hash_table_lookup (list->hash_by_id, id);
+       if (app_old == NULL) {
+               g_debug ("adding %s as nothing matched hash", id);
+               return TRUE;
+       }
+
+       /* existing app is a wildcard */
+       id_old = gs_app_get_unique_id (app_old);
+       if (gs_app_has_quirk (app_old, AS_APP_QUIRK_MATCH_ANY_PREFIX)) {
+               g_debug ("adding %s as %s is a wildcard", id, id_old);
+               return TRUE;
+       }
+
+       /* already exists */
+       g_debug ("not adding duplicate %s as %s already exists", id, id_old);
+       return FALSE;
+}
+
 static void
 gs_app_list_add_safe (GsAppList *list, GsApp *app)
 {
@@ -79,10 +106,8 @@ gs_app_list_add_safe (GsAppList *list, GsApp *app)
        }
 
        /* check for duplicate */
-       if (g_hash_table_lookup (list->hash_by_id, id) != NULL) {
-               g_debug ("not adding duplicate %s", id);
+       if (!gs_app_list_check_for_duplicate (list, app))
                return;
-       }
 
 #if !AS_CHECK_VERSION(0,6,2)
        /* check for duplicate using globs (slower) */
diff --git a/src/gs-self-test.c b/src/gs-self-test.c
index f5f2e7a..4b00b8d 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -263,6 +263,19 @@ gs_plugin_func (void)
        g_assert (gs_app_list_lookup (list, "*/b/c/d/e/f") != NULL);
        g_assert (gs_app_list_lookup (list, "x/x/x/x/x/x") == NULL);
        g_object_unref (list);
+
+       /* allow duplicating a wildcard */
+       list = gs_app_list_new ();
+       app = gs_app_new ("gimp.desktop");
+       gs_app_add_quirk (app, AS_APP_QUIRK_MATCH_ANY_PREFIX);
+       gs_app_list_add (list, app);
+       g_object_unref (app);
+       app = gs_app_new ("gimp.desktop");
+       gs_app_set_unique_id (app, "system/flatpak/*/*/gimp.desktop/stable");
+       gs_app_list_add (list, app);
+       g_object_unref (app);
+       g_assert_cmpint (gs_app_list_length (list), ==, 2);
+       g_object_unref (list);
 }
 
 static void


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