[gnome-software/1194-broken-repository-can-hide-other-repositories] rpm-ostree: Use dedicated dnf context for repository listing



commit fc2bfd934252982d3b6a18bcb264d3437a980ca6
Author: Milan Crha <mcrha redhat com>
Date:   Wed Mar 31 09:26:38 2021 +0200

    rpm-ostree: Use dedicated dnf context for repository listing
    
    A broken repository can cause refresh failure, which unsets global
    dnf context, thus no repositories are returned when the rpm-ostree
    plugin is asked for them. As only the dnf context is required to
    get the list of the repositories, it can use its own instance of it.
    
    Closes https://gitlab.gnome.org/GNOME/gnome-software/-/issues/1194

 plugins/rpm-ostree/gs-plugin-rpm-ostree.c | 57 ++++++++++++++++++++++---------
 1 file changed, 40 insertions(+), 17 deletions(-)
---
diff --git a/plugins/rpm-ostree/gs-plugin-rpm-ostree.c b/plugins/rpm-ostree/gs-plugin-rpm-ostree.c
index e47c282ba..41498dd5f 100644
--- a/plugins/rpm-ostree/gs-plugin-rpm-ostree.c
+++ b/plugins/rpm-ostree/gs-plugin-rpm-ostree.c
@@ -648,29 +648,51 @@ rpmostree_update_deployment (GsRPMOSTreeOS *os_proxy,
 #define RPMOSTREE_DIR_CACHE_REPOMD "repomd"
 #define RPMOSTREE_DIR_CACHE_SOLV "solv"
 
+static DnfContext *
+create_bare_rpmostree_dnf_context (GCancellable *cancellable,
+                                  GError **error)
+{
+       g_autoptr(DnfContext) context = dnf_context_new ();
+
+       dnf_context_set_repo_dir (context, "/etc/yum.repos.d");
+       dnf_context_set_cache_dir (context, RPMOSTREE_CORE_CACHEDIR RPMOSTREE_DIR_CACHE_REPOMD);
+       dnf_context_set_solv_dir (context, RPMOSTREE_CORE_CACHEDIR RPMOSTREE_DIR_CACHE_SOLV);
+       dnf_context_set_cache_age (context, G_MAXUINT);
+       dnf_context_set_enable_filelists (context, FALSE);
+
+       if (!dnf_context_setup (context, cancellable, error)) {
+               g_warning ("failed to dnf_context setup()");
+               gs_rpmostree_error_convert (error);
+               return NULL;
+       }
+
+       return g_steal_pointer (&context);
+}
+
 static gboolean
 ensure_rpmostree_dnf_context (GsPlugin *plugin, GCancellable *cancellable, GError **error)
 {
        GsPluginData *priv = gs_plugin_get_data (plugin);
+       g_autoptr(DnfContext) context = NULL;
        g_autofree gchar *transaction_address = NULL;
-       g_autoptr(GsApp) progress_app = gs_app_new (gs_plugin_get_name (plugin));
-       g_autoptr(DnfContext) context = dnf_context_new ();
-       g_autoptr(DnfState) state = dnf_state_new ();
+       g_autoptr(GsApp) progress_app = NULL;
        g_autoptr(GVariant) options = NULL;
-       g_autoptr(TransactionProgress) tp = transaction_progress_new ();
+       g_autoptr(TransactionProgress) tp = NULL;
+       g_autoptr(DnfState) state = NULL;
 
        if (priv->dnf_context != NULL)
                return TRUE;
 
+       context = create_bare_rpmostree_dnf_context (cancellable, error);
+       if (!context)
+               return FALSE;
+
+       progress_app = gs_app_new (gs_plugin_get_name (plugin));
+       tp = transaction_progress_new ();
+
        tp->app = g_object_ref (progress_app);
        tp->plugin = g_object_ref (plugin);
 
-       dnf_context_set_repo_dir (context, "/etc/yum.repos.d");
-       dnf_context_set_cache_dir (context, RPMOSTREE_CORE_CACHEDIR RPMOSTREE_DIR_CACHE_REPOMD);
-       dnf_context_set_solv_dir (context, RPMOSTREE_CORE_CACHEDIR RPMOSTREE_DIR_CACHE_SOLV);
-       dnf_context_set_cache_age (context, G_MAXUINT);
-       dnf_context_set_enable_filelists (context, FALSE);
-
        options = make_refresh_md_options_variant (FALSE /* force */);
        if (!gs_rpmostree_os_call_refresh_md_sync (priv->os_proxy,
                                                   options,
@@ -690,10 +712,7 @@ ensure_rpmostree_dnf_context (GsPlugin *plugin, GCancellable *cancellable, GErro
                return FALSE;
        }
 
-       if (!dnf_context_setup (context, cancellable, error)) {
-               gs_rpmostree_error_convert (error);
-               return FALSE;
-       }
+       state = dnf_state_new ();
 
        if (!dnf_context_setup_sack_with_flags (context, state, DNF_CONTEXT_SETUP_SACK_FLAG_SKIP_RPMDB, 
error)) {
                gs_rpmostree_error_convert (error);
@@ -1814,14 +1833,18 @@ gs_plugin_add_sources (GsPlugin *plugin,
 {
        GsPluginData *priv = gs_plugin_get_data (plugin);
        g_autoptr(GMutexLocker) locker = NULL;
+       g_autoptr(DnfContext) dnf_context = NULL;
        GPtrArray *repos;
 
        locker = g_mutex_locker_new (&priv->mutex);
 
-       if (priv->dnf_context == NULL)
-               return TRUE;
+       dnf_context = create_bare_rpmostree_dnf_context (cancellable, error);
+       if (!dnf_context) {
+               gs_rpmostree_error_convert (error);
+               return FALSE;
+       }
 
-       repos = dnf_context_get_repos (priv->dnf_context);
+       repos = dnf_context_get_repos (dnf_context);
        if (repos == NULL)
                return TRUE;
 


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