summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/libalpm/alpm.h8
-rw-r--r--lib/libalpm/package.c34
2 files changed, 35 insertions, 7 deletions
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index bf726fc2..8d6edb81 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -712,6 +712,14 @@ int alpm_pkg_vercmp(const char *a, const char *b);
*/
alpm_list_t *alpm_pkg_compute_requiredby(alpm_pkg_t *pkg);
+/** Computes the list of packages optionally requiring a given package.
+ * The return value of this function is a newly allocated
+ * list of package names (char*), it should be freed by the caller.
+ * @param pkg a package
+ * @return the list of packages optionally requiring pkg
+ */
+alpm_list_t *alpm_pkg_compute_optionalfor(alpm_pkg_t *pkg);
+
/** @name Package Property Accessors
* Any pointer returned by these functions points to internal structures
* allocated by libalpm. They should not be freed nor modified in any
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,