Commit 6b1be4aa authored by Bernhard Link's avatar Bernhard Link

Package-databases are closed as soon as possible as libdb seems to have problems otherwise...

parent 6fd7ac73
......@@ -445,6 +445,32 @@ static int md5sums(int argc,char *argv[]) {
}
}
static retvalue printout(void *data,const char *package,const char *chunk){
printf("'%s' -> '%s'\n",package,chunk);
return RET_OK;
}
static int dumpcontents(int argc,char *argv[]) {
retvalue result,r;
packagesdb packages;
if( argc != 2 ) {
fprintf(stderr,"mirrorer _dumpcontents <identifier>\n");
return 1;
}
result = packages_initialize(&packages,dbdir,argv[1]);
if( RET_WAS_ERROR(result) )
return EXIT_RET(result);
result = packages_foreach(packages,printout,NULL,force);
r = packages_done(packages);
RET_ENDUPDATE(result,r);
return EXIT_RET(result);
}
static retvalue doexport(void *dummy,const char *chunk,struct distribution *distribution) {
if( verbose > 0 ) {
......@@ -516,7 +542,7 @@ static int update(int argc,char *argv[]) {
r = files_done(files);
RET_ENDUPDATE(result,r);
doexport = force || RET_IS_OK(result);
doexport = 0; // force || RET_IS_OK(result);
if( doexport && verbose >= 0 )
fprintf(stderr,"Exporting indices...\n");
while( distributions ) {
......@@ -784,6 +810,7 @@ static struct action {
{"_detect", detect},
{"_forget", forget},
{"_md5sums", md5sums},
{"_dumpcontents", dumpcontents},
{"remove", removepackage},
{"export", export},
{"check", check},
......
......@@ -91,7 +91,9 @@ char *calc_downloadedlistfile(const char *listdir,const char *codename,const cha
}
char *calc_identifier(const char *codename,const char *component,const char *architecture) {
return mprintf("%s-%s-%s",codename,component,architecture);
// TODO: add checks to all data possibly given into here...
assert( index(codename,'|') == NULL && index(component,'|') == NULL && index(architecture,'|') == NULL );
return mprintf("%s|%s|%s",codename,component,architecture);
}
char *calc_addsuffix(const char *str1,const char *str2) {
......
......@@ -40,13 +40,17 @@
extern int verbose;
// to make sure the problems do not arise there:
int isopen = 0;
/* release the packages-database initialized got be packages_initialize */
retvalue packages_done(packagesdb db) {
int r;
if( db->wasmodified ) {
fprintf(stderr,"Warning: database '%s' was modified but no index file was exported.\nChanges might only be visible after the next 'export'!\n",db->identifier);
}
isopen--;
if( isopen < 0 )
fprintf(stderr,"isopen: %d\n",isopen);
r = db->database->close(db->database,0);
free(db->identifier);
free(db);
......@@ -104,6 +108,9 @@ retvalue packages_initialize(packagesdb *db,const char *dbpath,const char *ident
free(pkgs);
return RET_DBERR(dbret);
}
isopen++;
if( isopen > 1 )
fprintf(stderr,"isopen: %d\n",isopen);
if ((dbret = pkgs->database->open(pkgs->database, filename, identifier, DB_BTREE, DB_CREATE, 0664)) != 0) {
pkgs->database->err(pkgs->database, dbret, "%s(%s)", filename,identifier);
(void)pkgs->database->close(pkgs->database,0);
......@@ -118,7 +125,7 @@ retvalue packages_initialize(packagesdb *db,const char *dbpath,const char *ident
}
/* replace a save chunk with another */
retvalue packages_replace(packagesdb db,const char *package,const char *chunk) {
static retvalue packages_replace(packagesdb db,const char *package,const char *chunk) {
int dbret;
DBT key,data;
......@@ -146,7 +153,7 @@ retvalue packages_replace(packagesdb db,const char *package,const char *chunk) {
}
/* save a given chunk in the database */
retvalue packages_add(packagesdb db,const char *package,const char *chunk) {
static retvalue packages_add(packagesdb db,const char *package,const char *chunk) {
int dbret;
DBT key,data;
......@@ -250,6 +257,8 @@ retvalue packages_foreach(packagesdb db,per_package_action action,void *privdata
fprintf(stderr,"packages_foreach: Stopping procession of further packages due to privious errors\n");
break;
}
CLEARDBT(key);
CLEARDBT(data);
}
if( dbret != 0 && dbret != DB_NOTFOUND ) {
......
......@@ -94,14 +94,19 @@ retvalue target_free(struct target *target) {
if( target == NULL )
return RET_OK;
if( target->packages ) {
result = target_closepackagesdb(target);
} else
result = RET_OK;
if( target->wasmodified ) {
fprintf(stderr,"Warning: database '%s' was modified but no index file was exported.\nChanges will only be visible after the next 'export'!\n",target->identifier);
}
free(target->codename);
free(target->component);
free(target->architecture);
free(target->identifier);
free(target->directory);
if( target->packages ) {
result = packages_done(target->packages);
}
free(target);
return result;
}
......@@ -110,9 +115,10 @@ retvalue target_free(struct target *target) {
retvalue target_initpackagesdb(struct target *target, const char *dbdir) {
retvalue r;
if( target->packages != NULL )
if( target->packages != NULL ) {
fprintf(stderr,"again2\n");
r = RET_OK;
else {
} else {
r = packages_initialize(&target->packages,dbdir,target->identifier);
if( RET_WAS_ERROR(r) ) {
target->packages = NULL;
......@@ -121,6 +127,23 @@ retvalue target_initpackagesdb(struct target *target, const char *dbdir) {
}
return r;
}
/* this closes databases... */
retvalue target_closepackagesdb(struct target *target) {
retvalue r;
if( target->packages == NULL ) {
fprintf(stderr,"Internal Warning: Double close!\n");
r = RET_OK;
} else {
if( target->packages->wasmodified && !target->wasmodified ) {
fprintf(stderr,"Internal Warning: Missed change!\n");
target->wasmodified = 1;
}
r = packages_done(target->packages);
target->packages = NULL;
}
return r;
}
retvalue target_removepackage(struct target *target,DB *references,const char *name) {
char *oldchunk;
......@@ -147,6 +170,7 @@ retvalue target_removepackage(struct target *target,DB *references,const char *n
fprintf(stderr,"removing '%s' from '%s'...\n",name,target->identifier);
r = packages_remove(target->packages,name);
if( RET_IS_OK(r) ) {
target->wasmodified = 1;
r = references_delete(references,target->identifier,&files,NULL);
}
strlist_done(&files);
......@@ -209,6 +233,9 @@ retvalue target_addpackage(struct target *target,DB *references,const char *name
}
}
r = packages_insert(references,target->packages,name,control,filekeys,ofk);
if( RET_IS_OK(r) )
target->wasmodified = 1;
if( ofk )
strlist_done(ofk);
return r;
......@@ -308,7 +335,7 @@ retvalue target_check(struct target *target,filesdb filesdb,DB *referencesdb,int
retvalue target_export(struct target *target,const char *dbdir,const char *distdir,int force,int onlyneeded) {
indexcompression compression;
retvalue result,r;
retvalue result,r,r2;
if( verbose > 5 ) {
fprintf(stderr," exporting '%s'...\n",target->identifier);
......@@ -324,7 +351,7 @@ retvalue target_export(struct target *target,const char *dbdir,const char *distd
target->indexfile,compression);
if( filename == NULL )
return RET_ERROR_OOM;
if( onlyneeded && !(target->packages && target->packages->wasmodified)) {
if( onlyneeded && !target->wasmodified &&!(target->packages && target->packages->wasmodified)) {
struct stat s;
int i;
......@@ -335,9 +362,12 @@ retvalue target_export(struct target *target,const char *dbdir,const char *distd
}
}
r = target_initpackagesdb(target,dbdir);
if( !RET_WAS_ERROR(r) )
if( !RET_WAS_ERROR(r) ) {
r = packages_export(target->packages,
filename,compression);
r2 = target_closepackagesdb(target);
RET_ENDUPDATE(r,r2);
}
free(filename);
RET_UPDATE(result,r);
if( !force && RET_WAS_ERROR(r) )
......
......@@ -35,6 +35,7 @@ struct target {
get_installdata *getinstalldata;
get_filekeys *getfilekeys;
get_upstreamindex *getupstreamindex;
int wasmodified;
/* the next one in the list of targets of a distribution */
struct target *next;
/* is initialized as soon as needed: */
......@@ -51,6 +52,8 @@ retvalue target_printmd5sums(const struct target *target,const char *distdir,FIL
/* This opens up the database, if db != NULL, *db will be set to it.. */
retvalue target_initpackagesdb(struct target *target, const char *dbdir);
/* this closes databases... */
retvalue target_closepackagesdb(struct target *target);
/* The following calls can only be called if target_initpackagesdb was called before: */
......
......@@ -786,13 +786,13 @@ retvalue updates_readindices(const char *dbdir,struct downloadcache *cache,files
}
retvalue updates_install(filesdb filesdb,DB *refsdb,struct distribution *distribution,int force) {
retvalue updates_install(const char *dbdir,filesdb filesdb,DB *refsdb,struct distribution *distribution,int force) {
retvalue result,r;
struct update_target *u;
result = RET_NOTHING;
for( u=distribution->updatetargets ; u ; u=u->next ) {
r = upgradelist_install(u->upgradelist,filesdb,refsdb,force);
r = upgradelist_install(u->upgradelist,dbdir,filesdb,refsdb,force);
RET_UPDATE(result,r);
upgradelist_free(u->upgradelist);
u->upgradelist = NULL;
......@@ -888,7 +888,7 @@ retvalue updates_update(const char *dbdir,const char *listdir,const char *method
fprintf(stderr,"Installing packages...\n");
for( distribution=distributions ; distribution ; distribution=distribution->next) {
r = updates_install(filesdb,refsdb,distribution,force);
r = updates_install(dbdir,filesdb,refsdb,distribution,force);
RET_UPDATE(result,r);
if( RET_WAS_ERROR(r) && ! force )
break;
......
......@@ -131,7 +131,7 @@ static retvalue save_package_version(void *d,const char *packagename,const char
retvalue upgradelist_initialize(struct upgradelist **ul,struct target *t,const char *dbdir,upgrade_decide_function *decide) {
struct upgradelist *upgrade;
retvalue r;
retvalue r,r2;
upgrade = calloc(1,sizeof(struct upgradelist));
if( upgrade == NULL )
......@@ -147,6 +147,8 @@ retvalue upgradelist_initialize(struct upgradelist **ul,struct target *t,const c
}
r = packages_foreach(t->packages,save_package_version,upgrade,0);
r2 = target_closepackagesdb(t);
RET_UPDATE(r,r2);
if( RET_WAS_ERROR(r) ) {
upgradelist_free(upgrade);
......@@ -290,6 +292,9 @@ static retvalue upgradelist_trypackage(struct upgradelist *upgrade,const char *c
return r;
}
if( r == RET_NOTHING ) {
if( verbose > 30 )
fprintf(stderr,"Ignoring '%s' from '%s' as not newer than '%s'\n",
version,packagename,current->version);
/* there already is a newer version, so
* doing nothing but perhaps updating what
* versions are around, when we are newer
......@@ -308,6 +313,9 @@ static retvalue upgradelist_trypackage(struct upgradelist *upgrade,const char *c
free(packagename);
return RET_NOTHING;
}
if( verbose > 30 )
fprintf(stderr,"'%s' from '%s' is newer than '%s' currently\n",
version,packagename,current->version);
decision = upgrade->decide(current->name,
current->version,version);
if( decision != UD_UPGRADE ) {
......@@ -383,11 +391,17 @@ retvalue upgradelist_enqueue(struct upgradelist *upgrade,struct downloadcache *c
return result;
}
retvalue upgradelist_install(struct upgradelist *upgrade,filesdb files,DB *references,int force){
retvalue upgradelist_install(struct upgradelist *upgrade,const char *dbdir,filesdb files,DB *references,int force){
struct package_data *pkg;
retvalue result,r;
if( upgrade->list == NULL )
return RET_NOTHING;
result = target_initpackagesdb(upgrade->target,dbdir);
if( RET_WAS_ERROR(result) )
return result;
pkg = upgrade->list;
result = RET_NOTHING;
while( pkg ) {
if( pkg->version == pkg->new_version ) {
r = files_expectfiles(files,&pkg->new_filekeys,
......@@ -404,6 +418,8 @@ retvalue upgradelist_install(struct upgradelist *upgrade,filesdb files,DB *refer
}
pkg = pkg->next;
}
r = target_closepackagesdb(upgrade->target);
RET_ENDUPDATE(result,r);
return result;
}
......
......@@ -40,6 +40,6 @@ retvalue upgradelist_update(struct upgradelist *upgrade,struct aptmethod *method
/* request all wanted files refering the methods given before */
retvalue upgradelist_enqueue(struct upgradelist *upgrade,struct downloadcache *cache,filesdb filesdb,int force);
retvalue upgradelist_install(struct upgradelist *upgrade,filesdb files,DB *references,int force);
retvalue upgradelist_install(struct upgradelist *upgrade,const char *dbdir,filesdb files,DB *references,int force);
#endif
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