[gnome-software/1471-getting-duplicate-search-results-for-debs] gs-app-list: Detect duplicates also by GsApp instance address



commit e724606f35bf4437a2127088c96203756d0703a1
Author: Milan Crha <mcrha redhat com>
Date:   Thu Oct 21 13:36:05 2021 +0200

    gs-app-list: Detect duplicates also by GsApp instance address
    
    There could happen that a GsApp instance had been added to the list
    multiple times, but it was not caught, due to refining an app,
    which is also in the list, but as a wildcard, which "hides" the other
    instance in the list.
    
    Closes https://gitlab.gnome.org/GNOME/gnome-software/-/issues/1471

 lib/gs-app-list.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
---
diff --git a/lib/gs-app-list.c b/lib/gs-app-list.c
index 33a01ce56..7f1f40a7b 100644
--- a/lib/gs-app-list.c
+++ b/lib/gs-app-list.c
@@ -336,14 +336,15 @@ gs_app_list_check_for_duplicate (GsAppList *list, GsApp *app)
                return TRUE;
        }
 
+       for (guint i = 0; i < list->array->len; i++) {
+               GsApp *app_tmp = g_ptr_array_index (list->array, i);
+               if (app_tmp == app)
+                       return FALSE;
+       }
+
        /* does not exist */
        id = gs_app_get_unique_id (app);
        if (id == NULL) {
-               for (guint i = 0; i < list->array->len; i++) {
-                       GsApp *app_tmp = g_ptr_array_index (list->array, i);
-                       if (app_tmp == app)
-                               return FALSE;
-               }
                /* not much else we can do... */
                return TRUE;
        }
@@ -851,8 +852,11 @@ gs_app_list_filter_duplicates (GsAppList *list, GsAppListFilterFlags flags)
        /* add back the apps we want to keep */
        for (guint i = 0; i < old->array->len; i++) {
                GsApp *app = gs_app_list_index (old, i);
-               if (g_hash_table_contains (kept_apps, app))
+               if (g_hash_table_contains (kept_apps, app)) {
                        gs_app_list_add_safe (list, app, GS_APP_LIST_ADD_FLAG_NONE);
+                       /* In case the same instance is in the 'list' multiple times */
+                       g_hash_table_remove (kept_apps, app);
+               }
        }
 }
 


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