From 10e111f7859b2b55307dba280d80daf220cc0526 Mon Sep 17 00:00:00 2001 From: Silvan Calarco Date: Fri, 12 Mar 2021 17:08:02 +0100 Subject: [PATCH] repodata: check for duplicated SRPM packages --- src/headerlist.c | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/src/headerlist.c b/src/headerlist.c index 7ef8d85..45d1609 100644 --- a/src/headerlist.c +++ b/src/headerlist.c @@ -1049,6 +1049,35 @@ int addToSourceHeaderList(struct configTag *ct, int mode, int altrepository) { filelists_node = filelists_node->next, other_node = other_node->next) { if (!strcmp((char*)package_node->name, "package")) { + char *package_name = strdup((char*) + findXMLPropertyByName(package_node, "name")->children->content); + xmlNode *version = findXMLPropertyByName(package_node, "version"); + tmp = (char*)findXMLAttributeByName(version, "epoch"); + int package_epoch = atoi(tmp); + free(tmp); + char *package_version = (char*)findXMLAttributeByName(version, "ver"); + char *package_release = (char*)findXMLAttributeByName(version, "rel"); + + // Check next package for duplicates + xmlNode *next_package = package_node->next; + while (next_package && strcmp((char*)next_package->name, "package")) { + next_package = next_package->next; + } + if (next_package) { + char *next_package_name = strdup((char*) + findXMLPropertyByName(next_package, "name")->children->content); + if (!strcmp(package_name, next_package_name)) { + // Assuming that older packages come first + logmsg(LOG_WARNING,"skipping older duplicated SRPM package %s(%d:%s:%s)", + package_name, package_epoch, package_version, package_release); + free(next_package_name); + free(package_name); + free(package_version); + free(package_release); + continue; + } + } + newheadersourcelist = malloc(sizeof(struct headerSourceList)); if (newheadersourcelist == NULL) return 1; @@ -1063,14 +1092,10 @@ int addToSourceHeaderList(struct configTag *ct, int mode, int altrepository) { newheadersourcelist->old = NULL; newheadersourcelist->id = ++sourceid; - newheadersourcelist->name = strdup((char*) - findXMLPropertyByName(package_node, "name")->children->content); - xmlNode *version = findXMLPropertyByName(package_node, "version"); - tmp = (char*)findXMLAttributeByName(version, "epoch"); - newheadersourcelist->epoch = atoi(tmp); - free(tmp); - newheadersourcelist->version = (char*)findXMLAttributeByName(version, "ver"); - newheadersourcelist->release = (char*)findXMLAttributeByName(version, "rel"); + newheadersourcelist->name = package_name; + newheadersourcelist->epoch = package_epoch; + newheadersourcelist->version = package_version; + newheadersourcelist->release = package_release; newheadersourcelist->summary = strdup((char*) findXMLPropertyByName(package_node, "summary")->children->content); newheadersourcelist->arch = strdup((char*)