From a3994f975ba6cc52c56efb081fc94809a03500ce Mon Sep 17 00:00:00 2001 From: Nagy Gabor Date: Mon, 14 May 2007 02:54:16 -0400 Subject: Use alpm_depcmp in _alpm_pkg_update_requiredby The old function did too much on its own; let alpm_depcmp do the hard work. This will allow for future versioned provisions if necessary. Signed-off-by: Dan McGee --- lib/libalpm/package.c | 41 +++++++++++++---------------------------- 1 file changed, 13 insertions(+), 28 deletions(-) (limited to 'lib') diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c index e8dd5d60..17851535 100644 --- a/lib/libalpm/package.c +++ b/lib/libalpm/package.c @@ -533,11 +533,11 @@ int _alpm_pkg_splitname(const char *target, char *name, char *version, int witha return(0); } - +/* scan the local db to fill in requiredby field of package, + * used when we want to install or add a package */ void _alpm_pkg_update_requiredby(pmpkg_t *pkg) { - alpm_list_t *i, *j, *k; - const char *pkgname = alpm_pkg_get_name(pkg); + alpm_list_t *i, *j; pmdb_t *localdb = alpm_option_get_localdb(); for(i = _alpm_db_get_pkgcache(localdb); i; i = i->next) { @@ -549,6 +549,8 @@ void _alpm_pkg_update_requiredby(pmpkg_t *pkg) for(j = alpm_pkg_get_depends(cachepkg); j; j = j->next) { pmdepend_t *dep; + int satisfies; + if(!j->data) { continue; } @@ -557,33 +559,16 @@ void _alpm_pkg_update_requiredby(pmpkg_t *pkg) continue; } - /* check the actual package itself */ - if(strcmp(dep->name, pkgname) == 0) { + satisfies = alpm_depcmp(pkg, dep); + free(dep); + if(satisfies) { alpm_list_t *reqs = alpm_pkg_get_requiredby(pkg); - - if(!alpm_list_find_str(reqs, cachepkgname)) { - _alpm_log(PM_LOG_DEBUG, _("adding '%s' in requiredby field for '%s'"), - cachepkgname, pkg->name); - reqs = alpm_list_add(reqs, strdup(cachepkgname)); - pkg->requiredby = reqs; - } + _alpm_log(PM_LOG_DEBUG, _("adding '%s' in requiredby field for '%s'"), + cachepkgname, pkg->name); + reqs = alpm_list_add(reqs, strdup(cachepkgname)); + pkg->requiredby = reqs; + break; } - - /* check for provisions as well */ - for(k = alpm_pkg_get_provides(pkg); k; k = k->next) { - const char *provname = k->data; - if(strcmp(dep->name, provname) == 0) { - alpm_list_t *reqs = alpm_pkg_get_requiredby(pkg); - - if(!alpm_list_find_str(reqs, cachepkgname)) { - _alpm_log(PM_LOG_DEBUG, _("adding '%s' in requiredby field for '%s' (provides: %s)"), - cachepkgname, pkgname, provname); - reqs = alpm_list_add(reqs, strdup(cachepkgname)); - pkg->requiredby = reqs; - } - } - } - free(dep); } } } -- cgit v1.2.3-24-g4f1b