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

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