From cf2556872b850f5d9c26975b5e287a4bf7ef38ca Mon Sep 17 00:00:00 2001 From: Stefan Schubert Date: Mon, 28 Jan 2008 16:16:52 +0000 Subject: [PATCH] Added callbacks for policy handling. --- src/policy.c | 38 +++++++++++++++++++++++-------- src/policy.h | 8 +++---- src/solver.c | 6 +++-- src/solver.h | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++--------- 4 files changed, 100 insertions(+), 25 deletions(-) diff --git a/src/policy.c b/src/policy.c index 4c632e5..646f937 100644 --- a/src/policy.c +++ b/src/policy.c @@ -296,8 +296,13 @@ prune_to_best_version(Pool *pool, Queue *plist) /* legacy, do not use anymore! */ void -prune_best_version_arch(Pool *pool, Queue *plist) +prune_best_version_arch(Solver *solv, Pool *pool, Queue *plist) { + if (solv && solv->bestSolvableCb) + { /* The application is responsible for */ + return solv->bestSolvableCb (plist); + } + if (plist->count > 1) prune_to_best_arch(pool, plist); if (plist->count > 1) @@ -316,18 +321,21 @@ policy_filter_unwanted(Solver *solv, Queue *plist, Id inst, int mode) /* FIXME: do this different! */ if (inst) queue_push(plist, inst); - if (plist->count > 1) - prune_to_best_arch(pool, plist); - if (plist->count > 1) - prune_to_best_version(pool, plist); + + prune_best_version_arch (solv, pool, plist); } int -policy_illegal_archchange(Pool *pool, Solvable *s1, Solvable *s2) +policy_illegal_archchange(Solver *solv, Pool *pool, Solvable *s1, Solvable *s2) { Id a1 = s1->arch, a2 = s2->arch; + if (solv && solv->archCheckCb) + { /* The application is responsible for */ + return solv->archCheckCb (s1, s2); + } + /* we allow changes to/from noarch */ if (a1 == a2 || a1 == ARCH_NOARCH || a2 == ARCH_NOARCH) return 0; @@ -341,9 +349,15 @@ policy_illegal_archchange(Pool *pool, Solvable *s1, Solvable *s2) } int -policy_illegal_vendorchange(Pool *pool, Solvable *s1, Solvable *s2) +policy_illegal_vendorchange(Solver *solv, Pool *pool, Solvable *s1, Solvable *s2) { Id vendormask1, vendormask2; + + if (solv && solv->vendorCheckCb) + { /* The application is responsible for */ + return solv->vendorCheckCb (s1, s2); + } + if (s1->vendor == s2->vendor) return 0; vendormask1 = pool_vendor2mask(pool, s1->vendor); @@ -366,6 +380,12 @@ policy_findupdatepackages(Solver *solv, Solvable *s, Queue *qs, int allowall) Id vendormask; queue_empty(qs); + + if (solv && solv->updateCandidateCb) + { /* The application is responsible for */ + return solv->updateCandidateCb (s, qs); + } + /* * s = solvable ptr * n = solvable Id @@ -388,9 +408,9 @@ policy_findupdatepackages(Solver *solv, Solvable *s, Queue *qs, int allowall) { if (!solv->allowdowngrade && evrcmp(pool, s->evr, ps->evr, EVRCMP_MATCH_RELEASE) > 0) continue; - if (!solv->allowarchchange && s->arch != ps->arch && policy_illegal_archchange(pool, s, ps)) + if (!solv->allowarchchange && s->arch != ps->arch && policy_illegal_archchange(solv, pool, s, ps)) continue; - if (!solv->allowvendorchange && s->vendor != ps->vendor && policy_illegal_vendorchange(pool, s, ps)) + if (!solv->allowvendorchange && s->vendor != ps->vendor && policy_illegal_vendorchange(solv, pool, s, ps)) continue; } } diff --git a/src/policy.h b/src/policy.h index 7dea8ce..392e27b 100644 --- a/src/policy.h +++ b/src/policy.h @@ -16,14 +16,14 @@ #define POLICY_MODE_RECOMMEND 1 #define POLICY_MODE_SUGGEST 2 -/* legacy, do not use! */ -extern void prune_best_version_arch(Pool *pool, Queue *plist); +extern void prune_best_version_arch(Solver *solv, Pool *pool, Queue *plist); extern void policy_filter_unwanted(Solver *solv, Queue *plist, Id inst, int mode); -extern int policy_illegal_archchange(Pool *pool, Solvable *s1, Solvable *s2); -extern int policy_illegal_vendorchange(Pool *pool, Solvable *s1, Solvable *s2); +extern int policy_illegal_archchange(Solver *solv, Pool *pool, Solvable *s1, Solvable *s2); +extern int policy_illegal_vendorchange(Solver *solv, Pool *pool, Solvable *s1, Solvable *s2); extern void policy_findupdatepackages(Solver *solv, Solvable *s, Queue *qs, int allowall); /* do not regard policies for vendor,architecuture,... change */ + diff --git a/src/solver.c b/src/solver.c index dcc6656..11c325a 100644 --- a/src/solver.c +++ b/src/solver.c @@ -24,6 +24,8 @@ #include "evr.h" #include "policy.h" + + #define RULES_BLOCK 63 #define REGARD_RECOMMENDS_OF_INSTALLED_ITEMS 0 @@ -3239,12 +3241,12 @@ printsolutions(Solver *solv, Queue *job) POOL_DEBUG(SAT_DEBUG_RESULT, "- allow downgrade of %s to %s\n", solvable2str(pool, s), solvable2str(pool, sd)); gotone = 1; } - if (!solv->allowarchchange && s->name == sd->name && s->arch != sd->arch && policy_illegal_archchange(pool, s, sd)) + if (!solv->allowarchchange && s->name == sd->name && s->arch != sd->arch && policy_illegal_archchange(solv, pool, s, sd)) { POOL_DEBUG(SAT_DEBUG_RESULT, "- allow architecture change of %s to %s\n", solvable2str(pool, s), solvable2str(pool, sd)); gotone = 1; } - if (!solv->allowvendorchange && s->name == sd->name && s->vendor != sd->vendor && policy_illegal_vendorchange(pool, s, sd)) + if (!solv->allowvendorchange && s->name == sd->name && s->vendor != sd->vendor && policy_illegal_vendorchange(solv,pool, s, sd)) { if (sd->vendor) POOL_DEBUG(SAT_DEBUG_RESULT, "- allow vendor change from '%s' (%s) to '%s' (%s)\n", id2str(pool, s->vendor), solvable2str(pool, s), id2str(pool, sd->vendor), solvable2str(pool, sd)); diff --git a/src/solver.h b/src/solver.h index fa1e57c..9c7803c 100644 --- a/src/solver.h +++ b/src/solver.h @@ -18,6 +18,15 @@ #include "repo.h" #include "queue.h" #include "bitmap.h" +/* + * Callback definitions in order to "overwrite" the policies by an external application. + */ + +typedef void (*BestSolvableCb) (Queue *canditates); +typedef int (*ArchCheckCb) (Solvable *solvable1, Solvable *solvable2); +typedef int (*VendorCheckCb) (Solvable *solvable1, Solvable *solvable2); +typedef void (*UpdateCandidateCb) (Solvable *solvable, Queue *canditates); + /* ---------------------------------------------- * Rule @@ -49,16 +58,6 @@ struct solver; typedef struct solver { Pool *pool; Repo *installed; - - int fixsystem; /* repair errors in rpm dependency graph */ - int allowdowngrade; /* allow to downgrade installed solvable */ - int allowarchchange; /* allow to change architecture of installed solvables */ - int allowvendorchange; /* allow to change vendor of installed solvables */ - int allowuninstall; /* allow removal of installed solvables */ - int updatesystem; /* distupgrade */ - int allowvirtualconflicts; /* false: conflicts on package name, true: conflicts on package provides */ - int noupdateprovide; /* true: update packages needs not to provide old package */ - int dosplitprovides; /* true: consider legacy split provides */ Rule *rules; /* all rules */ Id nrules; /* index of the last rule */ @@ -108,6 +107,60 @@ typedef struct solver { Id *obsoletes_data; /* data area for obsoletes */ Queue covenantq; /* Covenants honored by this solver (generic locks) */ + + /*------------------------------------------------------------------------------------------------------------- + * Solver configuration + *-------------------------------------------------------------------------------------------------------------*/ + + int fixsystem; /* repair errors in rpm dependency graph */ + int allowdowngrade; /* allow to downgrade installed solvable */ + int allowarchchange; /* allow to change architecture of installed solvables */ + int allowvendorchange; /* allow to change vendor of installed solvables */ + int allowuninstall; /* allow removal of installed solvables */ + int updatesystem; /* distupgrade */ + int allowvirtualconflicts; /* false: conflicts on package name, true: conflicts on package provides */ + int noupdateprovide; /* true: update packages needs not to provide old package */ + int dosplitprovides; /* true: consider legacy split provides */ + + /* Callbacks for defining the bahaviour of the SAT solver */ + + /* Finding best candidate + * + * Callback definition: + * void bestSolvable (Queue *canditates) + * candidates : List of canditates which has to be sorted by the function call + * return candidates: Sorted list of the candidates(first is the best). + */ + BestSolvableCb bestSolvableCb; + + /* Checking if two solvables has compatible architectures + * + * Callback definition: + * int archCheck (Solvable *solvable1, Solvable *solvable2); + * + * return 0 it the two solvables has compatible architectures + */ + ArchCheckCb archCheckCb; + + /* Checking if two solvables has compatible vendors + * + * Callback definition: + * int vendorCheck (Solvable *solvable1, Solvable *solvable2); + * + * return 0 it the two solvables has compatible architectures + */ + VendorCheckCb vendorCheckCb; + + /* Evaluate update candidate + * + * Callback definition: + * void pdateCandidateCb (Solvable *solvable, Queue *canditates) + * solvable : for which updates should be search + * candidates : List of candidates (This list depends on other + * restrictions like architecture and vendor policies too) + */ + UpdateCandidateCb updateCandidateCb; + } Solver; -- 2.7.4