[gnome-software/1132-fix-duplicate-addons] WIP




commit cccab5f199fe90d43e97d11d0c1aacdef8979c3d
Author: Phaedrus Leeds <mwleeds endlessos org>
Date:   Thu Feb 4 19:00:19 2021 -0800

    WIP

 plugins/flatpak/gs-flatpak.c | 90 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 90 insertions(+)
---
diff --git a/plugins/flatpak/gs-flatpak.c b/plugins/flatpak/gs-flatpak.c
index dd7f3ee20..0096dd5d3 100644
--- a/plugins/flatpak/gs-flatpak.c
+++ b/plugins/flatpak/gs-flatpak.c
@@ -2223,6 +2223,90 @@ gs_flatpak_get_installed_ref (GsFlatpak *self,
        return ref;
 }
 
+static gboolean
+gs_flatpak_prune_addons_list (GsFlatpak *self,
+                             GsApp *app,
+                             GCancellable *cancellable,
+                             GError **error)
+{
+       GsAppList *addons_list;
+       g_autoptr(FlatpakInstalledRef) installed_ref = NULL;
+       g_autoptr(GPtrArray) installed_related_refs = NULL;
+       g_autoptr(GPtrArray) remote_related_refs = NULL;
+       g_autofree gchar *ref = NULL;
+       g_autoptr(GError) error_local = NULL;
+
+       addons_list = gs_app_get_addons (app);
+       if (gs_app_list_length (addons_list) == 0)
+               return TRUE;
+
+       if (gs_app_get_origin (app) == NULL)
+               return TRUE;
+
+       ref = g_strdup_printf ("%s/%s/%s/%s",
+                             gs_flatpak_app_get_ref_kind_as_str (app),
+                             gs_flatpak_app_get_ref_name (app),
+                             gs_flatpak_app_get_ref_arch (app),
+                             gs_app_get_branch (app));
+
+       /* Find installed related refs in case the app is installed */
+       installed_related_refs = flatpak_installation_list_installed_related_refs_sync (self->installation,
+                                                                                       gs_app_get_origin 
(app),
+                                                                                       ref,
+                                                                                       NULL, &error_local);
+       if (installed_related_refs == NULL &&
+           !g_error_matches (error_local,
+                             FLATPAK_ERROR,
+                             FLATPAK_ERROR_NOT_INSTALLED)) {
+               gs_flatpak_error_convert (&error_local);
+               g_propagate_error (error, g_steal_pointer (&error_local));
+               return FALSE;
+       }
+
+       //TODO use flatpak_installation_list_remote_related_refs_for_installed_sync()
+       /* Find remote related refs but ignore errors in case we're offline */
+       remote_related_refs = flatpak_installation_list_remote_related_refs_sync (self->installation,
+                                                                                       gs_app_get_origin 
(app),
+                                                                                       ref,
+                                                                                       NULL, NULL);
+
+       /* For each addon, if it is neither installed nor available, hide it
+        * since it may be intended for a different version of the app. We
+        * don't want to show both org.videolan.VLC.Plugin.bdj//3-19.08 and
+        * org.videolan.VLC.Plugin.bdj//3-20.08 in the UI; only one will work
+        * for the installed app
+        */
+       for (guint i = 0; i < gs_app_list_length (addons_list); i++) {
+               GsApp *app_addon = gs_app_list_index (addons_list, i);
+               gboolean found = FALSE;
+               g_autofree char *addon_ref = NULL;
+
+               addon_ref = g_strdup_printf ("%s/%s/%s/%s",
+                                            gs_flatpak_app_get_ref_kind_as_str (app_addon),
+                                            gs_flatpak_app_get_ref_name (app_addon),
+                                            gs_flatpak_app_get_ref_arch (app_addon),
+                                            gs_app_get_branch (app_addon));
+               for (guint j = 0; installed_related_refs && j < installed_related_refs->len; j++) {
+                       FlatpakRelatedRef *rel = g_ptr_array_index (installed_related_refs, j);
+                       g_autofree *rel_ref = flatpak_ref_format_ref (FLATPAK_REF (rel));
+                       if (g_strcmp0 (addon_ref, rel_ref) == 0)
+                               found = TRUE;
+               }
+               for (guint j = 0; remote_related_refs && j < remote_related_refs->len; j++) {
+                       FlatpakRelatedRef *rel = g_ptr_array_index (remote_related_refs, j);
+                       g_autofree char *rel_ref = flatpak_ref_format_ref (FLATPAK_REF (rel));
+                       if (g_strcmp0 (addon_ref, rel_ref) == 0)
+                               found = TRUE;
+               }
+
+               if (!found) {
+                       gs_app_add_quirk (app_addon, GS_APP_QUIRK_HIDE_EVERYWHERE);
+                       g_warning ("hiding %s", gs_app_get_unique_id (app_addon));
+               }
+       }
+       return TRUE;
+}
+
 static gboolean
 gs_plugin_refine_item_size (GsFlatpak *self,
                            GsApp *app,
@@ -2671,6 +2755,12 @@ gs_flatpak_refine_app_unlocked (GsFlatpak *self,
                return FALSE;
        }
 
+       /* hide any addons that aren't for this app */
+       if (!gs_flatpak_prune_addons_list (self, app, cancellable, error)) {
+               g_prefix_error (error, "failed to prune addons: ");
+               return FALSE;
+       }
+
        /* scope is fast, do unconditionally */
        if (gs_app_get_state (app) != GS_APP_STATE_AVAILABLE_LOCAL)
                gs_plugin_refine_item_scope (self, app);


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