On Thu, Jul 19, 2007 at 08:32:36PM +0200, Nagy Gabor wrote:
self.description = "target vs db conflict will disappear after upgrade"
sp1 = pmpkg("pkg1") sp1.conflicts = ["imaginary"] self.addpkg2db("sync", sp1);
sp2 = pmpkg("pkg2", "1.0-2") self.addpkg2db("sync", sp2)
lp = pmpkg("pkg2", "1.0-1") lp.provides = ["imaginary"] self.addpkg2db("local", lp)
self.args = "-S %s" % " ".join([p.name for p in sp1, sp2])
self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_EXIST=pkg1") self.addrule("PKG_EXIST=pkg2") self.addrule("PKG_VERSION=pkg2|1.0-2")
I thought this was already handled, but no :) Actually, this would just need the check I added to chk_db_vs_targets here : http://projects.archlinux.org/git/?p=pacman.git;a=commitdiff;h=cb164c3130f15... but for the chk_target_vs_db this time. Anyway, by looking at this code again, I thought about a way of cleaning it up a bit, so there is now less code for doing the same thing better imo :)
From 01046d565192b13724f10116708ea9782f83f772 Mon Sep 17 00:00:00 2001 From: Chantry Xavier <shiningxc@gmail.com> Date: Fri, 20 Jul 2007 01:22:45 +0200 Subject: [PATCH] libalpm/conflict.c : cleanup + fix for conflict001.
Signed-off-by: Chantry Xavier <shiningxc@gmail.com> --- lib/libalpm/conflict.c | 228 ++++++++++++++---------------------------------- 1 files changed, 65 insertions(+), 163 deletions(-) diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c index 98f4d66..acfcda9 100644 --- a/lib/libalpm/conflict.c +++ b/lib/libalpm/conflict.c @@ -47,172 +47,83 @@ #include "deps.h" -/** See if potential conflict 'name' matches package 'pkg'. - * @param target the name of the parent package we're checking - * @param depname the name of the dependency we're checking - * @param pkg the package to check - * @param conflict the name of the possible conflict - * @return A depmissing struct indicating the conflict - * @note The first two paramters are here to simplify the addition - * of new 'depmiss' objects. - * - * TODO WTF is a 'depmissing' doing indicating a conflict?? +/** Check if pkg1 conflicts with pkg2 + * @param pkg1 package we are looking at + * @param conflict name of the possible conflict + * @param pkg2 package to check */ -static pmdepmissing_t *does_conflict(const char *target, const char *depname, - pmpkg_t *pkg, const char *conflict) +static int does_conflict(pmpkg_t *pkg1, const char *conflict, pmpkg_t *pkg2) { - alpm_list_t *i; - - /* check the actual package name, easy */ - if(strcmp(alpm_pkg_get_name(pkg), conflict) == 0) { - _alpm_log(PM_LOG_DEBUG, " found conflict '%s' : package '%s'", - conflict, target); - return(_alpm_depmiss_new(target, PM_DEP_TYPE_CONFLICT, - PM_DEP_MOD_ANY, depname, NULL)); - } else { - /* check what this package provides, harder */ - for(i = alpm_pkg_get_provides(pkg); i; i = i->next) { - const char *provision = i->data; - - if(strcmp(provision, conflict) == 0) { - _alpm_log(PM_LOG_DEBUG, " found conflict '%s' : package '%s' provides '%s'", - conflict, target, provision); - return(_alpm_depmiss_new(target, PM_DEP_TYPE_CONFLICT, - PM_DEP_MOD_ANY, depname, NULL)); - } - } + const char *pkg1name = alpm_pkg_get_name(pkg1); + const char *pkg2name = alpm_pkg_get_name(pkg2); + pmdepend_t *conf = alpm_splitdep(conflict); + int match = 0; + + match = alpm_depcmp(pkg2, conf); + if(match) { + _alpm_log(PM_LOG_DEBUG, "package %s conflicts with %s (by %s)", + pkg1name, pkg2name, conflict); } - return(NULL); /* not a conflict */ + free(conf); + return(match); } -static alpm_list_t *chk_pkg_vs_db(alpm_list_t *baddeps, pmpkg_t *pkg, pmdb_t *db) +/** Adds the pkg1/pkg2 conflict to the baddeps list + * + * TODO WTF is a 'depmissing' doing indicating a conflict?? + */ +static void add_conflict(alpm_list_t **baddeps, const char *pkg1, const char *pkg2) { - pmdepmissing_t *miss = NULL; - const char *pkgname; - alpm_list_t *i, *j; - - pkgname = alpm_pkg_get_name(pkg); - - for(i = alpm_pkg_get_conflicts(pkg); i; i = i->next) { - const char *conflict = i->data; - - if(strcmp(pkgname, conflict) == 0) { - /* a package cannot conflict with itself -- that's just not nice */ - _alpm_log(PM_LOG_DEBUG, "package '%s' conflicts with itself - packaging error", - pkgname); - continue; - } - - /* CHECK 1: check targets against database */ - _alpm_log(PM_LOG_DEBUG, "checkconflicts: target '%s' vs db", pkgname); - - for(j = _alpm_db_get_pkgcache(db); j; j = j->next) { - pmpkg_t *dbpkg = j->data; - - if(strcmp(alpm_pkg_get_name(dbpkg), pkgname) == 0) { - /* skip the package we're currently processing */ - continue; - } - - miss = does_conflict(pkgname, alpm_pkg_get_name(dbpkg), dbpkg, conflict); - if(miss && !_alpm_depmiss_isin(miss, baddeps)) { - baddeps = alpm_list_add(baddeps, miss); - } else { - FREE(miss); - } - } + pmdepmissing_t *miss = _alpm_depmiss_new(pkg1, PM_DEP_TYPE_CONFLICT, + PM_DEP_MOD_ANY, pkg2, NULL); + if(miss && !_alpm_depmiss_isin(miss, *baddeps)) { + *baddeps = alpm_list_add(*baddeps, miss); + } else { + FREE(miss); } - return(baddeps); } -static alpm_list_t *chk_pkg_vs_targets(alpm_list_t *baddeps, - pmpkg_t *pkg, pmdb_t *db, - alpm_list_t *targets) -{ - pmdepmissing_t *miss = NULL; - const char *pkgname; - alpm_list_t *i, *j; - - pkgname = alpm_pkg_get_name(pkg); +/** Check if packages from list1 conflict with packages from list2 + * Add the conflicts to the baddeps list, following the order. */ +static void check_conflict(alpm_list_t *list1, alpm_list_t *list2, alpm_list_t **baddeps, int order) { + alpm_list_t *i, *j, *k; - for(i = alpm_pkg_get_conflicts(pkg); i; i = i->next) { - const char *conflict = i->data; - - if(strcmp(pkgname, conflict) == 0) { - /* a package cannot conflict with itself -- that's just not nice */ - _alpm_log(PM_LOG_DEBUG, "package '%s' conflicts with itself - packaging error", - pkgname); - continue; - } - - /* CHECK 2: check targets against targets */ - _alpm_log(PM_LOG_DEBUG, "checkconflicts: target '%s' vs all targets", pkgname); + if(!baddeps) { + return; + } + for(i = list1; i; i = i->next) { + pmpkg_t *pkg1 = i->data; + const char *pkg1name = alpm_pkg_get_name(pkg1); - for(j = targets; j; j = j->next) { - const char *targetname; - pmpkg_t *target = j->data; - targetname = alpm_pkg_get_name(target); + for(j = alpm_pkg_get_conflicts(pkg1); j; j = j->next) { + const char *conflict = j->data; - if(strcmp(targetname, pkgname) == 0) { - /* skip the package we're currently processing */ + if(strcmp(pkg1name, conflict) == 0) { + /* a package cannot conflict with itself -- that's just not nice */ + _alpm_log(PM_LOG_DEBUG, "package '%s' conflicts with itself - packaging error", + pkg1name); continue; } - miss = does_conflict(pkgname, targetname, target, conflict); - if(miss && !_alpm_depmiss_isin(miss, baddeps)) { - baddeps = alpm_list_add(baddeps, miss); - } else { - FREE(miss); - } - } - } - return(baddeps); -} - -static alpm_list_t *chk_db_vs_targets(alpm_list_t *baddeps, pmpkg_t *pkg, - pmdb_t *db, alpm_list_t *targets) -{ - pmdepmissing_t *miss = NULL; - const char *pkgname; - alpm_list_t *i, *j; - - pkgname = alpm_pkg_get_name(pkg); - - _alpm_log(PM_LOG_DEBUG, "checkconflicts: db vs target '%s'", pkgname); - - for(i = _alpm_db_get_pkgcache(db); i; i = i->next) { - alpm_list_t *conflicts = NULL; - const char *dbpkgname; - - pmpkg_t *dbpkg = i->data; - dbpkgname = alpm_pkg_get_name(dbpkg); - - if(strcmp(dbpkgname, pkgname) == 0) { - /* skip the package we're currently processing */ - continue; - } - - if(_alpm_pkg_find(dbpkgname, targets)) { - /* skip targets, already handled by chk_pkg_vs_targets in checkconflicts */ - _alpm_log(PM_LOG_DEBUG, "target '%s' is also in target list, ignoring it", - dbpkgname); - continue; - } - - conflicts = alpm_pkg_get_conflicts(dbpkg); + for(k = list2; k; k = k->next) { + pmpkg_t *pkg2 = k->data; + const char *pkg2name = alpm_pkg_get_name(pkg2); - for(j = conflicts; j; j = j->next) { - const char *conflict = j->data; + if(strcmp(pkg1name, pkg2name) == 0) { + /* skip the package we're currently processing */ + continue; + } - miss = does_conflict(pkgname, dbpkgname, pkg, conflict); - if(miss && !_alpm_depmiss_isin(miss, baddeps)) { - baddeps = alpm_list_add(baddeps, miss); - } else { - FREE(miss); + if(does_conflict(pkg1, conflict, pkg2)) { + if(order >= 0) { + add_conflict(baddeps, pkg1name, pkg2name); + } else { + add_conflict(baddeps, pkg2name, pkg1name); + } + } } } } - return(baddeps); } /* Returns a alpm_list_t* of pmdepmissing_t pointers. @@ -221,7 +132,7 @@ static alpm_list_t *chk_db_vs_targets(alpm_list_t *baddeps, pmpkg_t *pkg, */ alpm_list_t *_alpm_checkconflicts(pmdb_t *db, alpm_list_t *packages) { - alpm_list_t *i, *baddeps = NULL; + alpm_list_t *baddeps = NULL; ALPM_LOG_FUNC; @@ -229,23 +140,14 @@ alpm_list_t *_alpm_checkconflicts(pmdb_t *db, alpm_list_t *packages) return(NULL); } - for(i = packages; i; i = i->next) { - pmpkg_t *pkg = i->data; - if(pkg == NULL) { - continue; - } + alpm_list_t *dblist = alpm_list_diff(_alpm_db_get_pkgcache(db), packages, _alpm_pkg_cmp); - /* run three different conflict checks on each package */ - baddeps = chk_pkg_vs_db(baddeps, pkg, db); - baddeps = chk_pkg_vs_targets(baddeps, pkg, db, packages); - baddeps = chk_db_vs_targets(baddeps, pkg, db, packages); - } - - /* debug loop */ - for(i = baddeps; i; i = i->next) { - pmdepmissing_t *miss = i->data; - _alpm_log(PM_LOG_DEBUG, "\tCONFLICTS:: %s conflicts with %s", miss->target, miss->depend.name); - } + _alpm_log(PM_LOG_DEBUG, "check targets vs db"); + check_conflict(packages, dblist, &baddeps, 1); + _alpm_log(PM_LOG_DEBUG, "check db vs targets"); + check_conflict(dblist, packages, &baddeps, -1); + _alpm_log(PM_LOG_DEBUG, "check targets vs targets"); + check_conflict(packages, packages, &baddeps, 0); return(baddeps); } -- 1.5.2.4