Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib/libalpm/package.c
diff options
context:
space:
mode:
authorAllan McRae <allan@archlinux.org>2012-08-12 16:28:42 +1000
committerAllan McRae <allan@archlinux.org>2012-12-14 12:35:34 +1000
commitd0e5cd2c7faef6159ab353714fa5227739994b2f (patch)
tree290fa301adf0daa733f7ec298593a456b3c01e61 /lib/libalpm/package.c
parent9a24f1ffc50deb7d979430ac85475b10b4a98d28 (diff)
Add "Optional for" to package information output
Much like packages that require a give package are displayed in the "Required by" field of its information output, alos display packages that optionally require the package. Inspired-by: Benedikt Morbach <benedikt.morbach@googlemail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'lib/libalpm/package.c')
-rw-r--r--lib/libalpm/package.c34
1 files changed, 27 insertions, 7 deletions
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index 4887e215..f3e0b7fa 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -389,7 +389,8 @@ int SYMEXPORT alpm_pkg_has_scriptlet(alpm_pkg_t *pkg)
return pkg->ops->has_scriptlet(pkg);
}
-static void find_requiredby(alpm_pkg_t *pkg, alpm_db_t *db, alpm_list_t **reqs)
+static void find_requiredby(alpm_pkg_t *pkg, alpm_db_t *db, alpm_list_t **reqs,
+ int optional)
{
const alpm_list_t *i;
pkg->handle->pm_errno = 0;
@@ -397,7 +398,14 @@ static void find_requiredby(alpm_pkg_t *pkg, alpm_db_t *db, alpm_list_t **reqs)
for(i = _alpm_db_get_pkgcache(db); i; i = i->next) {
alpm_pkg_t *cachepkg = i->data;
alpm_list_t *j;
- for(j = alpm_pkg_get_depends(cachepkg); j; j = j->next) {
+
+ if(optional == 0) {
+ j = alpm_pkg_get_depends(cachepkg);
+ } else {
+ j = alpm_pkg_get_optdepends(cachepkg);
+ }
+
+ for(; j; j = j->next) {
if(_alpm_depcmp(pkg, j->data)) {
const char *cachepkgname = cachepkg->name;
if(alpm_list_find_str(*reqs, cachepkgname) == NULL) {
@@ -408,8 +416,7 @@ static void find_requiredby(alpm_pkg_t *pkg, alpm_db_t *db, alpm_list_t **reqs)
}
}
-/** Compute the packages requiring a given package. */
-alpm_list_t SYMEXPORT *alpm_pkg_compute_requiredby(alpm_pkg_t *pkg)
+static alpm_list_t *compute_requiredby(alpm_pkg_t *pkg, int optional)
{
const alpm_list_t *i;
alpm_list_t *reqs = NULL;
@@ -420,17 +427,17 @@ alpm_list_t SYMEXPORT *alpm_pkg_compute_requiredby(alpm_pkg_t *pkg)
if(pkg->origin == ALPM_PKG_FROM_FILE) {
/* The sane option; search locally for things that require this. */
- find_requiredby(pkg, pkg->handle->db_local, &reqs);
+ find_requiredby(pkg, pkg->handle->db_local, &reqs, optional);
} 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->status & DB_STATUS_LOCAL) {
- find_requiredby(pkg, db, &reqs);
+ find_requiredby(pkg, db, &reqs, optional);
} else {
for(i = pkg->handle->dbs_sync; i; i = i->next) {
db = i->data;
- find_requiredby(pkg, db, &reqs);
+ find_requiredby(pkg, db, &reqs, optional);
}
reqs = alpm_list_msort(reqs, alpm_list_count(reqs), _alpm_str_cmp);
}
@@ -438,6 +445,19 @@ alpm_list_t SYMEXPORT *alpm_pkg_compute_requiredby(alpm_pkg_t *pkg)
return reqs;
}
+/** Compute the packages requiring a given package. */
+alpm_list_t SYMEXPORT *alpm_pkg_compute_requiredby(alpm_pkg_t *pkg)
+{
+ return compute_requiredby(pkg, 0);
+}
+
+/** Compute the packages optionally requiring a given package. */
+alpm_list_t SYMEXPORT *alpm_pkg_compute_optionalfor(alpm_pkg_t *pkg)
+{
+ return compute_requiredby(pkg, 1);
+}
+
+
/** @} */
alpm_file_t *_alpm_file_copy(alpm_file_t *dest,