Commit 50b4393e authored by Bernhard Link's avatar Bernhard Link

Added references_insert/remove and packages/insert

parent b4402664
......@@ -24,8 +24,8 @@
#include <malloc.h>
#include "error.h"
#include "mprintf.h"
#include "packages.h"
#include "chunks.h"
#include "packages.h"
#include "binaries.h"
#include "names.h"
#include "dpkgversions.h"
......
......@@ -30,6 +30,7 @@
#include <string.h>
#include <ctype.h>
#include "error.h"
#include "dpkgversions.h"
#define _(a) a
......
......@@ -24,6 +24,7 @@
#include <string.h>
#include <db.h>
#include "error.h"
#include "strlist.h"
#include "mprintf.h"
#include "md5sum.h"
#include "dirs.h"
......
......@@ -20,6 +20,7 @@
#include <assert.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <getopt.h>
#include <string.h>
#include <malloc.h>
......@@ -27,11 +28,12 @@
#include "mprintf.h"
#include "dirs.h"
#include "names.h"
#include "md5sum.h"
#include "strlist.h"
#include "chunks.h"
#include "files.h"
#include "packages.h"
#include "reference.h"
#include "md5sum.h"
#include "chunks.h"
#include "binaries.h"
#include "sources.h"
#include "release.h"
......
......@@ -26,8 +26,10 @@
#include <zlib.h>
#include "error.h"
#include "mprintf.h"
#include "strlist.h"
#include "md5sum.h"
#include "dirs.h"
#include "reference.h"
#include "packages.h"
#define CLEARDBT(dbt) {memset(&dbt,0,sizeof(dbt));}
......@@ -298,3 +300,44 @@ retvalue packages_dozprintout(const char *dbpath,const char *dbname,const char *
RET_ENDUPDATE(result,r);
return result;
}
retvalue packages_insert(const char *identifier,
DB *referencesdb, DB *packagesdb,
const char *packagename, const char *controlchunk,
const struct strlist *files,
const struct strlist *oldfiles) {
retvalue result,r;
/* mark it as needed by this distribution */
r = references_insert(referencesdb,identifier,files,oldfiles);
if( RET_WAS_ERROR(r) )
return r;
/* Add package to the distribution's database */
if( oldfiles != NULL ) {
result = packages_replace(packagesdb,packagename,controlchunk);
} else {
result = packages_add(packagesdb,packagename,controlchunk);
}
if( RET_WAS_ERROR(result) )
return result;
/* remove old references to files */
if( oldfiles != NULL ) {
r = references_delete(referencesdb,identifier,
oldfiles,files);
RET_UPDATE(result,r);
}
return result;
}
......@@ -6,6 +6,10 @@
#include "error.h"
#warning "What's hapening here?"
#endif
#ifndef __MIRRORER_STRLIST_H
#include "strlist.h"
#warning "What's hapening here?"
#endif
/* initialize the packages-database for <identifier> */
DB *packages_initialize(const char *dbpath,const char *dbname);
......@@ -29,6 +33,14 @@ char *packages_get(DB *packagesdb,const char *package);
*/
retvalue packages_check(DB *packagesdb,const char *package);
/* insert a chunk in the packages database, adding and deleting
* referenced while that. */
retvalue packages_insert(const char *identifier,
DB *referencesdb, DB *packagesdb,
const char *packagename, const char *controlchunk,
const struct strlist *files,
const struct strlist *oldfiles);
/* print the database to a "Packages" or "Sources" file */
// retvalue packages_printout(DB *packagesdb,const char *filename);
// retvalue packages_zprintout(DB *packagesdb,const char *filename);
......
......@@ -25,6 +25,7 @@
#include <db.h>
#include "error.h"
#include "mprintf.h"
#include "strlist.h"
#include "md5sum.h"
#include "dirs.h"
#include "reference.h"
......@@ -181,6 +182,47 @@ retvalue references_decrement(DB* refdb,const char *needed,const char *neededby)
return r;
}
/* Add an reference by <identifer> for the given <files>,
* excluding <exclude>, if it is nonNULL. */
retvalue references_insert(DB *refdb,const char *identifier,
const struct strlist *files,const struct strlist *exclude) {
retvalue result,r;
int i;
result = RET_NOTHING;
for( i = 0 ; i < files->count ; i++ ) {
const char *filename = files->values[i];
if( exclude == NULL || !strlist_in(exclude,filename) ) {
r = references_increment(refdb,filename,identifier);
RET_UPDATE(result,r);
}
}
return result;
}
/* Remove reference by <identifer> for the given <oldfiles>,
* excluding <exclude>, if it is nonNULL. */
retvalue references_delete(DB *refdb,const char *identifier,
const struct strlist *files,const struct strlist *exclude) {
retvalue result,r;
int i;
result = RET_NOTHING;
for( i = 0 ; i < files->count ; i++ ) {
const char *filename = files->values[i];
if( exclude == NULL || !strlist_in(exclude,filename) ) {
r = references_decrement(refdb,filename,identifier);
RET_UPDATE(result,r);
}
}
return result;
}
/* remove all references from a given identifier */
retvalue references_remove(DB* refdb,const char *neededby) {
DBC *cursor;
......@@ -260,4 +302,3 @@ retvalue references_dump(DB *refdb) {
}
return result;
}
......@@ -6,12 +6,28 @@
#warning "What's happening?"
#endif
#ifndef __MIRRORER_STRLIST_H
#include "strlist.h"
#warning "What's happening?"
#endif
DB *references_initialize(const char *dbpath);
retvalue references_done( DB *db);
/* remove all references from a given identifier */
retvalue references_remove(DB* refdb,const char *neededby);
/* Add an reference by <identifer> for the given <files>,
* excluding <exclude>, if it is nonNULL. */
retvalue references_insert(DB *refdb,const char *identifer,
const struct strlist *files,const struct strlist *exclude);
/* Remove reference by <identifer> for the given <oldfiles>,
* excluding <exclude>, if it is nonNULL. */
retvalue references_delete(DB *refdb,const char *identifer,
const struct strlist *files,const struct strlist *exclude);
/* add an reference to a file for an identifier. multiple calls
* will add multiple references to allow source packages to share
* files over versions. (as first the new is added, then the old removed) */
......
......@@ -24,6 +24,7 @@
#include <ctype.h>
#include <malloc.h>
#include "error.h"
#include "strlist.h"
#include "packages.h"
#include "reference.h"
#include "chunks.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