diff options
author | Chantry Xavier <shiningxc@gmail.com> | 2007-08-26 01:07:02 +0200 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2007-09-11 20:41:54 -0500 |
commit | be32aa3004fc04dd0602b657d847fe671fb4372f (patch) | |
tree | 5e5bc78bd489cc492083e28ef133ef183087bab6 /lib | |
parent | 2f0de317b862e154f0b172da0668b887413cc55f (diff) | |
download | pacman-be32aa3004fc04dd0602b657d847fe671fb4372f.tar.xz |
libalpm/package.c : add new alpm_pkg_compute_requiredby function.
Signed-off-by: Chantry Xavier <shiningxc@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libalpm/alpm.h | 1 | ||||
-rw-r--r-- | lib/libalpm/package.c | 85 |
2 files changed, 48 insertions, 38 deletions
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index a3772a05..493b688d 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -195,6 +195,7 @@ int alpm_pkg_checkmd5sum(pmpkg_t *pkg); char *alpm_fetch_pkgurl(const char *url); int alpm_pkg_vercmp(const char *ver1, const char *ver2); char *alpm_pkg_name_hasarch(const char *pkgname); +alpm_list_t *alpm_pkg_compute_requiredby(pmpkg_t *pkg); const char *alpm_pkg_get_filename(pmpkg_t *pkg); const char *alpm_pkg_get_name(pmpkg_t *pkg); diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c index e171d69a..a841bf58 100644 --- a/lib/libalpm/package.c +++ b/lib/libalpm/package.c @@ -533,6 +533,51 @@ unsigned short SYMEXPORT alpm_pkg_has_scriptlet(pmpkg_t *pkg) return pkg->scriptlet; } +/** + * @brief Compute the packages requiring a given package. + * @param pkg a package + * @return the list of packages requiring pkg + * + * A depends on B through n depends <=> A listed in B's requiredby n times + * n == 0 or 1 in almost all cases */ +alpm_list_t SYMEXPORT *alpm_pkg_compute_requiredby(pmpkg_t *pkg) +{ + const alpm_list_t *i, *j; + alpm_list_t *reqs = NULL; + + pmdb_t *localdb = alpm_option_get_localdb(); + for(i = _alpm_db_get_pkgcache(localdb); i; i = i->next) { + if(!i->data) { + continue; + } + pmpkg_t *cachepkg = i->data; + const char *cachepkgname = alpm_pkg_get_name(cachepkg); + + for(j = alpm_pkg_get_depends(cachepkg); j; j = j->next) { + pmdepend_t *dep; + int satisfies; + + if(!j->data) { + continue; + } + dep = alpm_splitdep(j->data); + if(dep == NULL) { + continue; + } + + satisfies = alpm_depcmp(pkg, dep); + FREE(dep); + if(satisfies) { + _alpm_log(PM_LOG_DEBUG, "adding '%s' in requiredby field for '%s'\n", + cachepkgname, pkg->name); + reqs = alpm_list_add(reqs, strdup(cachepkgname)); + break; + } + } + } + return(reqs); +} + /** @} */ /* this function was taken from rpm 4.0.4 and rewritten */ @@ -1107,47 +1152,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, +/* fill in requiredby field of package, * used when we want to install or add a package */ - -/* A depends on B through n depends <=> A listed in B's requiredby n times - * n == 0 or 1 in almost all cases */ void _alpm_pkg_update_requiredby(pmpkg_t *pkg) { - const alpm_list_t *i, *j; - - pmdb_t *localdb = alpm_option_get_localdb(); - for(i = _alpm_db_get_pkgcache(localdb); i; i = i->next) { - if(!i->data) { - continue; - } - pmpkg_t *cachepkg = i->data; - const char *cachepkgname = alpm_pkg_get_name(cachepkg); - - for(j = alpm_pkg_get_depends(cachepkg); j; j = j->next) { - pmdepend_t *dep; - int satisfies; - - if(!j->data) { - continue; - } - dep = alpm_splitdep(j->data); - if(dep == NULL) { - continue; - } - - satisfies = alpm_depcmp(pkg, dep); - FREE(dep); - if(satisfies) { - alpm_list_t *reqs = alpm_pkg_get_requiredby(pkg); - _alpm_log(PM_LOG_DEBUG, "adding '%s' in requiredby field for '%s'\n", - cachepkgname, pkg->name); - reqs = alpm_list_add(reqs, strdup(cachepkgname)); - pkg->requiredby = reqs; - break; - } - } - } + pkg->requiredby = alpm_pkg_compute_requiredby(pkg); } /* TODO this should either be public, or done somewhere else */ |