summaryrefslogtreecommitdiff
path: root/lib/libalpm/deps.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libalpm/deps.c')
-rw-r--r--lib/libalpm/deps.c424
1 files changed, 246 insertions, 178 deletions
diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c
index 524136bd..946a42ff 100644
--- a/lib/libalpm/deps.c
+++ b/lib/libalpm/deps.c
@@ -26,9 +26,6 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-#ifdef __sun__
-#include <strings.h>
-#endif
/* libalpm */
#include "deps.h"
@@ -40,7 +37,6 @@
#include "db.h"
#include "cache.h"
#include "provide.h"
-#include "versioncmp.h"
#include "handle.h"
extern pmhandle_t *handle;
@@ -77,7 +73,7 @@ pmdepmissing_t *_alpm_depmiss_new(const char *target, pmdeptype_t type,
miss = malloc(sizeof(pmdepmissing_t));
if(miss == NULL) {
- _alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes"), sizeof(pmdepmissing_t));
+ _alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes\n"), sizeof(pmdepmissing_t));
RET_ERR(PM_ERR_MEMORY, NULL);
}
@@ -111,6 +107,46 @@ int _alpm_depmiss_isin(pmdepmissing_t *needle, alpm_list_t *haystack)
return(0);
}
+/* Convert a list of pmpkg_t * to a graph structure,
+ * with a edge for each dependency.
+ * Returns a list of vertices (one vertex = one package)
+ * (used by alpm_sortbydeps)
+ */
+static alpm_list_t *_alpm_graph_init(alpm_list_t *targets)
+{
+ alpm_list_t *i, *j, *k;
+ alpm_list_t *vertices = NULL;
+ /* We create the vertices */
+ for(i = targets; i; i = i->next) {
+ pmgraph_t *vertex = _alpm_graph_new();
+ vertex->data = (void *)i->data;
+ vertices = alpm_list_add(vertices, vertex);
+ }
+
+ /* We compute the edges */
+ for(i = vertices; i; i = i->next) {
+ pmgraph_t *vertex_i = i->data;
+ pmpkg_t *p_i = vertex_i->data;
+ /* TODO this should be somehow combined with _alpm_checkdeps */
+ for(j = vertices; j; j = j->next) {
+ pmgraph_t *vertex_j = j->data;
+ pmpkg_t *p_j = vertex_j->data;
+ int child = 0;
+ for(k = alpm_pkg_get_depends(p_i); k && !child; k = k->next) {
+ pmdepend_t *depend = alpm_splitdep(k->data);
+ child = alpm_depcmp(p_j, depend);
+ free(depend);
+ }
+ if(child) {
+ vertex_i->children =
+ alpm_list_add(vertex_i->children, vertex_j);
+ }
+ }
+ vertex_i->childptr = vertex_i->children;
+ }
+ return(vertices);
+}
+
/* Re-order a list of target packages with respect to their dependencies.
*
* Example (PM_TRANS_TYPE_ADD):
@@ -129,7 +165,6 @@ int _alpm_depmiss_isin(pmdepmissing_t *needle, alpm_list_t *haystack)
alpm_list_t *_alpm_sortbydeps(alpm_list_t *targets, pmtranstype_t mode)
{
alpm_list_t *newtargs = NULL;
- alpm_list_t *i, *j, *k;
alpm_list_t *vertices = NULL;
alpm_list_t *vptr;
pmgraph_t *vertex;
@@ -140,34 +175,9 @@ alpm_list_t *_alpm_sortbydeps(alpm_list_t *targets, pmtranstype_t mode)
return(NULL);
}
- _alpm_log(PM_LOG_DEBUG, _("started sorting dependencies"));
-
- /* We create the vertices */
- for(i = targets; i; i = i->next) {
- pmgraph_t *vertex = _alpm_graph_new();
- vertex->data = (void *)i->data;
- vertices = alpm_list_add(vertices, vertex);
- }
+ _alpm_log(PM_LOG_DEBUG, "started sorting dependencies\n");
- /* We compute the edges */
- for(i = vertices; i; i = i->next) {
- pmgraph_t *vertex_i = i->data;
- pmpkg_t *p_i = vertex_i->data;
- /* TODO this should be somehow combined with _alpm_checkdeps */
- for(j = vertices; j; j = j->next) {
- pmgraph_t *vertex_j = j->data;
- pmpkg_t *p_j = vertex_j->data;
- int child = 0;
- for(k = alpm_pkg_get_depends(p_i); k && !child; k = k->next) {
- pmdepend_t *depend = alpm_splitdep(k->data);
- child = alpm_depcmp(p_j, depend);
- free(depend);
- }
- if(child) vertex_i->children =
- alpm_list_add(vertex_i->children, vertex_j);
- }
- vertex_i->childptr = vertex_i->children;
- }
+ vertices = _alpm_graph_init(targets);
vptr = vertices;
vertex = vertices->data;
@@ -203,7 +213,7 @@ alpm_list_t *_alpm_sortbydeps(alpm_list_t *targets, pmtranstype_t mode)
}
}
- _alpm_log(PM_LOG_DEBUG, _("sorting dependencies finished"));
+ _alpm_log(PM_LOG_DEBUG, "sorting dependencies finished\n");
if(mode == PM_TRANS_TYPE_REMOVE) {
/* we're removing packages, so reverse the order */
@@ -218,12 +228,19 @@ alpm_list_t *_alpm_sortbydeps(alpm_list_t *targets, pmtranstype_t mode)
return(newtargs);
}
-/** Checks dependencies and returns missing ones in a list. Dependencies can include versions with depmod operators.
+/** Checks dependencies and returns missing ones in a list.
+ * Dependencies can include versions with depmod operators.
* @param db pointer to the local package database
* @param op transaction type
* @param packages an alpm_list_t* of packages to be checked
- * @return an alpm_list_t* of missing_t pointers.
+ * @return an alpm_list_t* of pmpkg_t* of missing_t pointers.
*/
+alpm_list_t SYMEXPORT *alpm_checkdeps(pmdb_t *db, pmtranstype_t op,
+ alpm_list_t *packages)
+{
+ return(_alpm_checkdeps(db, op, packages));
+}
+
alpm_list_t *_alpm_checkdeps(pmdb_t *db, pmtranstype_t op,
alpm_list_t *packages)
{
@@ -246,12 +263,12 @@ alpm_list_t *_alpm_checkdeps(pmdb_t *db, pmtranstype_t op,
pmpkg_t *newpkg = i->data;
pmpkg_t *oldpkg;
if(newpkg == NULL) {
- _alpm_log(PM_LOG_DEBUG, _("null package found in package list"));
+ _alpm_log(PM_LOG_DEBUG, "null package found in package list\n");
continue;
}
if((oldpkg = _alpm_db_get_pkgfromcache(db, alpm_pkg_get_name(newpkg))) == NULL) {
- _alpm_log(PM_LOG_DEBUG, _("cannot find package installed '%s'"),
+ _alpm_log(PM_LOG_DEBUG, "cannot find package installed '%s'\n",
alpm_pkg_get_name(newpkg));
continue;
}
@@ -284,7 +301,7 @@ alpm_list_t *_alpm_checkdeps(pmdb_t *db, pmtranstype_t op,
pmpkg_t *pkg = l->data;
if(alpm_depcmp(pkg, depend)) {
- _alpm_log(PM_LOG_DEBUG, _("checkdeps: dependency '%s' has moved from '%s' to '%s'"),
+ _alpm_log(PM_LOG_DEBUG, "checkdeps: dependency '%s' has moved from '%s' to '%s'\n",
depend->name, alpm_pkg_get_name(oldpkg), alpm_pkg_get_name(pkg));
satisfied = 1;
break;
@@ -300,7 +317,7 @@ alpm_list_t *_alpm_checkdeps(pmdb_t *db, pmtranstype_t op,
if(alpm_depcmp(pkg, depend) && !_alpm_pkg_find(alpm_pkg_get_name(pkg), packages)) {
/* we ignore packages that will be updated because we know
* that the updated ones don't satisfy depend */
- _alpm_log(PM_LOG_DEBUG, _("checkdeps: dependency '%s' satisfied by installed package '%s'"),
+ _alpm_log(PM_LOG_DEBUG, "checkdeps: dependency '%s' satisfied by installed package '%s'\n",
depend->name, alpm_pkg_get_name(pkg));
satisfied = 1;
break;
@@ -309,7 +326,7 @@ alpm_list_t *_alpm_checkdeps(pmdb_t *db, pmtranstype_t op,
}
if(!satisfied) {
- _alpm_log(PM_LOG_DEBUG, _("checkdeps: updated '%s' won't satisfy a dependency of '%s'"),
+ _alpm_log(PM_LOG_DEBUG, "checkdeps: updated '%s' won't satisfy a dependency of '%s'\n",
alpm_pkg_get_name(oldpkg), alpm_pkg_get_name(p));
miss = _alpm_depmiss_new(p->name, PM_DEP_TYPE_DEPEND, depend->mod,
depend->name, depend->version);
@@ -320,7 +337,7 @@ alpm_list_t *_alpm_checkdeps(pmdb_t *db, pmtranstype_t op,
}
}
}
- free(depend);
+ FREE(depend);
}
}
}
@@ -330,7 +347,7 @@ alpm_list_t *_alpm_checkdeps(pmdb_t *db, pmtranstype_t op,
for(i = packages; i; i = i->next) {
pmpkg_t *tp = i->data;
if(tp == NULL) {
- _alpm_log(PM_LOG_DEBUG, _("null package found in package list"));
+ _alpm_log(PM_LOG_DEBUG, "null package found in package list\n");
continue;
}
@@ -358,7 +375,7 @@ alpm_list_t *_alpm_checkdeps(pmdb_t *db, pmtranstype_t op,
/* else if still not found... */
if(!found) {
- _alpm_log(PM_LOG_DEBUG, _("missing dependency '%s' for package '%s'"),
+ _alpm_log(PM_LOG_DEBUG, "missing dependency '%s' for package '%s'\n",
depend->name, alpm_pkg_get_name(tp));
miss = _alpm_depmiss_new(alpm_pkg_get_name(tp), PM_DEP_TYPE_DEPEND, depend->mod,
depend->name, depend->version);
@@ -368,7 +385,7 @@ alpm_list_t *_alpm_checkdeps(pmdb_t *db, pmtranstype_t op,
FREE(miss);
}
}
- free(depend);
+ FREE(depend);
}
}
} else if(op == PM_TRANS_TYPE_REMOVE) {
@@ -377,7 +394,7 @@ alpm_list_t *_alpm_checkdeps(pmdb_t *db, pmtranstype_t op,
pmpkg_t *rmpkg = alpm_list_getdata(i);
if(rmpkg == NULL) {
- _alpm_log(PM_LOG_DEBUG, _("null package found in package list"));
+ _alpm_log(PM_LOG_DEBUG, "null package found in package list\n");
continue;
}
for(j = alpm_pkg_get_requiredby(rmpkg); j; j = j->next) {
@@ -404,7 +421,7 @@ alpm_list_t *_alpm_checkdeps(pmdb_t *db, pmtranstype_t op,
for(l = _alpm_db_get_pkgcache(db); l; l = l->next) {
pmpkg_t *pkg = l->data;
if(alpm_depcmp(pkg, depend) && !_alpm_pkg_find(alpm_pkg_get_name(pkg), packages)) {
- _alpm_log(PM_LOG_DEBUG, _("checkdeps: dependency '%s' satisfied by installed package '%s'"),
+ _alpm_log(PM_LOG_DEBUG, "checkdeps: dependency '%s' satisfied by installed package '%s'\n",
depend->name, alpm_pkg_get_name(pkg));
satisfied = 1;
break;
@@ -412,7 +429,7 @@ alpm_list_t *_alpm_checkdeps(pmdb_t *db, pmtranstype_t op,
}
if(!satisfied) {
- _alpm_log(PM_LOG_DEBUG, _("checkdeps: found %s which requires %s"),
+ _alpm_log(PM_LOG_DEBUG, "checkdeps: found %s which requires %s\n",
alpm_pkg_get_name(p), alpm_pkg_get_name(rmpkg));
miss = _alpm_depmiss_new(alpm_pkg_get_name(p),
PM_DEP_TYPE_DEPEND, depend->mod, depend->name,
@@ -424,7 +441,7 @@ alpm_list_t *_alpm_checkdeps(pmdb_t *db, pmtranstype_t op,
}
}
}
- free(depend);
+ FREE(depend);
}
}
}
@@ -433,6 +450,61 @@ alpm_list_t *_alpm_checkdeps(pmdb_t *db, pmtranstype_t op,
return(baddeps);
}
+static int _alpm_dep_vercmp(const char *version1, pmdepmod_t mod,
+ const char *version2)
+{
+ int equal = 0;
+
+ if(mod == PM_DEP_MOD_ANY) {
+ equal = 1;
+ } else {
+ int cmp = _alpm_versioncmp(version1, version2);
+ switch(mod) {
+ case PM_DEP_MOD_EQ: equal = (cmp == 0); break;
+ case PM_DEP_MOD_GE: equal = (cmp >= 0); break;
+ case PM_DEP_MOD_LE: equal = (cmp <= 0); break;
+ default: equal = 1; break;
+ }
+ }
+ return(equal);
+}
+
+int SYMEXPORT alpm_depcmp(pmpkg_t *pkg, pmdepend_t *dep)
+{
+ int equal = 0;
+
+ ALPM_LOG_FUNC;
+
+ const char *pkgname = alpm_pkg_get_name(pkg);
+ const char *pkgversion = alpm_pkg_get_version(pkg);
+
+ if(strcmp(pkgname, dep->name) == 0
+ || alpm_list_find_str(alpm_pkg_get_provides(pkg), dep->name)) {
+
+ equal = _alpm_dep_vercmp(pkgversion, dep->mod, dep->version);
+
+ char *mod = "~=";
+ switch(dep->mod) {
+ case PM_DEP_MOD_EQ: mod = "=="; break;
+ case PM_DEP_MOD_GE: mod = ">="; break;
+ case PM_DEP_MOD_LE: mod = "<="; break;
+ default: break;
+ }
+
+ if(strlen(dep->version) > 0) {
+ _alpm_log(PM_LOG_DEBUG, "depcmp: %s-%s %s %s-%s => %s\n",
+ pkgname, pkgversion,
+ mod, dep->name, dep->version, (equal ? "match" : "no match"));
+ } else {
+ _alpm_log(PM_LOG_DEBUG, "depcmp: %s-%s %s %s => %s\n",
+ pkgname, pkgversion,
+ mod, dep->name, (equal ? "match" : "no match"));
+ }
+ }
+
+ return(equal);
+}
+
pmdepend_t SYMEXPORT *alpm_splitdep(const char *depstring)
{
pmdepend_t *depend;
@@ -446,7 +518,7 @@ pmdepend_t SYMEXPORT *alpm_splitdep(const char *depstring)
depend = malloc(sizeof(pmdepend_t));
if(depend == NULL) {
- _alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes"), sizeof(pmdepend_t));
+ _alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes\n"), sizeof(pmdepend_t));
return(NULL);
}
@@ -482,10 +554,12 @@ pmdepend_t SYMEXPORT *alpm_splitdep(const char *depstring)
return(depend);
}
-/* These parameters are messy. We check if this package, given a list of
- * targets (and a db), is safe to remove. We do NOT remove it if it is in the
- * target list */
-static int can_remove_package(pmdb_t *db, pmpkg_t *pkg, alpm_list_t *targets)
+/* These parameters are messy. We check if this package, given a list of
+ * targets and a db is safe to remove. We do NOT remove it if it is in the
+ * target list, or if if the package was explictly installed and
+ * include_explicit == 0 */
+static int can_remove_package(pmdb_t *db, pmpkg_t *pkg, alpm_list_t *targets,
+ int include_explicit)
{
alpm_list_t *i;
@@ -493,12 +567,21 @@ static int can_remove_package(pmdb_t *db, pmpkg_t *pkg, alpm_list_t *targets)
return(0);
}
- /* see if it was explicitly installed */
- if(alpm_pkg_get_reason(pkg) == PM_PKG_REASON_EXPLICIT) {
- _alpm_log(PM_LOG_DEBUG, _("excluding %s -- explicitly installed"), alpm_pkg_get_name(pkg));
- return(0);
+ if(!include_explicit) {
+ /* see if it was explicitly installed */
+ if(alpm_pkg_get_reason(pkg) == PM_PKG_REASON_EXPLICIT) {
+ _alpm_log(PM_LOG_DEBUG, "excluding %s -- explicitly installed\n",
+ alpm_pkg_get_name(pkg));
+ return(0);
+ }
}
+ /* TODO: checkdeps could be used here, it handles multiple providers
+ * better, but that also makes it slower.
+ * Also this would require to first add the package to the targets list,
+ * then call checkdeps with it, then remove the package from the targets list
+ * if checkdeps detected it would break something */
+
/* see if other packages need it */
for(i = alpm_pkg_get_requiredby(pkg); i; i = i->next) {
pmpkg_t *reqpkg = _alpm_db_get_pkgfromcache(db, i->data);
@@ -511,89 +594,76 @@ static int can_remove_package(pmdb_t *db, pmpkg_t *pkg, alpm_list_t *targets)
return(1);
}
-/* return a new alpm_list_t target list containing all packages in the original
- * target list, as well as all their un-needed dependencies. By un-needed,
- * I mean dependencies that are *only* required for packages in the target
- * list, so they can be safely removed. This function is recursive.
+/**
+ * @brief Adds unneeded dependencies to an existing list of packages.
+ * By unneeded, we mean dependencies that are only required by packages in the
+ * target list, so they can be safely removed.
+ *
+ * @param db package database to do dependency tracing in
+ * @param *targs pointer to a list of packages
+ * @param include_explicit if 0, explicitly installed packages are not included
*/
-alpm_list_t *_alpm_removedeps(pmdb_t *db, alpm_list_t *targs)
+void _alpm_recursedeps(pmdb_t *db, alpm_list_t **targs, int include_explicit)
{
alpm_list_t *i, *j, *k;
- alpm_list_t *newtargs = targs;
ALPM_LOG_FUNC;
- if(db == NULL) {
- return(newtargs);
+ if(db == NULL || targs == NULL) {
+ return;
}
- for(i = targs; i; i = i->next) {
- pmpkg_t *pkg = i->data;
- for(j = alpm_pkg_get_depends(pkg); j; j = j->next) {
- pmdepend_t *depend = alpm_splitdep(j->data);
- pmpkg_t *deppkg;
- if(depend == NULL) {
- continue;
- }
-
- deppkg = _alpm_db_get_pkgfromcache(db, depend->name);
- if(deppkg == NULL) {
- /* package not found... look for a provision instead */
- alpm_list_t *provides = _alpm_db_whatprovides(db, depend->name);
- if(!provides) {
- /* Not found, that's fine, carry on */
- _alpm_log(PM_LOG_DEBUG, _("cannot find package \"%s\" or anything that provides it!"), depend->name);
+ /* TODO: the while loop should be removed if we can assume
+ * that alpm_list_add (or another function) adds to the end of the list,
+ * and that the target list is topo sorted (by _alpm_sortbydeps()).
+ */
+ int ready = 0;
+ while(!ready) {
+ ready = 1;
+ for(i = *targs; i; i = i->next) {
+ pmpkg_t *pkg = i->data;
+ for(j = alpm_pkg_get_depends(pkg); j; j = j->next) {
+ pmdepend_t *depend = alpm_splitdep(j->data);
+ if(depend == NULL) {
continue;
}
- for(k = provides; k; k = k->next) {
- pmpkg_t *provpkg = k->data;
- if(can_remove_package(db, provpkg, newtargs)) {
- pmpkg_t *pkg = _alpm_pkg_dup(provpkg);
-
- _alpm_log(PM_LOG_DEBUG, _("adding '%s' to the targets"), alpm_pkg_get_name(pkg));
+ for(k = _alpm_db_get_pkgcache(db); k; k = k->next) {
+ pmpkg_t *deppkg = k->data;
+ if(alpm_depcmp(deppkg,depend)
+ && can_remove_package(db, deppkg, *targs, include_explicit)) {
+ _alpm_log(PM_LOG_DEBUG, "adding '%s' to the targets\n",
+ alpm_pkg_get_name(deppkg));
/* add it to the target list */
- newtargs = alpm_list_add(newtargs, pkg);
- newtargs = _alpm_removedeps(db, newtargs);
+ *targs = alpm_list_add(*targs, _alpm_pkg_dup(deppkg));
+ ready = 0;
}
}
- alpm_list_free(provides);
- } else if(can_remove_package(db, deppkg, newtargs)) {
- pmpkg_t *pkg = _alpm_pkg_dup(deppkg);
-
- _alpm_log(PM_LOG_DEBUG, _("adding '%s' to the targets"), alpm_pkg_get_name(pkg));
-
- /* add it to the target list */
- newtargs = alpm_list_add(newtargs, pkg);
- newtargs = _alpm_removedeps(db, newtargs);
+ FREE(depend);
}
- free(depend);
}
}
-
- return(newtargs);
}
/* populates *list with packages that need to be installed to satisfy all
* dependencies (recursive) for syncpkg
*
- * make sure *list and *trail are already initialized
+ * make sure **list is already initialized
*/
int _alpm_resolvedeps(pmdb_t *local, alpm_list_t *dbs_sync, pmpkg_t *syncpkg,
- alpm_list_t *list, alpm_list_t *trail, pmtrans_t *trans,
- alpm_list_t **data)
+ alpm_list_t **list, pmtrans_t *trans, alpm_list_t **data)
{
- alpm_list_t *i, *j;
+ alpm_list_t *i, *j, *k;
alpm_list_t *targ;
alpm_list_t *deps = NULL;
ALPM_LOG_FUNC;
- if(local == NULL || dbs_sync == NULL || syncpkg == NULL) {
+ if(local == NULL || dbs_sync == NULL || syncpkg == NULL || list == NULL) {
return(-1);
}
- _alpm_log(PM_LOG_DEBUG, _("started resolving dependencies"));
+ _alpm_log(PM_LOG_DEBUG, "started resolving dependencies\n");
targ = alpm_list_add(NULL, syncpkg);
deps = _alpm_checkdeps(local, PM_TRANS_TYPE_ADD, targ);
alpm_list_free(targ);
@@ -605,14 +675,15 @@ int _alpm_resolvedeps(pmdb_t *local, alpm_list_t *dbs_sync, pmpkg_t *syncpkg,
for(i = deps; i; i = i->next) {
int found = 0;
pmdepmissing_t *miss = i->data;
+ pmdepend_t *missdep = &(miss->depend);
pmpkg_t *sync = NULL;
- /* check if one of the packages in *list already provides this dependency */
- for(j = list; j && !found; j = j->next) {
+ /* check if one of the packages in *list already satisfies this dependency */
+ for(j = *list; j && !found; j = j->next) {
pmpkg_t *sp = j->data;
- if(alpm_list_find_str(alpm_pkg_get_provides(sp), miss->depend.name)) {
- _alpm_log(PM_LOG_DEBUG, _("%s provides dependency %s -- skipping"),
- alpm_pkg_get_name(sp), miss->depend.name);
+ if(alpm_depcmp(sp, missdep)) {
+ _alpm_log(PM_LOG_DEBUG, "%s satisfies dependency %s -- skipping\n",
+ alpm_pkg_get_name(sp), missdep->name);
found = 1;
}
}
@@ -622,29 +693,27 @@ int _alpm_resolvedeps(pmdb_t *local, alpm_list_t *dbs_sync, pmpkg_t *syncpkg,
/* find the package in one of the repositories */
/* check literals */
- for(j = dbs_sync; !sync && j; j = j->next) {
- sync = _alpm_db_get_pkgfromcache(j->data, miss->depend.name);
+ for(j = dbs_sync; j && !found; j = j->next) {
+ if((sync = _alpm_db_get_pkgfromcache(j->data, missdep->name))) {
+ found = alpm_depcmp(sync, missdep);
+ }
}
- /*TODO this autoresolves the first 'provides' package... we should fix this
+ /*TODO this autoresolves the first 'satisfier' package... we should fix this
* somehow */
/* check provides */
- if(!sync) {
- for(j = dbs_sync; !sync && j; j = j->next) {
- alpm_list_t *provides;
- provides = _alpm_db_whatprovides(j->data, miss->depend.name);
- if(provides) {
- sync = provides->data;
- }
- alpm_list_free(provides);
+ for(j = dbs_sync; j && !found; j = j->next) {
+ for(k = _alpm_db_get_pkgcache(j->data); k && !found; k = k->next) {
+ sync = k->data;
+ found = alpm_depcmp(sync, missdep);
}
}
- if(!sync) {
- _alpm_log(PM_LOG_ERROR, _("cannot resolve dependencies for \"%s\" (\"%s\" is not in the package set)"),
- miss->target, miss->depend.name);
+ if(!found) {
+ _alpm_log(PM_LOG_ERROR, _("cannot resolve dependencies for \"%s\" (\"%s\" is not in the package set)\n"),
+ miss->target, missdep->name);
if(data) {
if((miss = malloc(sizeof(pmdepmissing_t))) == NULL) {
- _alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes"), sizeof(pmdepmissing_t));
+ _alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes\n"), sizeof(pmdepmissing_t));
FREELIST(*data);
pm_errno = PM_ERR_MEMORY;
goto error;
@@ -655,53 +724,40 @@ int _alpm_resolvedeps(pmdb_t *local, alpm_list_t *dbs_sync, pmpkg_t *syncpkg,
pm_errno = PM_ERR_UNSATISFIED_DEPS;
goto error;
}
- if(_alpm_pkg_find(alpm_pkg_get_name(sync), list)) {
- /* this dep is already in the target list */
- _alpm_log(PM_LOG_DEBUG, _("dependency %s is already in the target list -- skipping"),
- alpm_pkg_get_name(sync));
- continue;
+ /* check pmo_ignorepkg and pmo_s_ignore to make sure we haven't pulled in
+ * something we're not supposed to.
+ */
+ int usedep = 1;
+ if(alpm_list_find_str(handle->ignorepkg, alpm_pkg_get_name(sync))) {
+ pmpkg_t *dummypkg = _alpm_pkg_new(miss->target, NULL);
+ QUESTION(trans, PM_TRANS_CONV_INSTALL_IGNOREPKG, dummypkg, sync, NULL, &usedep);
+ _alpm_pkg_free(dummypkg);
}
-
- if(!_alpm_pkg_find(alpm_pkg_get_name(sync), trail)) {
- /* check pmo_ignorepkg and pmo_s_ignore to make sure we haven't pulled in
- * something we're not supposed to.
- */
- int usedep = 1;
- if(alpm_list_find_str(handle->ignorepkg, alpm_pkg_get_name(sync))) {
- pmpkg_t *dummypkg = _alpm_pkg_new(miss->target, NULL);
- QUESTION(trans, PM_TRANS_CONV_INSTALL_IGNOREPKG, dummypkg, sync, NULL, &usedep);
- _alpm_pkg_free(dummypkg);
+ if(usedep) {
+ _alpm_log(PM_LOG_DEBUG, "pulling dependency %s (needed by %s)\n",
+ alpm_pkg_get_name(sync), alpm_pkg_get_name(syncpkg));
+ *list = alpm_list_add(*list, sync);
+ if(_alpm_resolvedeps(local, dbs_sync, sync, list, trans, data)) {
+ goto error;
}
- if(usedep) {
- trail = alpm_list_add(trail, sync);
- if(_alpm_resolvedeps(local, dbs_sync, sync, list, trail, trans, data)) {
+ } else {
+ _alpm_log(PM_LOG_ERROR, _("cannot resolve dependencies for \"%s\"\n"), miss->target);
+ if(data) {
+ if((miss = malloc(sizeof(pmdepmissing_t))) == NULL) {
+ _alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes\n"), sizeof(pmdepmissing_t));
+ FREELIST(*data);
+ pm_errno = PM_ERR_MEMORY;
goto error;
}
- _alpm_log(PM_LOG_DEBUG, _("pulling dependency %s (needed by %s)"),
- alpm_pkg_get_name(sync), alpm_pkg_get_name(syncpkg));
- list = alpm_list_add(list, sync);
- } else {
- _alpm_log(PM_LOG_ERROR, _("cannot resolve dependencies for \"%s\""), miss->target);
- if(data) {
- if((miss = malloc(sizeof(pmdepmissing_t))) == NULL) {
- _alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes"), sizeof(pmdepmissing_t));
- FREELIST(*data);
- pm_errno = PM_ERR_MEMORY;
- goto error;
- }
- *miss = *(pmdepmissing_t *)i->data;
- *data = alpm_list_add(*data, miss);
- }
- pm_errno = PM_ERR_UNSATISFIED_DEPS;
- goto error;
+ *miss = *(pmdepmissing_t *)i->data;
+ *data = alpm_list_add(*data, miss);
}
- } else {
- /* cycle detected -- skip it */
- _alpm_log(PM_LOG_DEBUG, _("dependency cycle detected: %s"), sync->name);
+ pm_errno = PM_ERR_UNSATISFIED_DEPS;
+ goto error;
}
}
- _alpm_log(PM_LOG_DEBUG, _("finished resolving dependencies"));
+ _alpm_log(PM_LOG_DEBUG, "finished resolving dependencies\n");
FREELIST(deps);
@@ -712,7 +768,7 @@ error:
return(-1);
}
-const char SYMEXPORT *alpm_dep_get_target(pmdepmissing_t *miss)
+const char SYMEXPORT *alpm_miss_get_target(pmdepmissing_t *miss)
{
ALPM_LOG_FUNC;
@@ -723,7 +779,7 @@ const char SYMEXPORT *alpm_dep_get_target(pmdepmissing_t *miss)
return miss->target;
}
-pmdeptype_t SYMEXPORT alpm_dep_get_type(pmdepmissing_t *miss)
+pmdeptype_t SYMEXPORT alpm_miss_get_type(pmdepmissing_t *miss)
{
ALPM_LOG_FUNC;
@@ -734,36 +790,48 @@ pmdeptype_t SYMEXPORT alpm_dep_get_type(pmdepmissing_t *miss)
return miss->type;
}
-pmdepmod_t SYMEXPORT alpm_dep_get_mod(pmdepmissing_t *miss)
+pmdepend_t SYMEXPORT *alpm_miss_get_dep(pmdepmissing_t *miss)
+{
+ ALPM_LOG_FUNC;
+
+ /* Sanity checks */
+ ASSERT(handle != NULL, return(NULL));
+ ASSERT(miss != NULL, return(NULL));
+
+ return &miss->depend;
+}
+
+pmdepmod_t SYMEXPORT alpm_dep_get_mod(pmdepend_t *dep)
{
ALPM_LOG_FUNC;
/* Sanity checks */
ASSERT(handle != NULL, return(-1));
- ASSERT(miss != NULL, return(-1));
+ ASSERT(dep != NULL, return(-1));
- return miss->depend.mod;
+ return dep->mod;
}
-const char SYMEXPORT *alpm_dep_get_name(pmdepmissing_t *miss)
+const char SYMEXPORT *alpm_dep_get_name(pmdepend_t *dep)
{
ALPM_LOG_FUNC;
/* Sanity checks */
ASSERT(handle != NULL, return(NULL));
- ASSERT(miss != NULL, return(NULL));
+ ASSERT(dep != NULL, return(NULL));
- return miss->depend.name;
+ return dep->name;
}
-const char SYMEXPORT *alpm_dep_get_version(pmdepmissing_t *miss)
+const char SYMEXPORT *alpm_dep_get_version(pmdepend_t *dep)
{
ALPM_LOG_FUNC;
/* Sanity checks */
ASSERT(handle != NULL, return(NULL));
- ASSERT(miss != NULL, return(NULL));
+ ASSERT(dep != NULL, return(NULL));
- return miss->depend.version;
+ return dep->version;
}
+
/* vim: set ts=2 sw=2 noet: */