Make set_record act like a setter
authorPatrick Uiterwijk <puiterwijk@redhat.com>
Mon, 26 Sep 2016 12:45:25 +0000 (12:45 +0000)
committerPatrick Uiterwijk <puiterwijk@redhat.com>
Mon, 26 Sep 2016 12:52:39 +0000 (12:52 +0000)
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

index fea2c7ed83d3e42869067e306c64fcc7851288aa..3e79ccfc8c0cc4768c6ff0d6247769902cb866de 100644 (file)
@@ -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);
 }