Commit ee1b89f3 authored by Bernhard Link's avatar Bernhard Link

tidy up upgradelist.c and report errors properly

parent 807beeb9
2005-01-26 Bernhard R. Link <brlink@debian.org>
* change FilterList to need a defaultaction given
* tidy up upgradelist.c and report errors properly
2005-01-25 Bernhard R. Link <brlink@debian.org>
* Add ListHook keyword for external processing
of the downloaded index file before updating.
......
......@@ -193,7 +193,7 @@ Method: file:$WORKDIR
Suite: test2
Architectures: coal>abacus abacus source
FilterFormula: Priority(==optional),Package(>=alpha),Package(<=zeta)
FilterList: deinstall list
FilterList: error list
ListHook: /bin/cp
END
......
......@@ -1112,35 +1112,31 @@ upgrade_decision ud_decide_by_pattern(void *privdata, const char *package,const
return UD_HOLD;
case flt_error:
/* cannot yet be handled! */
fprintf(stderr,"Error: unexpected Packagename '%s'!\n",package);
return UD_NO;
fprintf(stderr,"Packagename marked to be unexpected('error'): '%s'!\n",package);
return UD_ERROR;
case flt_install:
break;
}
if( pattern->includecondition ) {
r = term_decidechunk(pattern->includecondition,newcontrolchunk);
// gna..., why is there no way to report errors?
// TODO: fix this insanity...
if( RET_WAS_ERROR(r) )
r = RET_NOTHING;
return UD_ERROR;
if( r == RET_NOTHING ) {
// fprintf(stderr,"Rejecting %s\n",package);
return UD_NO;
}
}
// fprintf(stderr,"Accepting %s\n",package);
return UD_UPGRADE;
}
static inline retvalue searchformissing(const char *dbdir,struct update_target *u,upgrade_decide_function *decide,void *decision_data,int force) {
static inline retvalue searchformissing(const char *dbdir,struct update_target *u,int force) {
struct update_index *index;
retvalue result,r;
if( verbose > 2 )
fprintf(stderr," processing updates for '%s'\n",u->target->identifier);
r = upgradelist_initialize(&u->upgradelist,u->target,dbdir,decide,decision_data);
r = upgradelist_initialize(&u->upgradelist,u->target,dbdir);
if( RET_WAS_ERROR(r) )
return r;
......@@ -1190,7 +1186,7 @@ static retvalue updates_readindices(const char *dbdir,struct distribution *distr
result = RET_NOTHING;
for( u=distribution->updatetargets ; u ; u=u->next ) {
r = searchformissing(dbdir,u,ud_always,NULL,force);
r = searchformissing(dbdir,u,force);
RET_UPDATE(result,r);
if( RET_WAS_ERROR(r) && !force )
break;
......@@ -1324,6 +1320,10 @@ retvalue updates_update(const char *dbdir,const char *methoddir,filesdb filesdb,
if( RET_WAS_ERROR(r) && ! force )
break;
}
if( RET_WAS_ERROR(result) && ! force ) {
aptmethod_shutdown(run);
return result;
}
if( verbose >= 0 )
fprintf(stderr,"Getting packages...\n");
r = aptmethod_download(run,methoddir,filesdb);
......
......@@ -65,8 +65,6 @@ struct package_data {
};
struct upgradelist {
upgrade_decide_function *decide;
void *decide_data;
struct target *target;
struct package_data *list;
/* package the next package will most probably be after.
......@@ -143,7 +141,7 @@ static retvalue save_package_version(void *d,const char *packagename,const char
return RET_OK;
}
retvalue upgradelist_initialize(struct upgradelist **ul,struct target *t,const char *dbdir,upgrade_decide_function *decide,void *decide_data) {
retvalue upgradelist_initialize(struct upgradelist **ul,struct target *t,const char *dbdir) {
struct upgradelist *upgrade;
retvalue r,r2;
......@@ -151,8 +149,6 @@ retvalue upgradelist_initialize(struct upgradelist **ul,struct target *t,const c
if( upgrade == NULL )
return RET_ERROR_OOM;
upgrade->decide = decide;
upgrade->decide_data = decide_data;
upgrade->target = t;
r = target_initpackagesdb(t,dbdir);
......@@ -224,21 +220,20 @@ static retvalue upgradelist_trypackage(void *data,const char *chunk){
* again and again... and again... and even some more...*/
while(1) {
//TODO: rename this!
int found;
int cmp;
assert( insertafter == NULL || insertafter->next == current );
assert( insertafter != NULL || current == upgrade->list );
if( current == NULL )
found = -1; /* every package is before the end of list */
cmp = -1; /* every package is before the end of list */
else
found = strcmp(packagename,current->name);
cmp = strcmp(packagename,current->name);
if( found == 0 )
if( cmp == 0 )
break;
if( found < 0 ) {
if( cmp < 0 ) {
int precmp;
if( insertafter == NULL ) {
......@@ -267,7 +262,7 @@ static retvalue upgradelist_trypackage(void *data,const char *chunk){
}
assert( "This is not reached" == NULL );
}
/* found > 0 : may come later... */
/* cmp > 0 : may come later... */
assert( current != NULL );
insertafter = current;
current = current->next;
......@@ -282,13 +277,11 @@ static retvalue upgradelist_trypackage(void *data,const char *chunk){
struct package_data *new;
decision = upgrade->predecide(upgrade->predecide_data,packagename,NULL,version,chunk);
if( decision == UD_UPGRADE )
decision = upgrade->decide(upgrade->decide_data,packagename,NULL,version,chunk);
if( decision != UD_UPGRADE ) {
upgrade->last = insertafter;
free(packagename);
free(version);
return RET_NOTHING;
return (decision==UD_ERROR)?RET_ERROR:RET_NOTHING;
}
new = calloc(1,sizeof(struct package_data));
......@@ -359,9 +352,6 @@ static retvalue upgradelist_trypackage(void *data,const char *chunk){
version,packagename,current->version);
decision = upgrade->predecide(upgrade->predecide_data,current->name,
current->version,version,chunk);
if( decision == UD_UPGRADE )
decision = upgrade->decide(upgrade->decide_data,current->name,
current->version,version,chunk);
if( decision != UD_UPGRADE ) {
/* Even if we do not install it, setting it on hold
* will keep it or even install from a mirror before
......@@ -370,7 +360,7 @@ static retvalue upgradelist_trypackage(void *data,const char *chunk){
current->deleted = FALSE;
free(version);
free(packagename);
return RET_NOTHING;
return (decision==UD_ERROR)?RET_ERROR:RET_NOTHING;
}
if( versioncmp == 0 ) {
......
......@@ -13,7 +13,7 @@
/* Things for making decisions what to upgrade and what not */
typedef enum { UD_NO, UD_UPGRADE, UD_HOLD } upgrade_decision;
typedef enum { UD_ERROR, UD_NO, UD_UPGRADE, UD_HOLD } upgrade_decision;
typedef upgrade_decision upgrade_decide_function(void *privdata, const char *package,const char *old_version,const char *new_version,const char *newcontrolchunk);
......@@ -24,7 +24,7 @@ upgrade_decision ud_always(void *privdata, const char *p,const char *ov,const ch
struct target;
struct upgradelist;
retvalue upgradelist_initialize(struct upgradelist **ul,struct target *target,const char *dbdir,upgrade_decide_function *decide,void *decide_data);
retvalue upgradelist_initialize(struct upgradelist **ul,struct target *target,const char *dbdir);
retvalue upgradelist_free(struct upgradelist *upgrade);
void upgradelist_dump(struct upgradelist *upgrade);
......
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