Blame SOURCES/0002-context-wildcard-support-in-dnf_context_repo_set_data-RhBug1781420.patch

462afb
From c398ea4431ea539b0847fdf7fddf1892655081de Mon Sep 17 00:00:00 2001
462afb
From: Jaroslav Rohel <jrohel@redhat.com>
462afb
Date: Sun, 15 Dec 2019 16:43:01 +0100
462afb
Subject: [PATCH] [context] wildcard support in dnf_context_repo_set_data
462afb
 (RhBug:1781420)
462afb
462afb
Adds support for wildcard pattern in repo_id to these functions:
462afb
gboolean dnf_context_repo_enable(DnfContext *context,
462afb
    const gchar *repo_id, GError **error);
462afb
gboolean dnf_context_repo_disable(DnfContext *context,
462afb
    const gchar *repo_id, GError **error);
462afb
462afb
For example, it is used by microdnf for enable and disable repositories
462afb
(arguments "--enablerepo=" and "--disablerepo=").
462afb
---
462afb
 libdnf/dnf-context.cpp | 26 +++++++++++++-------------
462afb
 1 file changed, 13 insertions(+), 13 deletions(-)
462afb
462afb
diff --git a/libdnf/dnf-context.cpp b/libdnf/dnf-context.cpp
462afb
index 061bf6f85..4b0a009fc 100644
462afb
--- a/libdnf/dnf-context.cpp
462afb
+++ b/libdnf/dnf-context.cpp
462afb
@@ -52,6 +52,7 @@
462afb
 #include <fcntl.h>
462afb
 #include <unistd.h>
462afb
 #endif
462afb
+#include <fnmatch.h>
462afb
 #include <unistd.h>
462afb
 
462afb
 #include "log.hpp"
462afb
@@ -2273,20 +2274,19 @@ dnf_context_repo_set_data(DnfContext *context,
462afb
                           GError **error)
462afb
 {
462afb
     DnfContextPrivate *priv = GET_PRIVATE(context);
462afb
-    DnfRepo *repo = NULL;
462afb
-    guint i;
462afb
+    bool found = false;
462afb
 
462afb
-    /* find a repo with a matching ID */
462afb
-    for (i = 0; i < priv->repos->len; i++) {
462afb
-        auto repo_tmp = static_cast<DnfRepo *>(g_ptr_array_index(priv->repos, i));
462afb
-        if (g_strcmp0(dnf_repo_get_id(repo_tmp), repo_id) == 0) {
462afb
-            repo = repo_tmp;
462afb
-            break;
462afb
+    /* set repos with a matching ID */
462afb
+    for (guint i = 0; i < priv->repos->len; ++i) {
462afb
+        auto repo = static_cast<DnfRepo *>(g_ptr_array_index(priv->repos, i));
462afb
+        if (fnmatch(repo_id, dnf_repo_get_id(repo), 0) == 0) {
462afb
+            dnf_repo_set_enabled(repo, enabled);
462afb
+            found = true;
462afb
         }
462afb
     }
462afb
 
462afb
     /* nothing found */
462afb
-    if (repo == NULL) {
462afb
+    if (!found) {
462afb
         g_set_error(error,
462afb
                     DNF_ERROR,
462afb
                     DNF_ERROR_INTERNAL_ERROR,
462afb
@@ -2294,8 +2294,6 @@ dnf_context_repo_set_data(DnfContext *context,
462afb
         return FALSE;
462afb
     }
462afb
 
462afb
-    /* this is runtime only */
462afb
-    dnf_repo_set_enabled(repo, enabled);
462afb
     return TRUE;
462afb
 }
462afb
 
462afb
@@ -2305,7 +2303,8 @@ dnf_context_repo_set_data(DnfContext *context,
462afb
  * @repo_id: A repo_id, e.g. "fedora-rawhide"
462afb
  * @error: A #GError or %NULL
462afb
  *
462afb
- * Enables a specific repo.
462afb
+ * Enables a specific repo(s).
462afb
+ * Wildcard pattern is supported.
462afb
  *
462afb
  * This must be done before dnf_context_setup() is called.
462afb
  *
462afb
@@ -2329,7 +2328,8 @@ dnf_context_repo_enable(DnfContext *context,
462afb
  * @repo_id: A repo_id, e.g. "fedora-rawhide"
462afb
  * @error: A #GError or %NULL
462afb
  *
462afb
- * Disables a specific repo.
462afb
+ * Disables a specific repo(s).
462afb
+ * Wildcard pattern is supported.
462afb
  *
462afb
  * This must be done before dnf_context_setup() is called.
462afb
  *