Commit 2a74a049 authored by Bernhard Link's avatar Bernhard Link

Improved .dsc import to a somehow working state

parent b0647dff
......@@ -128,7 +128,7 @@ static retvalue binaries_parse_chunk(const char *chunk,char **packagename,char *
return r;
}
/* TODO check parts to consist out of save charakters */
*basename = calc_package_basename(ppackage,pversion,parch);
*basename = calc_binary_basename(ppackage,pversion,parch);
free(pversion);free(parch);
if( !*basename ) {
free(ppackage);
......
......@@ -161,7 +161,7 @@ retvalue deb_read(struct debpackage **pkg, const char *filename) {
return r;
}
deb->basename = calc_package_basename(deb->package,deb->version,deb->architecture);
deb->basename = calc_binary_basename(deb->package,deb->version,deb->architecture);
if( deb->basename == NULL ) {
deb_free(deb);
return r;
......
......@@ -128,17 +128,38 @@ static inline retvalue getvalue_n(const char *chunk,const char *field,char **val
return r;
}
void dsc_free(struct dscpackage *pkg) {
struct dscpackage {
/* things to be set by dsc_read: */
char *package,*version;
char *control;
struct strlist basenames,md5sums;
/* things that might still be NULL then: */
char *section;
char *priority;
/* things that will still be NULL then: */
char *component; //This might be const, too and save some strdups, but...
char *dscmd5sum;
/* Things that will be calculated by dsc_calclocations: */
char *directory, *dscbasename, *dscfilekey;
struct strlist filekeys;
};
static void dsc_free(struct dscpackage *pkg) {
if( pkg ) {
free(pkg->package);free(pkg->version);
free(pkg->control);
free(pkg->section);free(pkg->priority);free(pkg->component);
free(pkg->directory);
strlist_done(&pkg->basenames);strlist_done(&pkg->md5sums);
free(pkg->section);
free(pkg->priority);
free(pkg->component);
free(pkg->dscmd5sum);
free(pkg->directory);free(pkg->dscbasename);free(pkg->dscfilekey);
strlist_done(&pkg->filekeys);
}
free(pkg);
}
retvalue dsc_read(struct dscpackage **pkg, const char *filename) {
static retvalue dsc_read(struct dscpackage **pkg, const char *filename) {
retvalue r;
struct dscpackage *dsc;
......@@ -182,15 +203,74 @@ retvalue dsc_read(struct dscpackage **pkg, const char *filename) {
dsc_free(dsc);
return r;
}
r = sources_parse_getmd5sums(dsc->control,&dsc->basenames,&dsc->md5sums);
if( RET_WAS_ERROR(r) ) {
dsc_free(dsc);
return r;
}
*pkg = dsc;
return RET_OK;
}
retvalue dsc_complete(struct dscpackage *pkg) {
retvalue dsc_calclocations(struct dscpackage *pkg) {
retvalue r;
assert( pkg != NULL && pkg->package != NULL && pkg->version != NULL );
assert( pkg->component != NULL );
pkg->dscbasename = calc_source_basename(pkg->package,pkg->version);
if( pkg->dscbasename == NULL ) {
return RET_ERROR_OOM;
}
pkg->directory = calc_sourcedir(pkg->component,pkg->package);
if( pkg->directory == NULL ) {
return RET_ERROR_OOM;
}
/* Calculate the filekeys: */
r = calc_dirconcats(pkg->directory,&pkg->basenames,&pkg->filekeys);
if( RET_WAS_ERROR(r) ) {
return r;
}
pkg->dscfilekey = calc_dirconcat(pkg->directory,pkg->dscbasename);
if( pkg->dscfilekey == NULL ) {
return RET_ERROR_OOM;
}
return RET_OK;
}
/* Add the dsc-file to basenames,filekeys and md5sums, so that it will
* be referenced and listed in the Sources.gz */
static retvalue dsc_adddsc(struct dscpackage *pkg) {
retvalue r;
r = strlist_include(&pkg->basenames,pkg->dscbasename);
if( RET_WAS_ERROR(r) )
return r;
pkg->dscbasename = NULL;
r = strlist_include(&pkg->md5sums,pkg->dscmd5sum);
if( RET_WAS_ERROR(r) )
return r;
pkg->dscmd5sum = NULL;
r = strlist_include(&pkg->filekeys,pkg->dscfilekey);
if( RET_WAS_ERROR(r) )
return r;
pkg->dscfilekey = NULL;
return RET_OK;
}
static retvalue dsc_complete(struct dscpackage *pkg) {
retvalue r;
struct fieldtoadd *name;
struct fieldtoadd *dir;
char *newchunk,*newchunk2;
char *newfilelines;
assert(pkg->section != NULL && pkg->priority != NULL);
......@@ -207,32 +287,30 @@ retvalue dsc_complete(struct dscpackage *pkg) {
return RET_ERROR_OOM;
}
dir = addfield_new("Directory",pkg->directory,NULL);
if( !dir ) {
free(newchunk2);
return RET_ERROR_OOM;
}
dir = deletefield_new("Status",dir);
if( !dir ) {
free(newchunk2);
return RET_ERROR_OOM;
}
dir = addfield_new("Section",pkg->section,dir);
if( !dir ) {
r = sources_calcfilelines(&pkg->basenames,&pkg->md5sums,&newfilelines);
if( RET_WAS_ERROR(r) ) {
free(newchunk2);
return RET_ERROR_OOM;
}
dir = addfield_new("Priority",pkg->priority,dir);
dir = addfield_new("Files",newfilelines,NULL);
if( dir )
dir = addfield_new("Directory",pkg->directory,dir);
if( dir )
dir = deletefield_new("Status",dir);
if( dir )
dir = addfield_new("Section",pkg->section,dir);
if( dir )
dir = addfield_new("Priority",pkg->priority,dir);
if( !dir ) {
free(newfilelines);
free(newchunk2);
return RET_ERROR_OOM;
}
// TODO: add overwriting of other fields here, (before the rest)
// TODO: ******** ADD .DSC TO FILES-ITEM ********
newchunk = chunk_replacefields(newchunk2,dir,"Files");
free(newfilelines);
free(newchunk2);
addfield_free(dir);
if( newchunk == NULL ) {
......@@ -245,18 +323,14 @@ retvalue dsc_complete(struct dscpackage *pkg) {
return RET_OK;
}
/* insert the given .deb into the mirror in <component> in the <distribution>
* putting things with architecture of "all" into <d->architectures> (and also
* causing error, if it is not one of them otherwise)
/* insert the given .dsc into the mirror in <component> in the <distribution>
* if component is NULL, guessing it from the section. */
// TODO: add something to compare files' md5sums to those in the .changes file.
// (Perhaps also importing all those first, such that the database-code handles this)
retvalue dsc_add(const char *dbdir,DB *references,DB *filesdb,const char *mirrordir,const char *forcecomponent,const char *forcesection,const char *forcepriority,struct distribution *distribution,const char *dscfilename,int force){
retvalue r,result;
retvalue r;
struct dscpackage *pkg;
struct strlist filekeys,md5sums,files;
char *sourcedir;
/* First taking a closer look to the file: */
......@@ -310,50 +384,38 @@ retvalue dsc_add(const char *dbdir,DB *references,DB *filesdb,const char *mirror
fprintf(stderr,"%s: component guessed as '%s'\n",dscfilename,pkg->component);
}
pkg->directory = calc_sourcedir(pkg->component,pkg->package);
if( pkg->directory == NULL ) {
dsc_free(pkg);
return RET_ERROR_OOM;
}
/* calculate the needed files: */
sources_calcfilekeys(pkg->directory,pkg->control,&files,&filekeys,&md5sums);
if( RET_WAS_ERROR(r) ) {
dsc_free(pkg);
return r;
}
r = dirs_getdirectory(dscfilename,&sourcedir);
if( RET_WAS_ERROR(r) ) {
dsc_free(pkg);
return r;
}
r = dsc_calclocations(pkg);
/* then looking if we already have this, or copy it in */
r = files_checkinfiles(mirrordir,filesdb,sourcedir,&files,&filekeys,&md5sums);
free(sourcedir);
strlist_done(&files);
strlist_done(&md5sums);
if( RET_WAS_ERROR(r) ) {
dsc_free(pkg);
strlist_done(&filekeys);
return r;
}
if( !RET_WAS_ERROR(r) )
r = files_checkin(filesdb,mirrordir,pkg->dscfilekey,dscfilename,&pkg->dscmd5sum);
r = dsc_complete(pkg);
if( RET_WAS_ERROR(r) ) {
dsc_free(pkg);
strlist_done(&filekeys);
return r;
}
if( !RET_WAS_ERROR(r) ) {
char *sourcedir;
r = dirs_getdirectory(dscfilename,&sourcedir);
if( RET_IS_OK(r) ) {
r = files_checkinfiles(mirrordir,filesdb,sourcedir,&pkg->basenames,&pkg->filekeys,&pkg->md5sums);
free(sourcedir);
}
}
/* Calculate the chunk to include: */
/* finaly put it into the source distribution */
if( !RET_WAS_ERROR(r) )
r = dsc_adddsc(pkg);
if( !RET_WAS_ERROR(r) )
r = dsc_complete(pkg);
result = sources_addtodist(dbdir,references,distribution->codename,pkg->component,pkg->package,pkg->version,pkg->control,&filekeys);
/* 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);
strlist_done(&filekeys);
dsc_free(pkg);
return result;
return r;
}
......@@ -9,18 +9,6 @@
#include "distribution.h"
#endif
struct dscpackage {
/* things to be set by dsc_read: */
char *package,*version;
char *control;
/* things that might still be NULL then: */
char *section;
char *priority;
/* things that will still be NULL then: */
char *directory;
char *component; //This might be const, too and save some strdups, but...
};
/* insert the given .deb into the mirror in <component> in the <distribution>
* putting things with architecture of "all" into <d->architectures> (and also
* causing error, if it is not one of them otherwise)
......
......@@ -423,7 +423,7 @@ static retvalue reference_source(void *data,const char *package,const char *chun
struct strlist filekeys;
retvalue r;
r = sources_parse_getfiles(chunk,&filekeys);
r = sources_parse_getfilekeys(chunk,&filekeys);
if( verbose >= 0 && r == RET_NOTHING ) {
fprintf(stderr,"Package does not look like source: '%s'\n",chunk);
}
......@@ -1114,7 +1114,7 @@ static retvalue check_source(void *data,const char *package,const char *chunk) {
struct strlist filekeys;
retvalue ret,r;
r = sources_parse_getfiles(chunk,&filekeys);
r = sources_parse_getfilekeys(chunk,&filekeys);
if( verbose >= 0 && r == RET_NOTHING ) {
fprintf(stderr,"Package does not look like source: '%s'\n",chunk);
}
......
......@@ -74,7 +74,7 @@ char *calc_filekey(const char *component,const char *sourcename,const char *file
}
char *calc_package_basename(const char *name,const char *version,const char *arch) {
char *calc_binary_basename(const char *name,const char *version,const char *arch) {
const char *v = index(version,':');
if( v )
v++;
......@@ -83,6 +83,15 @@ char *calc_package_basename(const char *name,const char *version,const char *arc
return mprintf("%s_%s_%s.deb",name,v,arch);
}
char *calc_source_basename(const char *name,const char *version) {
const char *v = index(version,':');
if( v )
v++;
else
v = version;
return mprintf("%s_%s.dsc",name,v);
}
char *calc_concatmd5andsize(const char *md5sum,const char *size) {
/* this is not the only reference, as there are prints
* with size as ofs_t, too */
......
......@@ -3,7 +3,8 @@
char *calc_addsuffix(const char *str1,const char *str2);
char *calc_dirconcat(const char *str1,const char *str2);
char *calc_package_basename(const char *package,const char *version,const char *architecture);
char *calc_binary_basename(const char *package,const char *version,const char *architecture);
char *calc_source_basename(const char *name,const char *version);
char *calc_sourcedir(const char *component,const char *sourcename);
char *calc_filekey(const char *component,const char *sourcename,const char *filename);
char *calc_srcfilekey(const char *sourcedir,const char *filename);
......
This diff is collapsed.
......@@ -16,7 +16,8 @@ retvalue sources_getfile(const char *fileline,
char **basename,
char **md5andsize);
retvalue sources_parse_getfiles(const char *chunk, struct strlist *files);
retvalue sources_parse_getfilekeys(const char *chunk, struct strlist *filekeys);
retvalue sources_parse_getmd5sums(const char *chunk,struct strlist *basenames, struct strlist *md5andsizes);
/* Look for an old version of the Package in the database.
* return RET_NOTHING, if there is none at all. */
......@@ -29,10 +30,10 @@ retvalue sources_lookforold(DB *packages,const char *packagename,
* (i.e. "main","contrib",...) for generated paths */
retvalue sources_findnew(DB *pkgs,const char *component,const char *sources_file,new_package_action action,void *data,int force);
/* Calculate the filekeys and their expected md5sums */
retvalue sources_calcfilekeys(const char *directory,const char *chunk,struct strlist *files,struct strlist *filekeys, struct strlist *md5andsizes);
/* 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);
#endif
......@@ -108,6 +108,26 @@ retvalue strlist_add(struct strlist *strlist, char *element) {
return RET_OK;
}
retvalue strlist_include(struct strlist *strlist, char *element) {
char **v;
assert(strlist != NULL && element != NULL);
if( strlist->count >= strlist->size ) {
strlist->size += 1;
v = realloc(strlist->values, strlist->size*sizeof(char *));
if( !v ) {
free(element);
return RET_ERROR_OOM;
}
strlist->values = v;
}
memmove(strlist->values+1,strlist->values,strlist->count*sizeof(char *));
strlist->count++;
strlist->values[0] = element;
return RET_OK;
}
retvalue strlist_fprint(FILE *file,const struct strlist *strlist) {
int c;
char **p;
......
......@@ -18,6 +18,8 @@ void strlist_done(struct strlist *strlist);
/* add a string, will get property of the strlist and free'd by it */
retvalue strlist_add(struct strlist *strlist,char *element);
/* include a string at the beginning, otherwise like strlist_add */
retvalue strlist_include(struct strlist *strlist,char *element);
/* print a space seperated list of elements */
retvalue strlist_fprint(FILE *file,const struct strlist *strlist);
......
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