[gnome-software/wip/mcrha/fedora-third-party-followup] gs-plugin-provenance: Mark fedora-third-party provided apps with GS_APP_QUIRK_DISTRO_SAFE



commit b30a43889a924ac416df12c54e35c437801a9914
Author: Milan Crha <mcrha redhat com>
Date:   Wed Sep 22 08:50:53 2021 +0200

    gs-plugin-provenance: Mark fedora-third-party provided apps with GS_APP_QUIRK_DISTRO_SAFE
    
    The fedora-third-party repos are not stored in the 'official-repos'
    GSettings key, but they also should not be, because the provenance
    quirk is used in the repos dialog to disable some functionality
    on such repos. Keeping the both lists (the GSettings key and
    the actual fedora-third-party repos list) in sync is also impractical.
    
    The GS_APP_QUIRK_DISTRO_SAFE will be used to show in the safety tile/dialog
    that the app is reviewed by the distro, rather than as being from a third-party
    repository.

 plugins/core/gs-plugin-provenance.c | 53 ++++++++++++++++++++++++++++++-------
 1 file changed, 44 insertions(+), 9 deletions(-)
---
diff --git a/plugins/core/gs-plugin-provenance.c b/plugins/core/gs-plugin-provenance.c
index 97ff76798..6d5937479 100644
--- a/plugins/core/gs-plugin-provenance.c
+++ b/plugins/core/gs-plugin-provenance.c
@@ -10,6 +10,7 @@
 #include <config.h>
 
 #include <gnome-software.h>
+#include "gs-fedora-third-party.h"
 
 /*
  * SECTION:
@@ -20,6 +21,7 @@
 struct GsPluginData {
        GSettings               *settings;
        gchar                   **sources;
+       GsFedoraThirdParty      *third_party;
 };
 
 static gchar **
@@ -55,6 +57,7 @@ gs_plugin_initialize (GsPlugin *plugin)
        g_signal_connect (priv->settings, "changed",
                          G_CALLBACK (gs_plugin_provenance_settings_changed_cb), plugin);
        priv->sources = gs_plugin_provenance_get_sources (plugin);
+       priv->third_party = gs_fedora_third_party_new ();
 
        /* after the package source is set */
        gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "dummy");
@@ -68,12 +71,27 @@ gs_plugin_destroy (GsPlugin *plugin)
        GsPluginData *priv = gs_plugin_get_data (plugin);
        g_strfreev (priv->sources);
        g_object_unref (priv->settings);
+       g_clear_object (&priv->third_party);
+}
+
+static gboolean
+is_fedora_third_party_source (GHashTable *third_party_repos,
+                             GsApp *app,
+                             const gchar *origin)
+{
+       if (origin == NULL || gs_app_get_scope (app) == AS_COMPONENT_SCOPE_USER)
+               return FALSE;
+
+       return gs_fedora_third_party_util_is_third_party_repo (third_party_repos,
+                                                              origin,
+                                                              gs_app_get_management_plugin (app));
 }
 
 static gboolean
 refine_app (GsPlugin             *plugin,
            GsApp                *app,
            GsPluginRefineFlags   flags,
+           GHashTable           *third_party_repos,
            GCancellable         *cancellable,
            GError              **error)
 {
@@ -87,14 +105,15 @@ refine_app (GsPlugin             *plugin,
        if (gs_app_has_quirk (app, GS_APP_QUIRK_PROVENANCE))
                return TRUE;
 
-       /* nothing to search */
        sources = priv->sources;
-       if (sources == NULL || sources[0] == NULL)
-               return TRUE;
+       gs_app_remove_quirk (app, GS_APP_QUIRK_DISTRO_SAFE);
 
        /* simple case */
        origin = gs_app_get_origin (app);
-       if (origin != NULL && gs_utils_strv_fnmatch (sources, origin)) {
+       if (is_fedora_third_party_source (third_party_repos, app, origin)) {
+               gs_app_add_quirk (app, GS_APP_QUIRK_DISTRO_SAFE);
+               return TRUE;
+       } else if (origin != NULL && sources != NULL && gs_utils_strv_fnmatch (sources, origin)) {
                gs_app_add_quirk (app, GS_APP_QUIRK_PROVENANCE);
                return TRUE;
        }
@@ -103,8 +122,9 @@ refine_app (GsPlugin             *plugin,
         * provenance quirk to the system-configured repositories (but not
         * user-configured ones). */
        if (gs_app_get_kind (app) == AS_COMPONENT_KIND_REPOSITORY &&
-           gs_utils_strv_fnmatch (sources, gs_app_get_id (app))) {
-               if (gs_app_get_scope (app) != AS_COMPONENT_SCOPE_USER)
+           sources != NULL && gs_utils_strv_fnmatch (sources, gs_app_get_id (app))) {
+               if (gs_app_get_scope (app) != AS_COMPONENT_SCOPE_USER &&
+                   !is_fedora_third_party_source (third_party_repos, app, gs_app_get_id (app)))
                        gs_app_add_quirk (app, GS_APP_QUIRK_PROVENANCE);
                return TRUE;
        }
@@ -118,7 +138,10 @@ refine_app (GsPlugin             *plugin,
                return TRUE;
        if (g_str_has_prefix (origin + 1, "installed:"))
                origin += 10;
-       if (gs_utils_strv_fnmatch (sources, origin + 1)) {
+       if (is_fedora_third_party_source (third_party_repos, app, origin + 1)) {
+               gs_app_add_quirk (app, GS_APP_QUIRK_DISTRO_SAFE);
+               return TRUE;
+       } else if (sources != NULL && gs_utils_strv_fnmatch (sources, origin + 1)) {
                gs_app_add_quirk (app, GS_APP_QUIRK_PROVENANCE);
                return TRUE;
        }
@@ -133,17 +156,29 @@ gs_plugin_refine (GsPlugin             *plugin,
                  GError              **error)
 {
        GsPluginData *priv = gs_plugin_get_data (plugin);
+       g_autoptr(GHashTable) third_party_repos = NULL;
+       g_autoptr(GError) local_error = NULL;
 
        /* nothing to do here */
        if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_PROVENANCE) == 0)
                return TRUE;
+
+       if (!gs_fedora_third_party_list_sync (priv->third_party, &third_party_repos, cancellable, 
&local_error)) {
+               if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+                       g_propagate_error (error, local_error);
+                       return FALSE;
+               }
+               if (!g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
+                       g_debug ("Failed to get fedora-third-party repos: %s", local_error->message);
+       }
+
        /* nothing to search */
-       if (priv->sources == NULL || priv->sources[0] == NULL)
+       if ((priv->sources == NULL || priv->sources[0] == NULL) && third_party_repos == NULL)
                return TRUE;
 
        for (guint i = 0; i < gs_app_list_length (list); i++) {
                GsApp *app = gs_app_list_index (list, i);
-               if (!refine_app (plugin, app, flags, cancellable, error))
+               if (!refine_app (plugin, app, flags, third_party_repos, cancellable, error))
                        return FALSE;
        }
 


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