[gnome-software/1192-duplicate-source-origin-in-details-page-for-chromium-ungoogledchromium] gs-details-page: Enhance the alternates deduplication cycle
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/1192-duplicate-source-origin-in-details-page-for-chromium-ungoogledchromium] gs-details-page: Enhance the alternates deduplication cycle
- Date: Wed, 5 May 2021 14:13:24 +0000 (UTC)
commit da04e248d3992c41374f6f0118fe749e78b3888b
Author: Milan Crha <mcrha redhat com>
Date: Wed May 5 16:10:21 2021 +0200
gs-details-page: Enhance the alternates deduplication cycle
The deduplication works as long as the array doesn't contain the same pointers
or when those are not interleaved. Being interleaved it can happen the first
occurrence of the second or later instance is skipped due to the array content
shift with g_ptr_array_remove(), which removed the first occurrence of the data.
Closes https://gitlab.gnome.org/GNOME/gnome-software/-/issues/1192
src/gs-details-page.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
---
diff --git a/src/gs-details-page.c b/src/gs-details-page.c
index 6ac309da9..2e56e5d81 100644
--- a/src/gs-details-page.c
+++ b/src/gs-details-page.c
@@ -834,6 +834,9 @@ app_origin_equal (GsApp *a,
g_autofree gchar *a_origin_ui = NULL, *b_origin_ui = NULL;
GFile *a_local_file, *b_local_file;
+ if (a == b)
+ return TRUE;
+
a_origin_ui = gs_app_get_origin_ui (a);
b_origin_ui = gs_app_get_origin_ui (b);
@@ -907,16 +910,25 @@ gs_details_page_get_alternates_cb (GObject *source_object,
* items long. */
for (guint i = 0; i < gs_app_list_length (list); i++) {
GsApp *i_app = gs_app_list_index (list, i);
+ gboolean did_remove = FALSE;
for (guint j = i + 1; j < gs_app_list_length (list);) {
GsApp *j_app = gs_app_list_index (list, j);
if (app_origin_equal (i_app, j_app)) {
gs_app_list_remove (list, j_app);
+ did_remove = TRUE;
} else {
j++;
}
}
+
+ /* Needed to catch cases when the same pointer is in the array multiple times,
+ interleaving with another pointer. The removal can skip the first occurrence
+ due to the g_ptr_array_remove() removing the first instance in the array,
+ which shifts the array content. */
+ if (did_remove)
+ i--;
}
/* add the local file to the list so that we can carry it over when
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]