Commit 595922bb authored by Bernhard Link's avatar Bernhard Link

[refactor] refactor old data handling in trackingdata_insert and target.c's addpackages

parent a695b4fd
......@@ -340,7 +340,7 @@ retvalue package_remove_by_cursor(struct package_cursor *tc, struct logger *logg
return result;
}
static retvalue addpackages(struct target *target, const char *packagename, const char *controlchunk, /*@null@*/const char *oldcontrolchunk, const char *version, /*@null@*/const char *oldversion, const struct strlist *files, /*@only@*//*@null@*/struct strlist *oldfiles, /*@null@*/struct logger *logger, /*@null@*/struct trackingdata *trackingdata, architecture_t architecture, /*@null@*/const char *oldsource, /*@null@*/const char *oldsversion, /*@null@*/const char *causingrule, /*@null@*/const char *suitefrom) {
static retvalue addpackages(struct target *target, const char *packagename, const char *controlchunk, const char *version, const struct strlist *files, /*@null@*/const struct package *old, /*@only@*//*@null@*/struct strlist *oldfiles, /*@null@*/struct logger *logger, /*@null@*/struct trackingdata *trackingdata, architecture_t architecture, /*@null@*/const char *causingrule, /*@null@*/const char *suitefrom) {
retvalue result, r;
struct table *table = target->packages;
......@@ -367,7 +367,7 @@ static retvalue addpackages(struct target *target, const char *packagename, cons
/* Add package to the distribution's database */
if (oldcontrolchunk != NULL) {
if (old != NULL) {
result = table_replacerecord(table, packagename, controlchunk);
} else {
......@@ -381,16 +381,25 @@ static retvalue addpackages(struct target *target, const char *packagename, cons
}
if (logger != NULL) {
if (oldversion == NULL && oldcontrolchunk != NULL)
oldversion = "#unparseable";
logger_log(logger, target, packagename,
version, oldversion,
version,
/* the old version, NULL if there is
* no old package,
* "#unparseable" if there is old but
* no version available */
(old==NULL)
? NULL
: (old->version == NULL)
? "#unparseable"
: old->version,
files, oldfiles, causingrule, suitefrom);
}
r = trackingdata_insert(trackingdata, filetype, files,
oldsource, oldsversion, oldfiles);
RET_UPDATE(result, r);
if (trackingdata != NULL) {
r = trackingdata_insert(trackingdata,
filetype, files, old, oldfiles);
RET_UPDATE(result, r);
}
/* remove old references to files */
......@@ -406,7 +415,7 @@ static retvalue addpackages(struct target *target, const char *packagename, cons
retvalue target_addpackage(struct target *target, struct logger *logger, const char *name, const char *version, const char *control, const struct strlist *filekeys, bool downgrade, struct trackingdata *trackingdata, architecture_t architecture, const char *causingrule, const char *suitefrom) {
struct strlist oldfilekeys, *ofk;
char *newcontrol;
struct package old;
struct package old, *old_p;
retvalue r;
assert(target->packages!=NULL);
......@@ -415,9 +424,11 @@ retvalue target_addpackage(struct target *target, struct logger *logger, const c
if (RET_WAS_ERROR(r))
return r;
if (r == RET_NOTHING) {
old_p = NULL;
ofk = NULL;
setzero(struct package, &old);
} else {
old_p = &old;
r = package_getversion(&old);
if (RET_WAS_ERROR(r) && !IGNORING(brokenold,
"Error parsing old version!\n")) {
......@@ -494,12 +505,12 @@ retvalue target_addpackage(struct target *target, struct logger *logger, const c
if (RET_IS_OK(r))
control = newcontrol;
if (!RET_WAS_ERROR(r))
r = addpackages(target, name, control, old.control,
version, old.version,
filekeys, ofk,
r = addpackages(target, name, control,
version,
filekeys,
old_p, ofk,
logger,
trackingdata, architecture,
old.source, old.sourceversion,
causingrule, suitefrom);
if (RET_IS_OK(r)) {
target->wasmodified = true;
......
......@@ -842,46 +842,44 @@ retvalue trackingdata_switch(struct trackingdata *data, const char *source, cons
return RET_OK;
}
retvalue trackingdata_insert(struct trackingdata *data, enum filetype filetype, const struct strlist *filekeys, /*@null@*/const char *oldsource, /*@null@*/const char*oldversion, /*@null@*/const struct strlist *oldfilekeys) {
retvalue trackingdata_insert(struct trackingdata *data, enum filetype filetype, const struct strlist *filekeys, /*@null@*/const struct package *old, /*@null@*/const struct strlist *oldfilekeys) {
retvalue result, r;
struct trackedpackage *pkg;
if (data == NULL) {
assert(oldversion == NULL && oldsource == NULL);
return RET_OK;
}
assert (data != NULL);
assert(data->pkg != NULL);
result = trackedpackage_adddupfilekeys(data->tracks, data->pkg,
filetype, filekeys, true);
if (RET_WAS_ERROR(result)) {
return result;
}
if (oldsource == NULL || oldversion == NULL || oldfilekeys == NULL) {
assert(oldsource==NULL&&oldversion==NULL&&oldfilekeys==NULL);
if (old == NULL || old->source == NULL || old->sourceversion == NULL
|| oldfilekeys == NULL) {
return RET_OK;
}
if (strcmp(oldversion, data->pkg->sourceversion) == 0 &&
strcmp(oldsource, data->pkg->sourcename) == 0) {
if (strcmp(old->sourceversion, data->pkg->sourceversion) == 0 &&
strcmp(old->source, data->pkg->sourcename) == 0) {
/* Unlikely, but it may also be the same source version as
* the package we are currently adding */
return trackedpackage_removefilekeys(data->tracks, data->pkg,
oldfilekeys);
}
r = tracking_get(data->tracks, oldsource, oldversion, &pkg);
r = tracking_get(data->tracks, old->source, old->sourceversion, &pkg);
if (RET_WAS_ERROR(r)) {
return r;
}
if (r == RET_NOTHING) {
fprintf(stderr,
"Could not found tracking data for %s_%s in %s to remove old files from it.\n",
oldsource, oldversion, data->tracks->codename);
old->source, old->sourceversion,
data->tracks->codename);
return result;
}
r = trackedpackage_removefilekeys(data->tracks, pkg, oldfilekeys);
RET_UPDATE(result, r);
r = tracking_save(data->tracks, pkg);
RET_UPDATE(result, r);
r = trackingdata_remember(data, oldsource, oldversion);
r = trackingdata_remember(data, old->source, old->sourceversion);
RET_UPDATE(result, r);
return result;
......
......@@ -39,7 +39,8 @@ retvalue tracking_printall(trackingdb);
retvalue trackingdata_summon(trackingdb, const char *, const char *, struct trackingdata *);
retvalue trackingdata_new(trackingdb, struct trackingdata *);
retvalue trackingdata_switch(struct trackingdata *, const char *, const char *);
retvalue trackingdata_insert(struct trackingdata *, enum filetype, const struct strlist * /*filekeys*/, /*@null@*/const char * /*oldsource*/, /*@null@*/const char * /*oldversion*/, /*@null@*/const struct strlist * /*oldfilekeys*/);
struct package;
retvalue trackingdata_insert(struct trackingdata *, enum filetype, const struct strlist * /*filekeys*/, /*@null@*/const struct package * /*oldpackage*/, /*@null@*/const struct strlist * /*oldfilekeys*/);
retvalue trackingdata_remove(struct trackingdata *, const char */*oldsource*/, const char * /*oldversion*/, const struct strlist * /*filekeys*/);
void trackingdata_done(struct trackingdata *);
/* like _done but actually do something */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment