Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/libalpm/alpm.h1
-rw-r--r--lib/libalpm/package.c85
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 */