Blame SOURCES/0001-utils-add-support-for-multiple-entitlement-certifica.patch

6a33d9
From 702a47c067d5c1cd27b0c815514746dc39afb85e Mon Sep 17 00:00:00 2001
6a33d9
From: Igor Gnatenko <ignatenko@redhat.com>
6a33d9
Date: Thu, 30 Mar 2017 18:45:19 +0200
6a33d9
Subject: [PATCH] utils: add support for multiple entitlement certificates
6a33d9
6a33d9
..for generation of yum repo.
6a33d9
6a33d9
We just need to go through list and find all possible repositories.
6a33d9
If there are duplicates, silently skip it (as sub-man does).
6a33d9
6a33d9
Signed-off-by: Igor Gnatenko <ignatenko@redhat.com>
6a33d9
---
6a33d9
 rhsm/rhsm-utils.c | 33 ++++++++++++++++++++-------------
6a33d9
 1 file changed, 20 insertions(+), 13 deletions(-)
6a33d9
6a33d9
diff --git a/rhsm/rhsm-utils.c b/rhsm/rhsm-utils.c
6a33d9
index d9bb4a2..7b6a26b 100644
6a33d9
--- a/rhsm/rhsm-utils.c
6a33d9
+++ b/rhsm/rhsm-utils.c
6a33d9
@@ -195,25 +195,24 @@ rhsm_utils_yum_repo_from_context (RHSMContext *ctx)
6a33d9
   g_autoptr(GPtrArray) entitlements = rhsm_context_get_entitlement_certificates (ctx);
6a33d9
   g_autoptr(GPtrArray) products = rhsm_context_get_product_certificates (ctx);
6a33d9
 
6a33d9
-  if (entitlements->len > 0)
6a33d9
+  /* Get all available tags from each of the products */
6a33d9
+  g_autoptr(GHashTable) available_tags = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
6a33d9
+  for (guint i = 0; i < products->len; i++)
6a33d9
     {
6a33d9
-      g_autoptr(GError) error = NULL;
6a33d9
-      RHSMEntitlementCertificate *entitlement = g_ptr_array_index (entitlements, 0);
6a33d9
+      RHSMProductCertificate *product = g_ptr_array_index (products, i);
6a33d9
+      g_auto(GStrv) tags = g_strsplit (rhsm_product_certificate_get_tags (product), ",", -1);
6a33d9
+      for (GStrv tag = tags; *tag != NULL; tag++)
6a33d9
+        g_hash_table_add (available_tags, g_strdup (*tag));
6a33d9
+    }
6a33d9
+
6a33d9
+  for (guint i = 0; i < entitlements->len; i++)
6a33d9
+    {
6a33d9
+      RHSMEntitlementCertificate *entitlement = g_ptr_array_index (entitlements, i);
6a33d9
       JsonNode *ent = rhsm_entitlement_certificate_get_entitlement (entitlement);
6a33d9
       g_autoptr(JsonNode) contents = json_path_query ("$.products[*].content[*]", ent, NULL);
6a33d9
       /* Even there is non-matching JsonPath, node will be empty array */
6a33d9
       g_assert_nonnull (contents);
6a33d9
 
6a33d9
-      /* Get all available tags from each of the products */
6a33d9
-      g_autoptr(GHashTable) available_tags = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
6a33d9
-      for (guint i = 0; i < products->len; i++)
6a33d9
-        {
6a33d9
-          RHSMProductCertificate *product = g_ptr_array_index (products, i);
6a33d9
-          g_auto(GStrv) tags = g_strsplit (rhsm_product_certificate_get_tags (product), ",", -1);
6a33d9
-          for (GStrv tag = tags; *tag != NULL; tag++)
6a33d9
-            g_hash_table_add (available_tags, g_strdup (*tag));
6a33d9
-        }
6a33d9
-
6a33d9
       g_autoptr(GList) elements = json_array_get_elements (json_node_get_array (contents));
6a33d9
       const gchar *ctx_arch = rhsm_context_get_arch (ctx);
6a33d9
       const gchar *ctx_baseurl = rhsm_context_get_baseurl (ctx);
6a33d9
@@ -252,6 +251,14 @@ rhsm_utils_yum_repo_from_context (RHSMContext *ctx)
6a33d9
             enabled = json_object_get_boolean_member (repo, "enabled");
6a33d9
           if (id == NULL || name == NULL || path == NULL)
6a33d9
             continue; /* TODO: make some error reporting here */
6a33d9
+
6a33d9
+          /* Clashing repositories */
6a33d9
+          if (g_key_file_has_group (repofile, id))
6a33d9
+            {
6a33d9
+              g_debug ("Repository '%s' has been already added, skipping", id);
6a33d9
+              continue;
6a33d9
+            }
6a33d9
+
6a33d9
           g_autofree gchar *baseurl = g_strconcat (ctx_baseurl, path, NULL);
6a33d9
           g_key_file_set_string (repofile, id, "name", name);
6a33d9
           g_key_file_set_string (repofile, id, "baseurl", baseurl);
6a33d9
-- 
6a33d9
2.12.1
6a33d9