Commit c28807eb authored by Bernhard Link's avatar Bernhard Link

Moved some more code to target.c

parent 8eeb7d3e
......@@ -346,45 +346,6 @@ retvalue binaries_findnew(packagesdb pkgs,const char *component,const char *pack
return chunk_foreach(packages_file,processbinary,&mydata,force,0);
}
/* Add a binary package to a distribution, removing previous versions
* of it, if necesary. */
retvalue binaries_addtodist(const char *dbpath,DB *references,const char *codename,const char *component,const char *architecture,const char *package,const char *version,const char *controlchunk,const struct strlist *filekeys) {
retvalue result,r;
char *oldversion;
packagesdb packages;
struct strlist oldfilekeys,*o;
r = packages_init(&packages,dbpath,codename,component,architecture);
if( RET_WAS_ERROR(r) ) {
return r;
}
r = binaries_lookforolder(packages,package,version,&oldversion,&oldfilekeys);
if( RET_WAS_ERROR(r) ) {
(void)packages_done(packages);
return r;
}
if( RET_IS_OK(r) )
o = &oldfilekeys;
else
o = NULL;
if( RET_IS_OK(r) && oldversion ) {
fprintf(stderr,"Version '%s' already in the archive, skipping '%s'\n",oldversion,version);
free(oldversion);
result = RET_NOTHING;
} else
result = packages_insert(references,packages,
package, controlchunk, filekeys, o);
r = packages_done(packages);
RET_ENDUPDATE(result,r);
if( o )
strlist_done(&oldfilekeys);
return result;
}
retvalue binaries_getname(target t,const char *control,char **packagename){
retvalue r;
......
......@@ -47,10 +47,6 @@ retvalue binaries_findnew(
int force
);
/* Add a binary package to a distribution, removing previous versions
* of it, if necesary. */
retvalue binaries_addtodist(const char *dbpath,DB *references,const char *codename,const char *component,const char *architecture,const char *package,const char *version,const char *controlchunk,const struct strlist *filekeys);
/* Functions for the target.h-stuff: */
retvalue binaries_getname(target t,const char *chunk,char **packagename);
retvalue binaries_getversion(target t,const char *chunk,char **version);
......
......@@ -379,10 +379,16 @@ retvalue deb_add(const char *dbdir,DB *references,filesdb filesdb,const char *fo
result = RET_NOTHING;
if( strcmp(pkg->architecture,"all") != 0 ) {
r = binaries_addtodist(dbdir,references,distribution->codename,pkg->component,pkg->architecture,pkg->package,pkg->version,pkg->control,&pkg->filekeys);
target t = distribution_getpart(distribution,pkg->component,pkg->architecture);
r = target_initpackagesdb(t,dbdir,NULL);
if( !RET_WAS_ERROR(r) )
r = target_addpackage(t,references,NULL,pkg->package,pkg->version,pkg->control,&pkg->filekeys,NULL,force,0);
RET_UPDATE(result,r);
} else for( i = 0 ; i < distribution->architectures.count ; i++ ) {
r = binaries_addtodist(dbdir,references,distribution->codename,pkg->component,distribution->architectures.values[i],pkg->package,pkg->version,pkg->control,&pkg->filekeys);
target t = distribution_getpart(distribution,pkg->component,distribution->architectures.values[i]);
r = target_initpackagesdb(t,dbdir,NULL);
if( !RET_WAS_ERROR(r) )
r = target_addpackage(t,references,NULL,pkg->package,pkg->version,pkg->control,&pkg->filekeys,NULL,force,0);
RET_UPDATE(result,r);
}
......
......@@ -445,11 +445,12 @@ retvalue dsc_add(const char *dbdir,DB *references,filesdb filesdb,const char *fo
r = dsc_complete(pkg);
/* finaly put it into the source distribution */
if( !RET_WAS_ERROR(r) )
r = sources_addtodist(dbdir,references,distribution->codename,
pkg->component,pkg->package,pkg->version,
pkg->control,&pkg->filekeys);
if( !RET_WAS_ERROR(r) ) {
target t = distribution_getpart(distribution,pkg->component,"source");
r = target_initpackagesdb(t,dbdir,NULL);
if( !RET_WAS_ERROR(r) )
r = target_addpackage(t,references,NULL,pkg->package,pkg->version,pkg->control,&pkg->filekeys,NULL,force,0);
}
dsc_free(pkg);
return r;
......
......@@ -48,10 +48,57 @@ void distribution_free(struct distribution *distribution) {
strlist_done(&distribution->architectures);
strlist_done(&distribution->components);
strlist_done(&distribution->updates);
while( distribution->targets ) {
target next = distribution->targets->next;
target_free(distribution->targets);
distribution->targets = next;
}
free(distribution);
}
}
/* create all contained targets... */
static retvalue createtargets(struct distribution *distribution) {
retvalue r;
int i,j;
const char *arch,*comp;
target t;
target last = NULL;
for( i = 0 ; i < distribution->components.count ; i++ ) {
comp = distribution->components.values[i];
for( j = 0 ; j < distribution->architectures.count ; j++ ) {
arch = distribution->architectures.values[j];
if( strcmp(arch,"source") != 0 ) {
r = target_initialize_binary(distribution->codename,comp,arch,&t);
if( RET_IS_OK(r) ) {
if( last ) {
last->next = t;
} else {
distribution->targets = t;
}
last = t;
}
if( RET_WAS_ERROR(r) )
return r;
}
}
r = target_initialize_source(distribution->codename,comp,&t);
if( last ) {
last->next = t;
} else {
distribution->targets = t;
}
last = t;
if( RET_WAS_ERROR(r) )
return r;
}
return RET_OK;
}
static retvalue distribution_parse(struct distribution **distribution,const char *chunk) {
struct distribution *r;
retvalue ret;
......@@ -85,6 +132,9 @@ static retvalue distribution_parse(struct distribution **distribution,const char
ret = chunk_getwordlist(chunk,"Update",&r->updates);
checkret;
ret = createtargets(r);
checkret;
*distribution = r;
return RET_OK;
}
......@@ -117,32 +167,11 @@ static retvalue distribution_parse_and_filter(struct distribution **distribution
/* call <action> for each part of <distribution>. */
retvalue distribution_foreach_part(const struct distribution *distribution,distribution_each_action action,void *data,int force) {
retvalue result,r;
int i,j;
const char *arch,*comp;
target t;
result = RET_NOTHING;
for( i = 0 ; i < distribution->components.count ; i++ ) {
comp = distribution->components.values[i];
for( j = 0 ; j < distribution->architectures.count ; j++ ) {
arch = distribution->architectures.values[j];
if( strcmp(arch,"source") != 0 ) {
r = target_initialize_binary(distribution->codename,comp,arch,&t);
if( RET_IS_OK(r) ) {
r = action(data,t);
target_done(t);
}
RET_UPDATE(result,r);
if( RET_WAS_ERROR(r) && force <= 0 )
return result;
}
}
r = target_initialize_source(distribution->codename,comp,&t);
if( RET_IS_OK(r) ) {
r = action(data,t);
target_done(t);
}
for( t = distribution->targets ; t ; t = t->next ) {
r = action(data,t);
RET_UPDATE(result,r);
if( RET_WAS_ERROR(r) && force <= 0 )
return result;
......@@ -150,6 +179,18 @@ retvalue distribution_foreach_part(const struct distribution *distribution,distr
return result;
}
target distribution_getpart(const struct distribution *distribution,const char *component,const char *architecture) {
target t = distribution->targets;
while( t && ( strcmp(t->component,component) != 0 || strcmp(t->architecture,architecture) )) {
t = t->next;
}
assert(t);
return t;
}
struct dist_mydata {struct distribution_filter filter; distributionaction *action; void *data;};
static retvalue processdistribution(void *d,const char *chunk) {
......
......@@ -17,6 +17,8 @@ struct distribution {
char *codename,*suite,*version;
char *origin,*label,*description;
struct strlist architectures,components,updates;
/* A list of all targets contained in the distribution*/
target targets;
};
......@@ -28,6 +30,8 @@ typedef retvalue distribution_each_action(void *data, const target t);
/* call <action> for each part of <distribution>. */
retvalue distribution_foreach_part(const struct distribution *distribution,distribution_each_action action,void *data,int force);
target distribution_getpart(const struct distribution *distribution,const char *component,const char *architecture);
typedef retvalue distributionaction(void *data,const char *chunk,const struct distribution *distribution);
/* call <action> for each distribution-chunk from <conf> fitting in the filter given in <argc,argv> */
......
......@@ -697,7 +697,9 @@ static retvalue exportbinsrc(void *data,const target target) {
if( RET_WAS_ERROR(result) && !force )
return result;
r = target_doexport(target,dbdir,distdir,d->force);
r = target_initpackagesdb(target,dbdir,NULL);
if( !RET_WAS_ERROR(r) )
r = target_export(target,distdir,d->force);
RET_UPDATE(result,r);
return result;
......@@ -792,7 +794,6 @@ static int update(int argc,char *argv[]) {
static int upgrade(int argc,char *argv[]) {
retvalue result,r;
upgradelist upgrade;
packagesdb pkgs;
filesdb files;
target target;
......@@ -811,15 +812,9 @@ static int upgrade(int argc,char *argv[]) {
return EXIT_RET(r);
}
r = packages_initialize(&pkgs,dbdir,target->identifier);
if( RET_WAS_ERROR(r) ) {
target_done(target);
return EXIT_RET(r);
}
result = upgradelist_initialize(&upgrade,target,pkgs,ud_always);
result = upgradelist_initialize(&upgrade,target,dbdir,ud_always);
if( RET_WAS_ERROR(result) ) {
target_done(target);
(void)packages_done(pkgs);
target_free(target);
return EXIT_RET(result);
}
......@@ -835,8 +830,6 @@ static int upgrade(int argc,char *argv[]) {
r = upgradelist_done(upgrade);
RET_ENDUPDATE(result,r);
r = packages_done(pkgs);
RET_ENDUPDATE(result,r);
return EXIT_RET(result);
}
......@@ -848,7 +841,9 @@ static retvalue reref(void *data,const target target) {
retvalue result;
struct data_binsrcreref *d = data;
result = target_rereference(dbdir,d->references,target,force);
result = target_initpackagesdb(target,dbdir,NULL);
if( !RET_WAS_ERROR(result) )
result = target_rereference(target,d->references,force);
return result;
}
......@@ -894,8 +889,12 @@ struct data_check { const struct distribution *distribution; DB *references; fil
static retvalue check_target(void *data,const target target) {
struct data_check *d = data;
retvalue r;
return target_check(dbdir,d->files,d->references,target,force);
r = target_initpackagesdb(target,dbdir,NULL);
if( RET_WAS_ERROR(r) )
return r;
return target_check(target,d->files,d->references,force);
}
static retvalue check_dist(void *data,const char *chunk,const struct distribution *distribution) {
......
......@@ -473,45 +473,6 @@ retvalue sources_parse_getmd5sums(const char *chunk,struct strlist *basenames, s
return r;
}
/* Add a source package to a distribution, removing previous versions
* of it, if necesary. */
retvalue sources_addtodist(const char *dbpath,DB *references,const char *codename,const char *component,const char *package,const char *version,const char *controlchunk,const struct strlist *filekeys) {
retvalue result,r;
char *oldversion;
packagesdb packages;
struct strlist oldfilekeys,*o;
r = packages_init(&packages,dbpath,codename,component,"source");
if( RET_WAS_ERROR(r) ) {
return r;
}
r = sources_lookforolder(packages,package,version,&oldversion,&oldfilekeys);
if( RET_WAS_ERROR(r) ) {
(void)packages_done(packages);
return r;
}
if( RET_IS_OK(r) )
o = &oldfilekeys;
else
o = NULL;
if( RET_IS_OK(r) && oldversion ) {
fprintf(stderr,"Version '%s' already in the archive, skipping '%s'\n",oldversion,version);
free(oldversion);
result = RET_NOTHING;
} else
result = packages_insert(references,packages,
package, controlchunk, filekeys, o);
r = packages_done(packages);
RET_ENDUPDATE(result,r);
if( o )
strlist_done(&oldfilekeys);
return result;
}
retvalue sources_calcfilelines(const struct strlist *basenames,const struct strlist *md5sums,char **item) {
size_t len;
int i;
......
......@@ -33,10 +33,6 @@ retvalue sources_lookforold(packagesdb packages,const char *packagename,
* (i.e. "main","contrib",...) for generated paths */
retvalue sources_findnew(packagesdb pkgs,const char *component,const char *sources_file,new_package_action action,void *data,int force);
/* Add a source package to a distribution, removing previous versions
* of it, if necesary. */
retvalue sources_addtodist(const char *dbpath,DB *references,const char *codename,const char *component,const char *package,const char *version,const char *controlchunk,const struct strlist *filekeys);
/* Calculate the filelines in a form suitable for chunk_replacefields: */
retvalue sources_calcfilelines(const struct strlist *basenames,const struct strlist *md5sums,char **item);
......
......@@ -33,6 +33,7 @@
#include "sources.h"
#include "names.h"
#include "md5sum.h"
#include "dpkgversions.h"
#include "target.h"
extern int verbose;
......@@ -64,7 +65,7 @@ static retvalue target_initialize(
t->architecture = strdup(architecture);
t->identifier = calc_identifier(codename,component,architecture);
if( !t->codename|| !t->component|| !t->architecture|| !t->identifier) {
target_done(t);
target_free(t);
return RET_ERROR_OOM;
}
t->getname = getname;
......@@ -84,7 +85,7 @@ retvalue target_initialize_source(const char *codename,const char *component,tar
}
void target_done(target target) {
void target_free(target target) {
if( target == NULL )
return;
free(target->codename);
......@@ -95,20 +96,74 @@ void target_done(target target) {
free(target);
}
retvalue target_addpackage(target target,packagesdb packages,DB *references,filesdb files,const char *name,const char *version,const char *control,const struct strlist *filekeys,const struct strlist *md5sums,int force) {
/* This opens up the database, if db != NULL, *db will be set to it.. */
retvalue target_initpackagesdb(target target, const char *dbdir, packagesdb *db) {
retvalue r;
if( target->packages != NULL )
r = RET_OK;
else {
r = packages_initialize(&target->packages,dbdir,target->identifier);
if( RET_WAS_ERROR(r) ) {
target->packages = NULL;
return r;
}
}
if( db )
*db = target->packages;
return r;
}
retvalue target_addpackage(target target,DB *references,filesdb files,const char *name,const char *version,const char *control,const struct strlist *filekeys,const struct strlist *md5sums,int force,int downgrade) {
struct strlist oldfilekeys,*ofk;
char *oldcontrol;
retvalue r;
r = files_expectfiles(files,filekeys,md5sums);
if( RET_WAS_ERROR(r) )
return r;
r = packages_get(packages,name,&oldcontrol);
assert(target->packages);
if( md5sums != NULL ) {
r = files_expectfiles(files,filekeys,md5sums);
if( RET_WAS_ERROR(r) )
return r;
}
r = packages_get(target->packages,name,&oldcontrol);
if( RET_WAS_ERROR(r) )
return r;
if( r == RET_NOTHING )
ofk = NULL;
else {
char *oldversion;
r = target->getversion(target,oldcontrol,&oldversion);
if( RET_WAS_ERROR(r) && !force ) {
free(oldcontrol);
return r;
}
if( RET_IS_OK(r) ) {
r = dpkgversions_isNewer(version,oldversion);
if( RET_WAS_ERROR(r) ) {
fprintf(stderr,"Parse errors processing versions of %s.\n",name);
if( !force ) {
free(oldversion);
free(oldcontrol);
return r;
}
} else {
if( r == RET_NOTHING ) {
/* new Version is not newer than old version */
if( downgrade ) {
fprintf(stderr,"Warning: downgrading '%s' from '%s' to '%s' in '%s'!\n",name,oldversion,version,target->identifier);
} else {
fprintf(stderr,"Skipping inclusion of '%s' '%s' in '%s', as it has already '%s'.\n",name,version,target->identifier,oldversion);
free(oldversion);
free(oldcontrol);
return RET_NOTHING;
}
}
}
free(oldversion);
}
r = target->getfilekeys(target,name,oldcontrol,&oldfilekeys);
free(oldcontrol);
ofk = &oldfilekeys;
......@@ -119,7 +174,7 @@ retvalue target_addpackage(target target,packagesdb packages,DB *references,file
return r;
}
}
r = packages_insert(references,packages,name,control,filekeys,&oldfilekeys);
r = packages_insert(references,target->packages,name,control,filekeys,&oldfilekeys);
if( ofk )
strlist_done(ofk);
return r;
......@@ -127,7 +182,6 @@ retvalue target_addpackage(target target,packagesdb packages,DB *references,file
/* rereference a full database */
struct data_reref {
packagesdb packagesdb;
DB *referencesdb;
target target;
};
......@@ -150,14 +204,12 @@ static retvalue rereferencepkg(void *data,const char *package,const char *chunk)
return r;
}
retvalue target_rereference(const char *dbdir,DB *referencesdb,target target,int force) {
retvalue target_rereference(target target,DB *referencesdb,int force) {
retvalue result,r;
struct data_reref refdata;
packagesdb pkgs;
r = packages_initialize(&pkgs,dbdir,target->identifier);
if( RET_WAS_ERROR(r) )
return r;
assert(target->packages);
if( verbose > 1 ) {
if( verbose > 2 )
fprintf(stderr,"Unlocking depencies of %s...\n",target->identifier);
......@@ -171,20 +223,15 @@ retvalue target_rereference(const char *dbdir,DB *referencesdb,target target,int
fprintf(stderr,"Referencing %s...\n",target->identifier);
refdata.referencesdb = referencesdb;
refdata.packagesdb = pkgs;
refdata.target = target;
r = packages_foreach(pkgs,rereferencepkg,&refdata,force);
r = packages_foreach(target->packages,rereferencepkg,&refdata,force);
RET_UPDATE(result,r);
r = packages_done(pkgs);
RET_ENDUPDATE(result,r);
return result;
}
/* check a full database */
struct data_check {
packagesdb packagesdb;
DB *referencesdb;
filesdb filesdb;
target target;
......@@ -209,34 +256,24 @@ static retvalue checkpkg(void *data,const char *package,const char *chunk) {
return r;
}
retvalue target_check(const char *dbdir,filesdb filesdb,DB *referencesdb,target target,int force) {
retvalue result,r;
retvalue target_check(target target,filesdb filesdb,DB *referencesdb,int force) {
struct data_check data;
packagesdb pkgs;
r = packages_initialize(&pkgs,dbdir,target->identifier);
if( RET_WAS_ERROR(r) )
return r;
assert(target->packages);
if( verbose > 1 ) {
fprintf(stderr,"Checking packages in '%s'...\n",pkgs->identifier);
fprintf(stderr,"Checking packages in '%s'...\n",target->identifier);
}
data.referencesdb = referencesdb;
data.filesdb = filesdb;
data.packagesdb = pkgs;
data.target = target;
result = packages_foreach(pkgs,checkpkg,&data,force);
r = packages_done(pkgs);
RET_ENDUPDATE(result,r);
return result;
return packages_foreach(target->packages,checkpkg,&data,force);
}
/* export a database */
retvalue target_export(target target,packagesdb packages,const char *distdir,int force) {
retvalue target_export(target target,const char *distdir,int force) {
indexcompression compression;
retvalue result,r;
assert(target && packages);
assert(target && target->packages);
result = RET_NOTHING;
for( compression = 0 ; compression <= ic_max ; compression++) {
......@@ -247,7 +284,7 @@ retvalue target_export(target target,packagesdb packages,const char *distdir,int
target->indexfile,compression);
if( filename == NULL )
return RET_ERROR_OOM;
r = packages_export(packages,filename,compression);
r = packages_export(target->packages,filename,compression);
free(filename);
RET_UPDATE(result,r);
if( !force && RET_WAS_ERROR(r) )
......@@ -256,22 +293,6 @@ retvalue target_export(target target,packagesdb packages,const char *distdir,int
}
return result;
}
/* export a database, also open the file... */
retvalue target_doexport(target target,const char *dbdir,const char *distdir, int force) {
retvalue result,r;
packagesdb pkgs;
r = packages_initialize(&pkgs,dbdir,target->identifier);
if( RET_WAS_ERROR(r) )
return r;
result = target_export(target,pkgs,distdir,force);
r = packages_done(pkgs);
RET_ENDUPDATE(result,r);
return result;
}
static inline retvalue printfilemd5(target target,const char *distdir,FILE *out,
const char *filename,indexcompression compression) {
......
......@@ -30,16 +30,27 @@ struct s_target {
get_version *getversion;
get_installdata *getinstalldata;
get_filekeys *getfilekeys;
/* the next one in the list of targets of a distribution */
struct s_target *next;
/* is initialized as soon as needed: */
packagesdb packages;
};
retvalue target_initialize_binary(const char *distribution,const char *component,const char *architecture,target *target);
retvalue target_initialize_source(const char *distribution,const char *component,target *target);
void target_done(target target);
retvalue target_initialize_binary(const char *codename,const char *component,const char *architecture,target *target);
retvalue target_initialize_source(const char *codename,const char *component,target *target);
void target_free(target target);
retvalue target_addpackage(target target,packagesdb packages,DB *references,filesdb files,const char *name,const char *version,const char *control,const struct strlist *filekeys,const struct strlist *md5sums,int force);
retvalue target_rereference(const char *dbdir,DB *referencesdb,target target,int force);
retvalue target_check(const char *dbdir,filesdb filesdb,DB *referencesdb,target target,int force);
retvalue target_export(target target,packagesdb packages,const char *distdir, int force);
retvalue target_doexport(target target,const char *dbdir,const char *distdir, int force);
retvalue target_printmd5sums(target target,const char *distdir,FILE *out,int force);
/* This opens up the database, if db != NULL, *db will be set to it.. */
retvalue target_initpackagesdb(target target, const char *dbdir, packagesdb *db);
/* The following calls can only be called if target_initpackagesdb was called before: */
retvalue target_addpackage(target target,DB *references,filesdb files,const char *name,const char *version,const char *control,const struct strlist *filekeys,const struct strlist *md5sums,int force,int downgrade);
retvalue target_export(target target,const char *distdir, int force);
retvalue target_check(target target,filesdb filesdb,DB *referencesdb,int force);
retvalue target_rereference(target target,DB *referencesdb,int force);
#endif
......@@ -58,7 +58,6 @@ typedef struct s_package_data {
struct s_upgradelist {
upgrade_decide_function *decide;
packagesdb packages;
target target;
package_data *list;
/* NULL or the last/next thing to test in alphabetical order */
......@@ -127,8 +126,9 @@ static retvalue save_package_version(void *d,const char *packagename,const char
}
retvalue upgradelist_initialize(upgradelist *ul,target t,packagesdb packages,upgrade_decide_function *decide) {
retvalue upgradelist_initialize(upgradelist *ul,target t,const char *dbdir,upgrade_decide_function *decide) {
upgradelist upgrade;
packagesdb packages;
retvalue r;
upgrade = calloc(1,sizeof(struct s_upgradelist));
......@@ -136,9 +136,14 @@ retvalue upgradelist_initialize(upgradelist *ul,target t,packagesdb packages,upg
return RET_ERROR_OOM;
upgrade->decide = decide;
upgrade->packages = packages;
upgrade->target = t;
r = target_initpackagesdb(t,dbdir,&packages);
if( RET_WAS_ERROR(r) ) {
upgradelist_done(upgrade);
return r;
}
r = packages_foreach(packages,save_package_version,upgrade,0);
if( RET_WAS_ERROR(r) ) {
......@@ -356,10 +361,11 @@ retvalue upgradelist_install(upgradelist upgrade,filesdb files,DB *references,in
result = RET_NOTHING;
while( pkg ) {
if( pkg->version == pkg->new_version ) {
// TODO: decide what to give to the downgrade flag...
r = target_addpackage(upgrade->target,
upgrade->packages,references,files,
references,files,
pkg->name,pkg->new_version,pkg->new_control,
&pkg->new_filekeys,&pkg->new_md5sums,force);
&pkg->new_filekeys,&pkg->new_md5sums,force,0);
RET_UPDATE(result,r);
if( RET_WAS_ERROR(r) && !force )
break;
......
......@@ -20,7 +20,7 @@ upgrade_decision ud_always(const char *p,const char *ov,const char *nv);
typedef struct s_upgradelist *upgradelist;
retvalue upgradelist_initialize(upgradelist *ul,target target, packagesdb packages,upgrade_decide_function *decide);
retvalue upgradelist_initialize(upgradelist *ul,target target,const char *dbdir,upgrade_decide_function *decide);
retvalue upgradelist_done(upgradelist upgrade);
retvalue upgradelist_dump(upgradelist upgrade);
......
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