Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
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.c82
1 files changed, 51 insertions, 31 deletions
diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c
index 0c0a054e..2a06bb04 100644
--- a/lib/libalpm/deps.c
+++ b/lib/libalpm/deps.c
@@ -1,7 +1,7 @@
/*
* deps.c
*
- * Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>
+ * Copyright (c) 2006-2012 Pacman Development Team <pacman-dev@archlinux.org>
* Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
* Copyright (c) 2005 by Aurelien Foret <orelien@chez.com>
* Copyright (c) 2005, 2006 by Miklos Vajna <vmiklos@frugalware.org>
@@ -20,8 +20,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "config.h"
-
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -41,6 +39,7 @@ void _alpm_dep_free(alpm_depend_t *dep)
{
FREE(dep->name);
FREE(dep->version);
+ FREE(dep->desc);
FREE(dep);
}
@@ -159,15 +158,17 @@ alpm_list_t *_alpm_sortbydeps(alpm_handle_t *handle,
else if(nextchild->state == -1) {
alpm_pkg_t *vertexpkg = vertex->data;
alpm_pkg_t *childpkg = nextchild->data;
- const char *message;
_alpm_log(handle, ALPM_LOG_WARNING, _("dependency cycle detected:\n"));
if(reverse) {
- message =_("%s will be removed after its %s dependency\n");
+ _alpm_log(handle, ALPM_LOG_WARNING,
+ _("%s will be removed after its %s dependency\n"),
+ vertexpkg->name, childpkg->name);
} else {
- message =_("%s will be installed before its %s dependency\n");
+ _alpm_log(handle, ALPM_LOG_WARNING,
+ _("%s will be installed before its %s dependency\n"),
+ vertexpkg->name, childpkg->name);
}
- _alpm_log(handle, ALPM_LOG_WARNING, message, vertexpkg->name, childpkg->name);
}
}
if(!found) {
@@ -204,8 +205,10 @@ alpm_list_t *_alpm_sortbydeps(alpm_handle_t *handle,
static int no_dep_version(alpm_handle_t *handle)
{
- int flags = alpm_trans_get_flags(handle);
- return flags != -1 && (flags & ALPM_TRANS_FLAG_NODEPVERSION);
+ if(!handle->trans) {
+ return 0;
+ }
+ return (handle->trans->flags & ALPM_TRANS_FLAG_NODEPVERSION);
}
static alpm_depend_t *filtered_depend(alpm_depend_t *dep, int nodepversion)
@@ -266,7 +269,7 @@ alpm_pkg_t SYMEXPORT *alpm_find_satisfier(alpm_list_t *pkgs, const char *depstri
* @return an alpm_list_t* of alpm_depmissing_t pointers.
*/
alpm_list_t SYMEXPORT *alpm_checkdeps(alpm_handle_t *handle,
- alpm_list_t *pkglist, alpm_list_t *remove, alpm_list_t *upgrade,
+ alpm_list_t *pkglist, alpm_list_t *rem, alpm_list_t *upgrade,
int reversedeps)
{
alpm_list_t *i, *j;
@@ -278,7 +281,7 @@ alpm_list_t SYMEXPORT *alpm_checkdeps(alpm_handle_t *handle,
for(i = pkglist; i; i = i->next) {
alpm_pkg_t *pkg = i->data;
- if(_alpm_pkg_find(remove, pkg->name) || _alpm_pkg_find(upgrade, pkg->name)) {
+ if(_alpm_pkg_find(rem, pkg->name) || _alpm_pkg_find(upgrade, pkg->name)) {
modified = alpm_list_add(modified, pkg);
} else {
dblist = alpm_list_add(dblist, pkg);
@@ -395,7 +398,7 @@ int _alpm_depcmp(alpm_pkg_t *pkg, alpm_depend_t *dep)
/* any version will satisfy the requirement */
satisfy = (provision->name_hash == dep->name_hash
&& strcmp(provision->name, dep->name) == 0);
- } else if (provision->mod == ALPM_DEP_MOD_EQ) {
+ } else if(provision->mod == ALPM_DEP_MOD_EQ) {
/* provision specifies a version, so try it out */
satisfy = (provision->name_hash == dep->name_hash
&& strcmp(provision->name, dep->name) == 0
@@ -409,7 +412,7 @@ int _alpm_depcmp(alpm_pkg_t *pkg, alpm_depend_t *dep)
alpm_depend_t *_alpm_splitdep(const char *depstring)
{
alpm_depend_t *depend;
- const char *ptr, *version;
+ const char *ptr, *version, *desc;
size_t deplen;
if(depstring == NULL) {
@@ -417,7 +420,17 @@ alpm_depend_t *_alpm_splitdep(const char *depstring)
}
MALLOC(depend, sizeof(alpm_depend_t), return NULL);
- deplen = strlen(depstring);
+
+ /* Note the extra space in ": " to avoid matching the epoch */
+ if((desc = strstr(depstring, ": ")) != NULL) {
+ STRDUP(depend->desc, desc + 2, return NULL);
+ deplen = desc - depstring;
+ } else {
+ /* no description- point desc at NULL at end of string for later use */
+ depend->desc = NULL;
+ deplen = strlen(depstring);
+ desc = depstring + deplen;
+ }
/* Find a version comparator if one exists. If it does, set the type and
* increment the ptr accordingly so we can copy the right strings. */
@@ -442,21 +455,18 @@ alpm_depend_t *_alpm_splitdep(const char *depstring)
depend->mod = ALPM_DEP_MOD_EQ;
version = ptr + 1;
} else {
- /* no version specified, leave ptr NULL and set version to NULL */
+ /* no version specified, set ptr to end of string and version to NULL */
+ ptr = depstring + deplen;
depend->mod = ALPM_DEP_MOD_ANY;
depend->version = NULL;
version = NULL;
}
/* copy the right parts to the right places */
- if(ptr) {
- STRNDUP(depend->name, depstring, ptr - depstring, return NULL);
- } else {
- STRDUP(depend->name, depstring, return NULL);
- }
+ STRNDUP(depend->name, depstring, ptr - depstring, return NULL);
depend->name_hash = _alpm_hash_sdbm(depend->name);
if(version) {
- STRDUP(depend->version, version, return NULL);
+ STRNDUP(depend->version, version, desc - version, return NULL);
}
return depend;
@@ -468,8 +478,9 @@ alpm_depend_t *_alpm_dep_dup(const alpm_depend_t *dep)
CALLOC(newdep, 1, sizeof(alpm_depend_t), return NULL);
STRDUP(newdep->name, dep->name, return NULL);
- newdep->name_hash = dep->name_hash;
STRDUP(newdep->version, dep->version, return NULL);
+ STRDUP(newdep->desc, dep->desc, return NULL);
+ newdep->name_hash = dep->name_hash;
newdep->mod = dep->mod;
return newdep;
@@ -639,14 +650,14 @@ static alpm_pkg_t *resolvedep(alpm_handle_t *handle, alpm_depend_t *dep,
count = alpm_list_count(providers);
if(count >= 1) {
/* default to first provider if there is no QUESTION callback */
- int index = 0;
+ int idx = 0;
if(count > 1) {
/* if there is more than one provider, we ask the user */
QUESTION(handle, ALPM_QUESTION_SELECT_PROVIDER,
- providers, dep, NULL, &index);
+ providers, dep, NULL, &idx);
}
- if(index >= 0 && index < count) {
- alpm_list_t *nth = alpm_list_nth(providers, index);
+ if(idx >= 0 && idx < count) {
+ alpm_list_t *nth = alpm_list_nth(providers, idx);
alpm_pkg_t *pkg = nth->data;
alpm_list_free(providers);
return pkg;
@@ -711,7 +722,7 @@ alpm_pkg_t SYMEXPORT *alpm_find_dbs_satisfier(alpm_handle_t *handle,
*/
int _alpm_resolvedeps(alpm_handle_t *handle, alpm_list_t *localpkgs,
alpm_pkg_t *pkg, alpm_list_t *preferred, alpm_list_t **packages,
- alpm_list_t *remove, alpm_list_t **data)
+ alpm_list_t *rem, alpm_list_t **data)
{
int ret = 0;
alpm_list_t *i, *j;
@@ -734,7 +745,7 @@ int _alpm_resolvedeps(alpm_handle_t *handle, alpm_list_t *localpkgs,
for(i = alpm_list_last(*packages); i; i = i->next) {
alpm_pkg_t *tpkg = i->data;
targ = alpm_list_add(NULL, tpkg);
- deps = alpm_checkdeps(handle, localpkgs, remove, targ, 0);
+ deps = alpm_checkdeps(handle, localpkgs, rem, targ, 0);
alpm_list_free(targ);
for(j = deps; j; j = j->next) {
@@ -792,7 +803,7 @@ int _alpm_resolvedeps(alpm_handle_t *handle, alpm_list_t *localpkgs,
*/
char SYMEXPORT *alpm_dep_compute_string(const alpm_depend_t *dep)
{
- const char *name, *opr, *ver;
+ const char *name, *opr, *ver, *desc_delim, *desc;
char *str;
size_t len;
@@ -834,12 +845,21 @@ char SYMEXPORT *alpm_dep_compute_string(const alpm_depend_t *dep)
ver = "";
}
+ if(dep->desc) {
+ desc_delim = ": ";
+ desc = dep->desc;
+ } else {
+ desc_delim = "";
+ desc = "";
+ }
+
/* we can always compute len and print the string like this because opr
* and ver will be empty when ALPM_DEP_MOD_ANY is the depend type. the
* reassignments above also ensure we do not do a strlen(NULL). */
- len = strlen(name) + strlen(opr) + strlen(ver) + 1;
+ len = strlen(name) + strlen(opr) + strlen(ver)
+ + strlen(desc_delim) + strlen(desc) + 1;
MALLOC(str, len, return NULL);
- snprintf(str, len, "%s%s%s", name, opr, ver);
+ snprintf(str, len, "%s%s%s%s%s", name, opr, ver, desc_delim, desc);
return str;
}