Commit 8370ffd8 authored by Bernhard Link's avatar Bernhard Link

Unified handling of binary and source packages a bit more.

parent fd9f20bb
......@@ -240,7 +240,7 @@ static inline retvalue callaction(new_package_action *action,void *data,
const struct strlist *origfiles,
const struct strlist *oldfiles) {
retvalue r;
char *filekey;
char *filekey,*newchunk;
struct strlist filekeys;
filekey = calc_filekey(component,sourcename,basename);
......@@ -251,8 +251,16 @@ static inline retvalue callaction(new_package_action *action,void *data,
free(filekey);
return r;
}
r = (*action)(data,chunk,packagename,version,
filekey,&filekeys,origfiles,md5sums,oldfiles);
// Calculating the following here will cause work done
// unnecesarrily, but it unifies handling afterwards:
newchunk = chunk_replacefield(chunk,"Filename",filekey);
if( !newchunk ) {
strlist_done(&filekeys);
return RET_ERROR_OOM;
}
r = (*action)(data,newchunk,packagename,version,
&filekeys,origfiles,md5sums,oldfiles);
free(newchunk);
strlist_done(&filekeys);
return r;
}
......
......@@ -43,32 +43,9 @@
extern int verbose;
// This file shall include the code to include binaries, i.e.
// create or adopt the chunk of the Packages.gz-file and
// create the chunk of the Packages.gz-file and
// putting it in the various databases.
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_insert(filesdb,mirrordir,filekeys,md5sums);
if( RET_WAS_ERROR(r) )
return r;
/* write in its position and check it in */
newchunk = chunk_replacefield(chunk,"Filename",filekey);
if( !newchunk )
return RET_ERROR;
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 *architecture,struct debpackage *package,const struct strlist *filekeys) {
retvalue result,r;
char *identifier,*oldversion;
......@@ -422,6 +399,7 @@ retvalue deb_add(const char *dbdir,DB *references,DB *filesdb,const char *mirror
/* then looking if we already have this, or copy it in */
//TODO ... rewrite this to do a list of files ...
r = files_checkin(filesdb,mirrordir,filekey,debfilename,&md5andsize);
if( RET_WAS_ERROR(r) ) {
free(filekey);
......
......@@ -26,6 +26,7 @@
#include <stdlib.h>
#include "error.h"
#include "strlist.h"
#include "names.h"
#include "dirs.h"
#include "copyfile.h"
......
......@@ -23,7 +23,9 @@
#include <malloc.h>
#include <string.h>
#include "error.h"
#include "strlist.h"
#include "dirs.h"
#include "names.h"
extern int verbose;
......@@ -75,3 +77,27 @@ retvalue dirs_make_recursive(const char *directory) {
RET_UPDATE(result,r);
return result;
}
/* create recursively all parent directories before the last '/' */
retvalue dirs_make_parents(const char *mirrordir,const struct strlist *filekeys) {
char *filename;
int i;
retvalue result,r;
result = RET_NOTHING;
//TODO: this is a bit ineffective. But As I do not
//know, if it will be still needed in the future, no
//optimization yet...
for( i=0; i<filekeys->count ; i++ ) {
filename = calc_dirconcat(mirrordir,filekeys->values[i]);
if( filename == NULL )
return RET_ERROR_OOM;
r = dirs_make_parent(filename);
if( RET_WAS_ERROR(r) )
return r;
RET_UPDATE(result,r);
}
return result;
}
......@@ -5,10 +5,16 @@
#warning "What is happening here?"
#include "error.h"
#endif
#ifndef __MIRRORER_STRLIST_H
#warning "What is happening here?"
#include "strlist.h"
#endif
/* create recursively all parent directories before the last '/' */
retvalue dirs_make_parent(const char *filename);
/* create dirname and any '/'-seperated part of it */
retvalue dirs_make_recursive(const char *directory);
/* create recursively all parent directories before the last '/' */
retvalue dirs_make_parents(const char *mirrordir,const struct strlist *filekeys);
#endif
......@@ -26,10 +26,10 @@
#include <malloc.h>
#include "error.h"
#include "mprintf.h"
#include "strlist.h"
#include "dirs.h"
#include "names.h"
#include "md5sum.h"
#include "strlist.h"
#include "chunks.h"
#include "files.h"
#include "packages.h"
......@@ -446,27 +446,19 @@ struct distributionhandles {
/***********************************addsources***************************/
static retvalue add_source(void *data,const char *chunk,const char *package,const char *version,const char *directory,const struct strlist *filekeys,const struct strlist *origfiles,const struct strlist *md5sums,const struct strlist *oldfilekeys) {
char *newchunk;
retvalue result,r;
static retvalue add(void *data,const char *chunk,const char *package,const char *version,const struct strlist *filekeys,const struct strlist *origfiles,const struct strlist *md5sums,const struct strlist *oldfilekeys) {
retvalue result;
struct distributionhandles *dist = (struct distributionhandles*)data;
/* look for needed files */
r = files_insert(dist->files,mirrordir,filekeys,md5sums);
if( RET_WAS_ERROR(r) )
return r;
newchunk = chunk_replacefield(chunk,"Directory",directory);
if( !newchunk )
return RET_ERROR_OOM;
/* Add package to distribution's database */
result = files_insert(dist->files,mirrordir,filekeys,md5sums);
if( RET_WAS_ERROR(result) )
return result;
result = packages_insert(dist->referee,dist->refs,dist->pkgs,
package,newchunk,filekeys,oldfilekeys);
package,chunk,filekeys,oldfilekeys);
free(newchunk);
return result;
}
......@@ -499,7 +491,7 @@ static int addsources(int argc,char *argv[]) {
}
result = RET_NOTHING;
for( i=3 ; i < argc ; i++ ) {
r = sources_findnew(dist.pkgs,dist.component,argv[i],add_source,&dist,force);
r = sources_findnew(dist.pkgs,dist.component,argv[i],add,&dist,force);
RET_UPDATE(result,r);
}
r = files_done(dist.files);
......@@ -512,19 +504,16 @@ 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 struct strlist *filekeys,const struct strlist *origfiles,const struct strlist *md5sums,const struct strlist *oldfilekeys) {
static retvalue showmissing(void *data,const char *chunk,const char *package,const char *version,const struct strlist *filekeys,const struct strlist *origfiles,const struct strlist *md5sums,const struct strlist *oldfilekeys) {
retvalue r,ret;
struct distributionhandles *dist = (struct distributionhandles*)data;
char *dn;
/* look for directory */
if( (dn = calc_fullfilename(mirrordir,directory))) {
r = dirs_make_recursive(dn);
free(dn);
if( RET_WAS_ERROR(r) )
return r;
}
// This is a bit stupid, first to generate the filekeys and
// then splitting the directory from it. But this should go
// away, when updating is solved a bit more reasoable...
r = dirs_make_parents(mirrordir,filekeys);
if( RET_WAS_ERROR(r) )
return r;
ret = files_printmissing(dist->files,mirrordir,filekeys,md5sums,origfiles);
return ret;
}
......@@ -555,7 +544,7 @@ static int prepareaddsources(int argc,char *argv[]) {
result = RET_NOTHING;
for( i=3 ; i < argc ; i++ ) {
r = sources_findnew(dist.pkgs,dist.component,argv[i],showmissingsourcefiles,&dist,force);
r = sources_findnew(dist.pkgs,dist.component,argv[i],showmissing,&dist,force);
RET_UPDATE(result,r);
}
r = files_done(dist.files);
......@@ -567,23 +556,6 @@ static int prepareaddsources(int argc,char *argv[]) {
/****************************prepareaddpackages*******************************************/
static retvalue showmissing(void *data,const char *chunk,const char *package,const char *version,const char *filekey,const struct strlist *filekeys,const struct strlist *origfiles,const struct strlist *md5sums,const struct strlist *oldfilekeys) {
retvalue r,ret;
struct distributionhandles *dist = (struct distributionhandles*)data;
char *dn;
/* look for directory */
if( (dn = calc_fullfilename(mirrordir,filekey))) {
r = dirs_make_parent(dn);
free(dn);
if( RET_WAS_ERROR(r) )
return r;
}
ret = files_printmissing(dist->files,mirrordir,filekeys,md5sums,origfiles);
return ret;
}
static int prepareaddpackages(int argc,char *argv[]) {
int i;
retvalue r,result;
......@@ -623,19 +595,6 @@ static int prepareaddpackages(int argc,char *argv[]) {
/***********************************addpackages*******************************************/
static retvalue add_package(void *data,const char *chunk,const char *package,const char *version,const char *filekey,const struct strlist *filekeys,const struct strlist *origfiles,const struct strlist *md5sums,const struct strlist *oldfilekeys) {
retvalue result;
struct distributionhandles *d = data;
result = checkindeb_addChunk(d->pkgs,d->refs,d->files,
d->referee, mirrordir,
chunk, package, filekey,
filekeys,md5sums,oldfilekeys);
return result;
}
static int addpackages(int argc,char *argv[]) {
int i;
retvalue r,result;
......@@ -664,7 +623,7 @@ static int addpackages(int argc,char *argv[]) {
dist.component = argv[2];
result = RET_NOTHING;
for( i=3 ; i < argc ; i++ ) {
r = binaries_findnew(dist.pkgs,dist.component,argv[i],add_package,&dist,force);
r = binaries_findnew(dist.pkgs,dist.component,argv[i],add,&dist,force);
RET_UPDATE(result,r);
}
r = files_done(dist.files);
......
......@@ -31,6 +31,7 @@
#include "dirs.h"
#include "reference.h"
#include "packages.h"
#include "files.h"
#define CLEARDBT(dbt) {memset(&dbt,0,sizeof(dbt));}
#define SETDBT(dbt,datastr) {const char *my = datastr;memset(&dbt,0,sizeof(dbt));dbt.data=(void *)my;dbt.size=strlen(my)+1;}
......@@ -313,6 +314,7 @@ retvalue packages_insert(const char *identifier,
const char *packagename, const char *controlchunk,
const struct strlist *files,
const struct strlist *oldfiles) {
retvalue result,r;
......@@ -346,5 +348,3 @@ retvalue packages_insert(const char *identifier,
return result;
}
......@@ -35,7 +35,7 @@ retvalue packages_get(DB *packagesdb,const char *package,char **chunk);
retvalue packages_check(DB *packagesdb,const char *package);
/* insert a chunk in the packages database, adding and deleting
* referenced while that. */
* references and insert files while that. */
retvalue packages_insert(const char *identifier,
DB *referencesdb, DB *packagesdb,
const char *packagename, const char *controlchunk,
......@@ -66,8 +66,6 @@ typedef retvalue new_package_action(
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: */
......
......@@ -26,6 +26,7 @@
#include <malloc.h>
#include "error.h"
#include "mprintf.h"
#include "strlist.h"
#include "dirs.h"
#include "names.h"
#include "md5sum.h"
......
......@@ -347,7 +347,7 @@ static inline retvalue callaction(new_package_action *action, void *data,
const char *chunk, const char *package, const char *version,
const char *origdirectory, const struct strlist *filelines,
const char *component, const struct strlist *oldfilekeys) {
char * directory;
char *directory,*newchunk;
struct strlist origfiles,filekeys,md5sums;
retvalue r;
......@@ -368,9 +368,23 @@ static inline retvalue callaction(new_package_action *action, void *data,
free(directory);
return r;
}
r = (*action)(data,chunk,package,version,directory,
&filekeys,&origfiles,&md5sums,oldfilekeys);
newchunk = chunk_replacefield(chunk,"Directory",directory);
free(directory);
if( !newchunk ) {
strlist_done(&origfiles);
strlist_done(&filekeys);
strlist_done(&md5sums);
return RET_ERROR_OOM;
}
// Calculating origfiles and newchunk will both not be needed in half of the
// cases. This could be avoided by pushing flags to sources_findnew which
// to generete. (doing replace_field here makes handling in main.c so
// nicely type-independent.)
r = (*action)(data,newchunk,package,version,
&filekeys,&origfiles,&md5sums,oldfilekeys);
free(newchunk);
strlist_done(&filekeys);
strlist_done(&origfiles);
strlist_done(&md5sums);
......
......@@ -28,10 +28,10 @@
#include <db.h>
#include "error.h"
#include "mprintf.h"
#include "strlist.h"
#include "dirs.h"
#include "names.h"
#include "chunks.h"
#include "strlist.h"
#include "signature.h"
#include "updates.h"
......
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