From cdbb90aceb288034dbf4f228fc4c49da1e2ed0c0 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Wed, 7 Oct 2009 21:52:09 -0500 Subject: Show 'Required By' in -Sii output Just as we do in -Qi, we can compute required by information for sync database packages. The behavior seems sane; for a given package, the -Sii required by will show all packages in *any* sync database that require it. Implements FS#16244. Signed-off-by: Dan McGee --- lib/libalpm/package.c | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) (limited to 'lib/libalpm') diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c index 742d0f59..f1682cbc 100644 --- a/lib/libalpm/package.c +++ b/lib/libalpm/package.c @@ -555,6 +555,21 @@ int SYMEXPORT alpm_pkg_has_scriptlet(pmpkg_t *pkg) return pkg->scriptlet; } +static void find_requiredby(pmpkg_t *pkg, pmdb_t *db, alpm_list_t **reqs) +{ + const alpm_list_t *i; + for(i = _alpm_db_get_pkgcache(db); i; i = i->next) { + if(!i->data) { + continue; + } + pmpkg_t *cachepkg = i->data; + if(_alpm_dep_edge(cachepkg, pkg)) { + const char *cachepkgname = cachepkg->name; + *reqs = alpm_list_add(*reqs, strdup(cachepkgname)); + } + } +} + /** * @brief Compute the packages requiring a given package. * @param pkg a package @@ -564,16 +579,23 @@ alpm_list_t SYMEXPORT *alpm_pkg_compute_requiredby(pmpkg_t *pkg) { const alpm_list_t *i; alpm_list_t *reqs = NULL; + pmdb_t *db; - 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; - if(_alpm_dep_edge(cachepkg, pkg)) { - const char *cachepkgname = cachepkg->name; - reqs = alpm_list_add(reqs, strdup(cachepkgname)); + if(pkg->origin == PKG_FROM_FILE) { + /* The sane option; search locally for things that require this. */ + db = alpm_option_get_localdb(); + find_requiredby(pkg, db, &reqs); + } else { + /* We have a DB package. if it is a local package, then we should + * only search the local DB; else search all known sync databases. */ + db = pkg->origin_data.db; + if(db->is_local) { + find_requiredby(pkg, db, &reqs); + } else { + for(i = handle->dbs_sync; i; i = i->next) { + db = i->data; + find_requiredby(pkg, db, &reqs); + } } } return(reqs); -- cgit v1.2.3-70-g09d2