cd63e5
From f1a7d9b5e7ee493133daf608adaf80b10a87b915 Mon Sep 17 00:00:00 2001
cd63e5
From: Patrick Uiterwijk <puiterwijk@redhat.com>
cd63e5
Date: Mon, 26 Sep 2016 12:45:25 +0000
cd63e5
Subject: [PATCH 1/2] Make set_record act like a setter
cd63e5
cd63e5
This will make sure that when set_record is called, all existing
cd63e5
records of the same type are removed.
cd63e5
It makes no sense to have multiple records of the same type,
cd63e5
and it actively breaks libhifs checksum validation.
cd63e5
cd63e5
Signed-off-by: Patrick Uiterwijk <puiterwijk@redhat.com>
cd63e5
---
cd63e5
 src/repomd.c | 8 ++++++++
cd63e5
 1 file changed, 8 insertions(+)
cd63e5
cd63e5
diff --git a/src/repomd.c b/src/repomd.c
cd63e5
index fea2c7e..3e79ccf 100644
cd63e5
--- a/src/repomd.c
cd63e5
+++ b/src/repomd.c
cd63e5
@@ -682,6 +682,14 @@ cr_repomd_set_record(cr_Repomd *repomd,
cd63e5
                      cr_RepomdRecord *record)
cd63e5
 {
cd63e5
     if (!repomd || !record) return;
cd63e5
+
cd63e5
+    cr_RepomdRecord *delrec = NULL;
cd63e5
+    // Remove all existing record of the same type
cd63e5
+    while((delrec = cr_repomd_get_record(repomd, record->type)) != NULL) {
cd63e5
+	cr_repomd_detach_record(repomd, delrec);
cd63e5
+	cr_repomd_record_free(delrec);
cd63e5
+    }
cd63e5
+
cd63e5
     repomd->records = g_slist_append(repomd->records, record);
cd63e5
 }
cd63e5
 
cd63e5
cd63e5
From 5e44d23842d68e31e92498edeb6aba2e72a63abd Mon Sep 17 00:00:00 2001
cd63e5
From: Patrick Uiterwijk <puiterwijk@redhat.com>
cd63e5
Date: Mon, 26 Sep 2016 12:48:31 +0000
cd63e5
Subject: [PATCH 2/2] Add test to make sure that set_record overrides the
cd63e5
 current record
cd63e5
cd63e5
Signed-off-by: Patrick Uiterwijk <puiterwijk@redhat.com>
cd63e5
---
cd63e5
 tests/python/tests/test_repomd.py | 4 ++++
cd63e5
 1 file changed, 4 insertions(+)
cd63e5
cd63e5
diff --git a/tests/python/tests/test_repomd.py b/tests/python/tests/test_repomd.py
cd63e5
index 283dedc..6b6b3ad 100644
cd63e5
--- a/tests/python/tests/test_repomd.py
cd63e5
+++ b/tests/python/tests/test_repomd.py
cd63e5
@@ -99,6 +99,10 @@ def test_repomd(self):
cd63e5
 
cd63e5
         self.assertEqual(len(md.records), 1)
cd63e5
 
cd63e5
+        md.set_record(rec)
cd63e5
+
cd63e5
+        self.assertEqual(len(md.records), 1)
cd63e5
+
cd63e5
         md.repoid = None
cd63e5
         md.contenthash = None
cd63e5