Commit 5a469d4c authored by Bernhard Link's avatar Bernhard Link

stage 3 of referencing of sources rewriting

parent 8777e11e
......@@ -132,25 +132,6 @@ int versioncompare(const struct versionrevision *version,
/* now own code */
int isVersionNewer(const char *first,const char *second) {
struct versionrevision v1,v2;
const char *m;
int r;
if( (m = parseversion(&v1,first)) != NULL ) {
fprintf(stderr,"Error while parsing '%s' as version: %s\n",first,m);
return -2;
}
if( (m = parseversion(&v2,second)) != NULL ) {
fprintf(stderr,"Error while parsing '%s' as version: %s\n",second,m);
return -2;
}
r = versioncompare(&v1,&v2);
free((char*)v1.version);
free((char*)v2.version);
return r>0;
}
retvalue dpkgversions_isNewer(const char *first,const char *second) {
struct versionrevision v1,v2;
const char *m;
......
......@@ -6,10 +6,6 @@
#warning wth?
#endif
/* code taken from dpkg to compare to version string, returns
* -2 on parsing errors, 1 if newer, 0 if not */
int isVersionNewer(const char *first,const char *second);
/* return RET_OK, if first >> second, RET_NOTHING if not,
* return error if those are not proper versions */
retvalue dpkgversions_isNewer(const char *first,const char *second);
......
......@@ -405,13 +405,12 @@ struct distributionhandles {
/***********************************addsources***************************/
static retvalue add_source(void *data,const char *chunk,const char *package,const char *version,const char *directory,const char *origdirectory,const struct strlist *files,const char *oldchunk) {
static retvalue add_source(void *data,const char *chunk,const char *package,const char *version,const char *directory,const char *origdirectory,const struct strlist *files,const char *olddirectory,const struct strlist *oldfiles) {
char *newchunk;
retvalue result,r;
struct distributionhandles *dist = (struct distributionhandles*)data;
int i;
struct strlist filekeys,oldfiles,oldfilekeys;
char *olddirectory;
struct strlist filekeys,oldfilekeys;
/* look for needed files */
......@@ -451,15 +450,7 @@ static retvalue add_source(void *data,const char *chunk,const char *package,cons
return r;
}
r = sources_parse_chunk(oldchunk,NULL,NULL,&olddirectory,&oldfiles);
if( !RET_IS_OK(r) ) {
free(newchunk);
strlist_done(&filekeys);
return r;
}
r = sources_getfilekeys(olddirectory,&oldfiles,&oldfilekeys);
free(olddirectory);strlist_done(&oldfiles);
r = sources_getfilekeys(olddirectory,oldfiles,&oldfilekeys);
if( RET_WAS_ERROR(r) ) {
free(newchunk);
strlist_done(&filekeys);
......@@ -519,7 +510,7 @@ static int addsources(int argc,char *argv[]) {
}
/****************************prepareaddsources********************************************/
static retvalue showmissingsourcefiles(void *data,const char *chunk,const char *package,const char *version,const char *directory,const char *origdirectory,const struct strlist *files,const char *oldchunk) {
static retvalue showmissingsourcefiles(void *data,const char *chunk,const char *package,const char *version,const char *directory,const char *origdirectory,const struct strlist *files,const char *olddirectory,const struct strlist *oldfiles) {
retvalue r,ret;
struct distributionhandles *dist = (struct distributionhandles*)data;
char *dn;
......
......@@ -157,70 +157,109 @@ retvalue sources_parse_chunk(const char *chunk,char **packagename,char **version
return RET_OK;
}
/* compare versions, 1= new is better, 0=old is better, <0 error */
static int sources_isnewer(const char *newchunk,const char *oldchunk) {
char *nv,*ov;
int r;
retvalue ret;
/* if new broken, tell it, if old broken, new is better: */
ret = chunk_getvalue(newchunk,"Version",&nv);
if( !RET_IS_OK(ret) )
return -1;
ret = chunk_getvalue(oldchunk,"Version",&ov);
if( !RET_IS_OK(ret) ) {
free(nv);
return 1;
/* Look for an older version of the Package in the database.
* Set *oldversion, if there is already a newer (or equal) version to
* <version> and <version> is != NULL */
retvalue sources_lookforolder(
DB *packages,const char *packagename,
const char *newversion,char **oldversion,
char **olddirectory,struct strlist *oldfiles) {
char *oldchunk,*ov;
retvalue r;
// TODO: why does packages_get return something else than a retvalue?
oldchunk = packages_get(packages,packagename);
if( oldchunk == NULL ) {
*olddirectory = NULL;
if( oldversion != NULL && newversion != NULL )
*oldversion = NULL;
return RET_NOTHING;
}
if( newversion ) {
assert(oldversion != NULL);
r = sources_parse_chunk(oldchunk,NULL,&ov,olddirectory,oldfiles);
} else {
assert( oldversion == NULL );
r = sources_parse_chunk(oldchunk,NULL,NULL,olddirectory,oldfiles);
}
r = isVersionNewer(nv,ov);
free(nv);free(ov);
if( !RET_IS_OK(r) ) {
if( r == RET_NOTHING ) {
fprintf(stderr,"Does not look like source control: '%s'\n",oldchunk);
r = RET_ERROR;
}
free(oldchunk);
return r;
}
if( newversion ) {
r = dpkgversions_isNewer(newversion,ov);
if( RET_WAS_ERROR(r) ) {
fprintf(stderr,"Parse errors processing versions of %s.\n",packagename);
free(ov);
free(*olddirectory);
*olddirectory = NULL;
strlist_done(oldfiles);
free(oldchunk);
return r;
}
if( RET_IS_OK(r) ) {
*oldversion = NULL;
free(ov);
} else
*oldversion = ov;
}
free(oldchunk);
return r;
}
//typedef retvalue source_package_action(void *data,const char *chunk,const char *package,const char *directory,const char *olddirectory,const char *files,const char *oldchunk);
//typedef retvalue source_package_action(void *data,const char *chunk,const char *package,const char *directory,const char *origdirectory,const char *files,const char *oldchunk);
struct sources_add {DB *pkgs; void *data; const char *component; source_package_action *action; };
static retvalue addsource(void *data,const char *chunk) {
retvalue r;
int isnewer;
struct sources_add *d = data;
char *package,*version,*directory,*olddirectory;
char *oldchunk;
struct strlist files;
char *package,*version,*directory,*origdirectory;
char *oldversion,*olddirectory;
struct strlist files,oldfiles;
r = sources_parse_chunk(chunk,&package,&version,&olddirectory,&files);
r = sources_parse_chunk(chunk,&package,&version,&origdirectory,&files);
if( r == RET_NOTHING ) {
// TODO: error?
return RET_ERROR;
} else if( RET_WAS_ERROR(r) ) {
return r;
}
oldchunk = packages_get(d->pkgs,package);
if( oldchunk && (isnewer=sources_isnewer(chunk,oldchunk)) != 0 ) {
if( isnewer < 0 ) {
fprintf(stderr,"Omitting %s because of parse errors.\n",package);
free(package);strlist_done(&files);
free(olddirectory);free(version);
free(oldchunk);
return RET_ERROR;
}
r = sources_lookforolder(d->pkgs,package,version,&oldversion,&olddirectory,&oldfiles);
if( RET_WAS_ERROR(r) ) {
free(version);free(origdirectory);strlist_done(&files);
return r;
}
if( oldchunk == NULL || isnewer > 0 ) {
if( oldversion != NULL ) {
if( verbose > 40 )
fprintf(stderr,"Ignoring '%s' with version '%s', as '%s'
is already there.\n",package,version,oldversion);
free(oldversion);
r = RET_NOTHING;
} else {
/* add source package */
directory = calc_sourcedir(d->component,package);
if( !directory )
r = RET_ERROR_OOM;
else
r = (*d->action)(d->data,chunk,package,version,directory,olddirectory,&files,oldchunk);
else
r = (*d->action)(d->data,chunk,package,version,directory,origdirectory,&files,olddirectory,&oldfiles);
free(directory);
} else {
r = RET_NOTHING;
}
free(oldchunk);
free(olddirectory);strlist_done(&oldfiles);
free(package);strlist_done(&files);
free(olddirectory);free(version);
free(origdirectory);free(version);
return r;
}
......
......@@ -32,11 +32,12 @@ typedef retvalue source_package_action(
/* the calculated directory it shall be put in (relative to mirrordir) */
const char *directory,
/* the directory specified by the chunk. (relative to dists/) */
const char *olddirectory,
const char *origdirectory,
/* a \n seperated list of md5sums,sizes and filenames, as parseable by sources_getfile */
const struct strlist *files,
/* !=NULL if there was a older chunk in the pkgs-database to be replaced */
const char *oldchunk);
const char *olddirectory,
const struct strlist *oldfiles);
/* call <data> for each package in the "Sources.gz"-style file <source_file> missing in
* <pkgs> and using <component> as subdir of pool (i.e. "main","contrib",...) for generated paths */
......
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