[gnome-software/1194-broken-repository-can-hide-other-repositories: 2/2] rpm-ostree: Use dedicated dnf context for repository listing
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/1194-broken-repository-can-hide-other-repositories: 2/2] rpm-ostree: Use dedicated dnf context for repository listing
- Date: Wed, 31 Mar 2021 11:52:13 +0000 (UTC)
commit a1d9c2c3a79dd0fb6ba5875202015a2f9859f0ff
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 | 56 +++++++++++++++++++++----------
1 file changed, 39 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..fac0f3f91 100644
--- a/plugins/rpm-ostree/gs-plugin-rpm-ostree.c
+++ b/plugins/rpm-ostree/gs-plugin-rpm-ostree.c
@@ -648,29 +648,50 @@ 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)) {
+ 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 +711,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 +1832,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]