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