Commit cf9e99f3 authored by Bernhard Link's avatar Bernhard Link

Completed rewrite to remove duplicated code

parent 5a469d4c
This diff is collapsed.
......@@ -5,48 +5,25 @@
#include "error.h"
#warning "What's hapening here?"
#endif
#ifndef __MIRRORER_PACKAGES_H
#include "packages.h"
#warning "What's hapening here?"
#endif
/* get somefields out of a "Packages.gz"-chunk. returns 1 on success, 0 if incomplete, -1 on error */
retvalue binaries_parse_chunk(const char *chunk,
char **packagename,
char **origfilename,
char **sourcename,
char **basename,
char **md5andsize,
char **version);
/* get files out of a "Packages.gz"-chunk. */
retvalue binaries_parse_getfiles(const char *chunk,struct strlist *files);
/* Look for an older version of the Package in the database.
* return RET_NOTHING if there is none, otherwise
* Set *oldversion, if there is already a newer (or equal) version to
* <version> and <version> is != NULL */
* <version> */
retvalue binaries_lookforolder(
DB *packages,const char *packagename,
const char *newversion,char **oldversion,
char **oldfilekey);
/* the type of a action for binaries_add */
typedef retvalue binary_package_action(
/* the data supplied to binaries_add */
void *data,
/* the chunk to be added */
const char *chunk,
/* the package name */
const char *package,
/* the sourcename */
const char *sourcename,
/* the filename (including path) as found in the chunk */
const char *origfile,
/* the calculated base filename it should have (without directory) */
const char *basename,
/* with directory relative to the mirrordir */
const char *filekey,
/* the expected md5sum and size */
const char *md5andsize,
/* the pkgs database had an entry of the same name already
(which was considered older), NULL otherwise */
const char *oldfilekey);
struct strlist *oldfilekeys);
/* call action for each package in packages_file */
retvalue binaries_add(
/* call action for each package in packages_file, not already in pkgs. */
retvalue binaries_findnew(
/* the database of already included packages */
DB *pkgs,
/* the part (i.e. "main","contrib","non-free") to be used for dirs */
......@@ -54,7 +31,7 @@ retvalue binaries_add(
/* the file to traverse */
const char *packages_file,
/* the action to take for each package to add */
binary_package_action action,
new_package_action action,
/* some data to pass to the action */
void *data,
/* == 0 to stop process at first error. */
......
......@@ -92,17 +92,15 @@ retvalue checkindeb_insert(DB *references,const char *referee,
}
retvalue checkindeb_addChunk(DB *packagesdb, DB *referencesdb,DB *filesdb, const char *identifier,const char *mirrordir,const char *chunk,const char *packagename, const char *filekey, const char *md5andsize,const char *oldfilekey){
retvalue checkindeb_addChunk(DB *packagesdb, DB *referencesdb,DB *filesdb, const char *identifier,const char *mirrordir,const char *chunk,const char *packagename, const char *filekey,const struct strlist *filekeys, const struct strlist *md5sums,const struct strlist *oldfilekeys){
char *newchunk;
retvalue result,r;
/* look for needed files */
r = files_expect(filesdb,mirrordir,filekey,md5andsize);
if( ! RET_IS_OK(r) ) {
printf("Missing file %s\n",filekey);
r = files_insert(filesdb,mirrordir,filekeys,md5sums);
if( RET_WAS_ERROR(r) )
return r;
}
/* write in its position and check it in */
......@@ -110,17 +108,18 @@ retvalue checkindeb_addChunk(DB *packagesdb, DB *referencesdb,DB *filesdb, const
if( !newchunk )
return RET_ERROR;
result = checkindeb_insert(referencesdb,identifier,packagesdb,
packagename,newchunk,filekey,oldfilekey);
result = packages_insert(identifier,referencesdb,packagesdb,
packagename,newchunk,filekeys,oldfilekeys);
free(newchunk);
return result;
}
static retvalue deb_addtodist(const char *dbpath,DB *references,struct distribution *distribution,const char *component,const char *architecture,struct debpackage *package,const char *filekey) {
static retvalue deb_addtodist(const char *dbpath,DB *references,struct distribution *distribution,const char *component,const char *architecture,struct debpackage *package,const struct strlist *filekeys) {
retvalue result,r;
char *identifier,*oldfilekey,*oldversion;
char *identifier,*oldversion;
DB *packages;
struct strlist oldfilekeys,*o;
identifier = calc_identifier(distribution->codename,component,architecture);
if( ! identifier )
......@@ -132,27 +131,32 @@ static retvalue deb_addtodist(const char *dbpath,DB *references,struct distribut
return RET_ERROR;
}
r = binaries_lookforolder(packages,package->package,package->version,&oldversion,&oldfilekey);
r = binaries_lookforolder(packages,package->package,package->version,&oldversion,&oldfilekeys);
if( RET_WAS_ERROR(r) ) {
(void)packages_done(packages);
free(identifier);
return r;
}
if( RET_IS_OK(r) )
o = &oldfilekeys;
else
o = NULL;
if( oldversion ) {
if( RET_IS_OK(r) && oldversion ) {
fprintf(stderr,"Version '%s' already in the archive, skipping '%s'\n",oldversion,package->version);
free(oldversion);
result = RET_NOTHING;
} else
result = checkindeb_insert(references,identifier,packages,
result = packages_insert(identifier,references,packages,
package->package, package->control,
filekey, oldfilekey);
filekeys, o);
r = packages_done(packages);
RET_ENDUPDATE(result,r);
free(identifier);
free(oldfilekey);
if( o )
strlist_done(&oldfilekeys);
return result;
}
......@@ -326,6 +330,7 @@ retvalue deb_add(const char *dbdir,DB *references,DB *filesdb,const char *mirror
retvalue r,result;
struct debpackage *pkg;
char *filekey,*md5andsize;
struct strlist filekeys;
int i;
/* First taking a closer look to the file: */
......@@ -370,6 +375,16 @@ retvalue deb_add(const char *dbdir,DB *references,DB *filesdb,const char *mirror
/* calculate it's filekey */
filekey = calc_filekey(component,pkg->source,pkg->basename);
if( filekey == NULL) {
deb_free(pkg);
return RET_ERROR_OOM;
}
r = strlist_init_singleton(filekey,&filekeys);
if( RET_WAS_ERROR(r) ) {
free(filekey);
deb_free(pkg);
return r;
}
/* then looking if we already have this, or copy it in */
......@@ -394,14 +409,14 @@ retvalue deb_add(const char *dbdir,DB *references,DB *filesdb,const char *mirror
result = RET_NOTHING;
if( strcmp(pkg->architecture,"all") != 0 ) {
r = deb_addtodist(dbdir,references,distribution,component,pkg->architecture,pkg,filekey);
r = deb_addtodist(dbdir,references,distribution,component,pkg->architecture,pkg,&filekeys);
RET_UPDATE(result,r);
} else for( i = 0 ; i < distribution->architectures.count ; i++ ) {
r = deb_addtodist(dbdir,references,distribution,component,distribution->architectures.values[i],pkg,filekey);
r = deb_addtodist(dbdir,references,distribution,component,distribution->architectures.values[i],pkg,&filekeys);
RET_UPDATE(result,r);
}
free(filekey);
strlist_done(&filekeys);
deb_free(pkg);
return result;
......
......@@ -33,7 +33,7 @@ void deb_free(struct debpackage *pkg);
/* Insert the given control-chunk in the database, including all
* files in the database and registering them */
retvalue checkindeb_addChunk(DB *packagesdb, DB *referencesdb,DB *filesdb, const char *identifier,const char *mirrordir,const char *chunk,const char *packagename,const char *filekey,const char *md5andsize,const char *oldfilekey);
retvalue checkindeb_addChunk(DB *packagesdb, DB *referencesdb,DB *filesdb, const char *identifier,const char *mirrordir,const char *chunk,const char *packagename,const char *filekey,const struct strlist *filekeys,const struct strlist *md5sums,const struct strlist *oldfilekeys);
/* insert the given .deb into the mirror in <component> in the <distribution>
* putting things with architecture of "all" into <architectures> (and also
......
......@@ -31,6 +31,7 @@
#include "error.h"
#include "mprintf.h"
#include "chunks.h"
#include "packages.h"
#include "sources.h"
#include "md5sum.h"
#include "dirs.h"
......
......@@ -254,6 +254,53 @@ int files_expect(DB *filesdb,const char *mirrordir,const char *filekey,const cha
return ret;
}
/* check for several files in the database and in the pool if missing */
retvalue files_insert(DB *filesdb,const char *mirrordir,const struct strlist *filekeys,const struct strlist *md5sums) {
int i;
retvalue r;
for( i = 0 ; i < filekeys->count ; i++ ) {
const char *filekey = filekeys->values[i];
const char *md5sum = md5sums->values[i];
r = files_expect(filesdb,mirrordir,filekey,md5sum);
if( RET_WAS_ERROR(r) ) {
return r;
}
if( r == RET_NOTHING ) {
/* File missing */
fprintf(stderr,"Missing file %s\n",filekey);
return RET_ERROR;
}
}
return RET_OK;
}
/* print missing files */
retvalue files_printmissing(DB *filesdb,const char *mirrordir,const struct strlist *filekeys,const struct strlist *md5sums,const struct strlist *origfiles) {
int i;
retvalue ret,r;
ret = RET_NOTHING;
for( i = 0 ; i < filekeys->count ; i++ ) {
const char *filekey = filekeys->values[i];
const char *md5sum = md5sums->values[i];
const char *origfile = origfiles->values[i];
r = files_expect(filesdb,mirrordir,filekey,md5sum);
if( RET_WAS_ERROR(r) ) {
return r;
}
if( r == RET_NOTHING ) {
/* File missing */
printf("%s %s/%s\n",origfile,mirrordir,filekey);
RET_UPDATE(ret,RET_OK);
} else
RET_UPDATE(ret,r);
}
return ret;
}
/* dump out all information */
int files_printmd5sums(DB* filesdb) {
DBC *cursor;
......
......@@ -29,6 +29,11 @@ retvalue files_detect(DB *filesdb,const char *mirrordir,const char *filekey);
/* check for file in the database and if not found there, if it can be detected */
retvalue files_expect(DB *filesdb,const char *mirrordir,const char *filekey,const char *md5andsize);
/* print missing files */
retvalue files_printmissing(DB *filesdb,const char *mirrordir,const struct strlist *filekeys,const struct strlist *md5sums,const struct strlist *origfiles);
/* check for several files in the database and in the pool if missing */
retvalue files_insert(DB *filesdb,const char *mirrordir,const struct strlist *filekeys,const struct strlist *md5sums);
/* Copy file <origfilename> to <mirrordir>/<filekey> and add it to
* the database <filesdb>. Return RET_ERROR_WRONG_MD5 if already there
* with other md5sum, return other error when the file does not exists
......
This diff is collapsed.
......@@ -53,5 +53,28 @@ typedef retvalue per_package_action(void *data,const char *package,const char *c
/* call action once for each saved chunk: */
retvalue packages_foreach(DB *packagesdb,per_package_action action,void *data, int force);
/* The action-type supplied to binary.c and source.c when looking
* for things to update: */
typedef retvalue new_package_action(
/* the private data passed to {binaries,sources}_add */
void *data,
/* the chunk to be added */
const char *chunk,
/* the name of the {binary-,source-}package */
const char *packagename,
/* the version */
const char *version,
/* the calculated place for this package (dir with src,filename oth) */
const char *newplace,
/* the files (relative to mirrordir) it contains */
const struct strlist *filekeys,
/* the original files the chunk describes: */
const struct strlist *origfiles,
/* the md5sumandsize of theese files requested: */
const struct strlist *md5sums,
/* files (r.t. mirrordir) the previous version needed: */
const struct strlist *oldfilekeys
);
#endif
......@@ -49,7 +49,6 @@ DB *references_initialize(const char *dbpath) {
int ret;
char *filename;
retvalue r;
filename = mprintf("%s/references.db",dbpath);
if( !filename )
......@@ -97,7 +96,7 @@ retvalue references_isused(DB *refdb,const char *what) {
}
}
retvalue references_check(DB *refdb,const char *what,const char *by) {
static retvalue references_checksingle(DB *refdb,const char *what,const char *by) {
int dbret;
retvalue r;
DBT key,data;
......@@ -126,6 +125,18 @@ retvalue references_check(DB *refdb,const char *what,const char *by) {
}
return r;
}
retvalue references_check(DB *refdb,const char *referee,const struct strlist *filekeys) {
int i;
retvalue ret,r;
ret = RET_NOTHING;
for( i = 0 ; i < filekeys->count ; i++ ) {
r = references_checksingle(refdb,filekeys->values[i],referee);
RET_UPDATE(ret,r);
}
return ret;
}
/* add an reference to a file for an identifier. multiple calls
* will add multiple references to allow source packages to share
......
......@@ -40,7 +40,7 @@ retvalue references_decrement(DB* refdb,const char *needed,const char *neededby)
retvalue references_isused(DB *refdb,const char *what);
/* check if a reference is found as expected */
retvalue references_check(DB *refdb,const char *what,const char *by);
retvalue references_check(DB *refdb,const char *referee,const struct strlist *what);
/* print out all referee-referenced-pairs. */
retvalue references_dump(DB *refdb);
......
......@@ -30,7 +30,9 @@
#include <db.h>
#include "error.h"
#include "mprintf.h"
#include "strlist.h"
#include "chunks.h"
#include "packages.h"
#include "sources.h"
#include "md5sum.h"
#include "dirs.h"
......
This diff is collapsed.
......@@ -6,46 +6,20 @@
#include "error.h"
#warning "What's hapening here?"
#endif
#ifndef __MIRRORER_PACKAGES_H
#include "packages.h"
#warning "What's hapening here?"
#endif
/* get filename and md5andsize from a files: line" */
retvalue sources_getfile(const char *fileline,
char **basename,
char **md5andsize);
retvalue sources_getfilekeys(const char *directory,const struct strlist *files,struct strlist *filekeys);
retvalue sources_parse_chunk(const char *chunk,
char **packagename,
char **version,
char **origdirectory,
struct strlist *files);
retvalue sources_parse_getfiles(const char *chunk, struct strlist *files);
/* action taken by sources_add for each sourcepacke missing */
typedef retvalue source_package_action(
/* the private data passed to sources_add */
void *data,
/* the chunk to be added */
const char *chunk,
/* the name of the sourcepackage */
const char *package,
/* the version */
const char *version,
/* 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 *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 *olddirectory,
const struct strlist *oldfiles);
/* call <data> for each package in the "Sources.gz"-style file <source_file> missing in
/* call <action> 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 */
retvalue sources_add(DB *pkgs,const char *component,const char *sources_file,source_package_action action,void *data,int force);
/* remove all references by the given chunk */
retvalue sources_dereference(DB *refs,const char *referee,const char *chunk);
/* add all references by the given data */
retvalue sources_reference(DB *refs,const char *referee,const char *dir,const struct strlist *files);
retvalue sources_findnew(DB *pkgs,const char *component,const char *sources_file,new_package_action action,void *data,int force);
#endif
......@@ -50,6 +50,19 @@ retvalue strlist_init_n(int startsize,struct strlist *strlist) {
return RET_OK;
}
retvalue strlist_init_singleton(char *value,struct strlist *strlist) {
assert(strlist != NULL);
strlist->count = 1;
strlist->size = 1;
strlist->values = malloc(sizeof(char *));
if( strlist->values == NULL )
return RET_ERROR_OOM;
strlist->values[0] = value;
return RET_OK;
}
retvalue strlist_init(struct strlist *strlist) {
assert(strlist != NULL);
......
......@@ -13,6 +13,7 @@ struct strlist {
retvalue strlist_init(struct strlist *strlist);
retvalue strlist_init_n(int startsize,struct strlist *strlist);
retvalue strlist_init_singleton(char *value,struct strlist *strlist);
void strlist_done(struct strlist *strlist);
/* add a string, will get property of the strlist and free'd by it */
......
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