From 57786153d2e6bf9191fcb38fa242b9b56be19f28 Mon Sep 17 00:00:00 2001 From: Silvan Calarco Date: Sun, 6 Oct 2013 16:31:06 +0200 Subject: [PATCH] Fix version requirements checks with multiple providers Also make providedList more linear by removing numversions and using numproviders for provider[] and version[] vectors --- src/distromatic.c | 60 ++++++++++++++++++++++++++++------------ src/headerlist.c | 23 +++++---------- src/include/headerlist.h | 1 - 3 files changed, 50 insertions(+), 34 deletions(-) diff --git a/src/distromatic.c b/src/distromatic.c index c923388..91e90ca 100644 --- a/src/distromatic.c +++ b/src/distromatic.c @@ -417,10 +417,11 @@ static int resolveFirstLevelDependencies(struct configTag *ct, int archidx) { struct headerList *currheader, *scanheader, **newprovider; - struct providedList *provided; + struct providedList *provided, *foundverprovided; struct fileTree *file; int i,j,k,found; char warning[PATH_MAX]; + char ** newversion; currheader = ct->headerlist[archidx]; @@ -593,51 +594,76 @@ resolveFirstLevelDependencies(struct configTag *ct, int archidx) newprovider[j]=provided->provider[j]; } newprovider[provided->numproviders-1] = file->provider[k]; - free(provided->provider); + if (provided->provider) free(provided->provider); provided->provider=newprovider; + newversion=malloc(sizeof(char *)*provided->numproviders); + for (j = 0; j < provided->numproviders-1; j++) { + newversion[j]=provided->version[j]; + } + newversion[provided->numproviders-1] = strdup(provided->provider[j]->version); + if (provided->version) free(provided->version); + provided->version=newversion; } } } } - if (provided->numversions > 0) { + if (provided->numproviders > 0) { if (strcmp(currheader->require[i]->version,"") && (currheader->require[i]->flags & (RPMSENSE_LESS|RPMSENSE_GREATER|RPMSENSE_EQUAL))) { found = 0; - for (j = 0; j < provided->numversions; j++) { + foundverprovided = NULL; + + for (j = 0; j < provided->numproviders; j++) { + if (foundverprovided && !strcmp(foundverprovided->name,provided->name)) { + found = 0; + foundverprovided = NULL; + } if (!strcmp(provided->version[j],"")) { /* provider with no version; assume ok */ found = 1; + foundverprovided=provided; } else { if (checkVersionWithFlags( currheader->require[i]->version, currheader->require[i]->flags, - provided->version[j])) found = 1; + provided->version[j])) { + found = 1; + foundverprovided=provided; + } } } /* for */ if (!found) { - for (j = 0; j < provided->numversions; j++) { - snprintf(warning, PATH_MAX, "%s = %s fails to provide %s ", + for (j = 0; j < provided->numproviders; j++) { + if (!checkVersionWithFlags( + currheader->require[i]->version, + currheader->require[i]->flags, + provided->version[j])) { + snprintf(warning, PATH_MAX, "%s = %s from %s(%s,%s) fails to provide %s ", provided->name, provided->version[j], + provided->provider[j]->name, + provided->provider[j]->arch, + ct->repository[provided->provider[j]->altrepository]->tag, provided->name); - if (currheader->require[i]->flags & RPMSENSE_LESS) snprintf(&warning[strlen(warning)], PATH_MAX,"<"); - if (currheader->require[i]->flags & RPMSENSE_GREATER) snprintf(&warning[strlen(warning)], PATH_MAX, ">"); - if (currheader->require[i]->flags & RPMSENSE_EQUAL) snprintf(&warning[strlen(warning)], PATH_MAX, "="); - snprintf(&warning[strlen(warning)], PATH_MAX, " %s to %s(%s,%s)", + if (currheader->require[i]->flags & RPMSENSE_LESS) snprintf(&warning[strlen(warning)], PATH_MAX,"<"); + if (currheader->require[i]->flags & RPMSENSE_GREATER) snprintf(&warning[strlen(warning)], PATH_MAX, ">"); + if (currheader->require[i]->flags & RPMSENSE_EQUAL) snprintf(&warning[strlen(warning)], PATH_MAX, "="); + snprintf(&warning[strlen(warning)], PATH_MAX, " %s to %s(%s,%s)", currheader->require[i]->version, currheader->name, currheader->arch, ct->repository[currheader->altrepository]->tag); - for (k = 0; k < provided->numproviders; k++) { - if (provided->provider[k]->sourceheader && - (provided->provider[k]->altrepository == ct->repository_level)) { + for (k = 0; k < provided->numproviders; k++) { + if (provided->provider[k]->sourceheader && + (provided->provider[k]->altrepository == ct->repository_level)) { fprintf(stderr,"Warning: %s\n", warning); - addWarning(provided->provider[k]->sourceheader, warning); + addWarning(provided->provider[k]->sourceheader, warning); + } } - } + } } } @@ -738,7 +764,7 @@ resolveFirstLevelSourceDependencies(struct configTag *ct, int archidx) if (strcmp(currsourceheader->require[i]->version,"") && (currsourceheader->require[i]->flags & (RPMSENSE_LESS+RPMSENSE_GREATER+RPMSENSE_EQUAL))) { found = 0; - for (j = 0; j < provided->numversions; j++) { + for (j = 0; j < provided->numproviders; j++) { if (!strcmp(provided->version[j],"")) { /* provider with no version; assume ok */ found = 1; diff --git a/src/headerlist.c b/src/headerlist.c index 999a556..082636a 100644 --- a/src/headerlist.c +++ b/src/headerlist.c @@ -456,7 +456,6 @@ findOrCreateProvidedListEntry(struct providedList* *idx, newprovided->provider = NULL; newprovided->numproviders = 0; newprovided->numbuildproviders = 0; - newprovided->numversions = 0; newprovided->buildprovider = NULL; newprovided->name = strdup(findname); newprovided->id = ++providedListId; @@ -1003,7 +1002,6 @@ addToHeaderList(struct configTag *ct, provided->numproviders++; provided->provider=malloc(sizeof(struct headerList*)); provided->provider[0]=newheaderlist; - provided->numversions++; provided->version=malloc(sizeof(char *)); provided->version[0]=strdup(provideversion[i]); } else if (provided && (provided->numproviders > 0)) { @@ -1016,21 +1014,14 @@ addToHeaderList(struct configTag *ct, free(provided->provider); provided->provider=newprovider; - // check if version is already provided - for (j = 0; j < provided->numversions; j++) { - if (!strcmp(provided->version[j],provideversion[i])) break; - } - // if not add to the list of versions - if (j == provided->numversions) { - provided->numversions++; - newversion=malloc(sizeof(char *)*provided->numversions); - for (j = 0; j < provided->numversions-1; j++) { - newversion[j]=provided->version[j]; - } - newversion[provided->numversions-1] = strdup(provideversion[i]); - free(provided->version); - provided->version=newversion; + newversion=malloc(sizeof(char *)*provided->numproviders); + for (j = 0; j < provided->numproviders-1; j++) { + newversion[j]=provided->version[j]; } + newversion[provided->numproviders-1] = strdup(provideversion[i]); + free(provided->version); + provided->version=newversion; + } else { fprintf(stderr,"%s has %d providers but is ignored\n",provided->name,provided->numproviders); } diff --git a/src/include/headerlist.h b/src/include/headerlist.h index 75b2c7d..0e95b36 100644 --- a/src/include/headerlist.h +++ b/src/include/headerlist.h @@ -29,7 +29,6 @@ struct providedList { struct headerList **provider; int numbuildproviders; struct headerList **buildprovider; - int numversions; char **version; int buildpriority; struct providedList *next;