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.c126
1 files changed, 53 insertions, 73 deletions
diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c
index 36d6e1aa..62e8702c 100644
--- a/lib/libalpm/deps.c
+++ b/lib/libalpm/deps.c
@@ -35,6 +35,10 @@
#include "package.h"
#include "db.h"
#include "handle.h"
+#include "trans.h"
+
+/* global handle variable */
+extern pmhandle_t *handle;
void _alpm_dep_free(pmdepend_t *dep)
{
@@ -48,15 +52,13 @@ static pmdepmissing_t *depmiss_new(const char *target, pmdepend_t *dep,
{
pmdepmissing_t *miss;
- ALPM_LOG_FUNC;
-
MALLOC(miss, sizeof(pmdepmissing_t), RET_ERR(PM_ERR_MEMORY, NULL));
STRDUP(miss->target, target, RET_ERR(PM_ERR_MEMORY, NULL));
miss->depend = _alpm_dep_dup(dep);
STRDUP(miss->causingpkg, causingpkg, RET_ERR(PM_ERR_MEMORY, NULL));
- return(miss);
+ return miss;
}
void _alpm_depmiss_free(pmdepmissing_t *miss)
@@ -73,10 +75,10 @@ static int _alpm_dep_edge(pmpkg_t *pkg1, pmpkg_t *pkg2)
alpm_list_t *i;
for(i = alpm_pkg_get_depends(pkg1); i; i = i->next) {
if(_alpm_depcmp(pkg2, i->data)) {
- return(1);
+ return 1;
}
}
- return(0);
+ return 0;
}
/* Convert a list of pmpkg_t * to a graph structure,
@@ -110,7 +112,7 @@ static alpm_list_t *dep_graph_init(alpm_list_t *targets)
}
vertex_i->childptr = vertex_i->children;
}
- return(vertices);
+ return vertices;
}
/* Re-order a list of target packages with respect to their dependencies.
@@ -134,10 +136,8 @@ alpm_list_t *_alpm_sortbydeps(alpm_list_t *targets, int reverse)
alpm_list_t *vptr;
pmgraph_t *vertex;
- ALPM_LOG_FUNC;
-
if(targets == NULL) {
- return(NULL);
+ return NULL;
}
_alpm_log(PM_LOG_DEBUG, "started sorting dependencies\n");
@@ -153,7 +153,7 @@ alpm_list_t *_alpm_sortbydeps(alpm_list_t *targets, int reverse)
while(vertex->childptr && !found) {
pmgraph_t *nextchild = vertex->childptr->data;
vertex->childptr = vertex->childptr->next;
- if (nextchild->state == 0) {
+ if(nextchild->state == 0) {
found = 1;
nextchild->parent = vertex;
vertex = nextchild;
@@ -181,7 +181,7 @@ alpm_list_t *_alpm_sortbydeps(alpm_list_t *targets, int reverse)
vptr = vptr->next;
while(vptr) {
vertex = vptr->data;
- if (vertex->state == 0) break;
+ if(vertex->state == 0) break;
vptr = vptr->next;
}
}
@@ -201,7 +201,7 @@ alpm_list_t *_alpm_sortbydeps(alpm_list_t *targets, int reverse)
alpm_list_free_inner(vertices, _alpm_graph_free);
alpm_list_free(vertices);
- return(newtargs);
+ return newtargs;
}
static int no_dep_version(void)
@@ -214,7 +214,7 @@ static pmdepend_t *filtered_depend(pmdepend_t *dep, int nodepversion)
{
if(nodepversion) {
pmdepend_t *newdep = _alpm_dep_dup(dep);
- ASSERT(newdep, return(dep));
+ ASSERT(newdep, return dep);
newdep->mod = PM_DEP_MOD_ANY;
dep = newdep;
}
@@ -235,10 +235,10 @@ static pmpkg_t *find_dep_satisfier(alpm_list_t *pkgs, pmdepend_t *dep)
for(i = pkgs; i; i = alpm_list_next(i)) {
pmpkg_t *pkg = i->data;
if(_alpm_depcmp(pkg, dep)) {
- return(pkg);
+ return pkg;
}
}
- return(NULL);
+ return NULL;
}
/** Find a package satisfying a specified dependency.
@@ -252,7 +252,7 @@ pmpkg_t SYMEXPORT *alpm_find_satisfier(alpm_list_t *pkgs, const char *depstring)
pmdepend_t *dep = _alpm_splitdep(depstring);
pmpkg_t *pkg = find_dep_satisfier(pkgs, dep);
_alpm_dep_free(dep);
- return(pkg);
+ return pkg;
}
/** Checks dependencies and returns missing ones in a list.
@@ -271,8 +271,6 @@ alpm_list_t SYMEXPORT *alpm_checkdeps(alpm_list_t *pkglist, int reversedeps,
alpm_list_t *baddeps = NULL;
int nodepversion;
- ALPM_LOG_FUNC;
-
targets = alpm_list_join(alpm_list_copy(remove), alpm_list_copy(upgrade));
for(i = pkglist; i; i = i->next) {
pmpkg_t *pkg = i->data;
@@ -343,7 +341,7 @@ alpm_list_t SYMEXPORT *alpm_checkdeps(alpm_list_t *pkglist, int reversedeps,
alpm_list_free(modified);
alpm_list_free(dblist);
- return(baddeps);
+ return baddeps;
}
static int dep_vercmp(const char *version1, pmdepmod_t mod,
@@ -364,7 +362,7 @@ static int dep_vercmp(const char *version1, pmdepmod_t mod,
default: equal = 1; break;
}
}
- return(equal);
+ return equal;
}
int _alpm_depcmp(pmpkg_t *pkg, pmdepend_t *dep)
@@ -380,7 +378,7 @@ int _alpm_depcmp(pmpkg_t *pkg, pmdepend_t *dep)
satisfy = (strcmp(pkg->name, dep->name) == 0
&& dep_vercmp(pkg->version, dep->mod, dep->version));
if(satisfy) {
- return(satisfy);
+ return satisfy;
}
}
@@ -406,7 +404,7 @@ int _alpm_depcmp(pmpkg_t *pkg, pmdepend_t *dep)
}
}
- return(satisfy);
+ return satisfy;
}
pmdepend_t *_alpm_splitdep(const char *depstring)
@@ -415,7 +413,7 @@ pmdepend_t *_alpm_splitdep(const char *depstring)
const char *ptr, *version = NULL;
if(depstring == NULL) {
- return(NULL);
+ return NULL;
}
CALLOC(depend, 1, sizeof(pmdepend_t), RET_ERR(PM_ERR_MEMORY, NULL));
@@ -451,7 +449,7 @@ pmdepend_t *_alpm_splitdep(const char *depstring)
STRDUP(depend->version, version, RET_ERR(PM_ERR_MEMORY, NULL));
}
- return(depend);
+ return depend;
}
pmdepend_t *_alpm_dep_dup(const pmdepend_t *dep)
@@ -464,7 +462,7 @@ pmdepend_t *_alpm_dep_dup(const pmdepend_t *dep)
STRDUP(newdep->version, dep->version, RET_ERR(PM_ERR_MEMORY, NULL));
newdep->mod = dep->mod;
- return(newdep);
+ return newdep;
}
/* These parameters are messy. We check if this package, given a list of
@@ -477,7 +475,7 @@ static int can_remove_package(pmdb_t *db, pmpkg_t *pkg, alpm_list_t *targets,
alpm_list_t *i;
if(_alpm_pkg_find(targets, alpm_pkg_get_name(pkg))) {
- return(0);
+ return 0;
}
if(!include_explicit) {
@@ -485,7 +483,7 @@ static int can_remove_package(pmdb_t *db, pmpkg_t *pkg, alpm_list_t *targets,
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);
+ return 0;
}
}
@@ -499,12 +497,12 @@ static int can_remove_package(pmdb_t *db, pmpkg_t *pkg, alpm_list_t *targets,
for(i = _alpm_db_get_pkgcache(db); i; i = i->next) {
pmpkg_t *lpkg = i->data;
if(_alpm_dep_edge(lpkg, pkg) && !_alpm_pkg_find(targets, lpkg->name)) {
- return(0);
+ return 0;
}
}
/* it's ok to remove */
- return(1);
+ return 1;
}
/**
@@ -521,8 +519,6 @@ void _alpm_recursedeps(pmdb_t *db, alpm_list_t *targs, int include_explicit)
{
alpm_list_t *i, *j;
- ALPM_LOG_FUNC;
-
if(db == NULL || targs == NULL) {
return;
}
@@ -569,7 +565,7 @@ static pmpkg_t *resolvedep(pmdepend_t *dep, alpm_list_t *dbs,
if(pkg && _alpm_depcmp(pkg, dep) && !_alpm_pkg_find(excluding, pkg->name)) {
if(_alpm_pkg_should_ignore(pkg)) {
int install = 0;
- if (prompt) {
+ if(prompt) {
QUESTION(handle->trans, PM_TRANS_CONV_INSTALL_IGNOREPKG, pkg,
NULL, NULL, &install);
} else {
@@ -580,7 +576,7 @@ static pmpkg_t *resolvedep(pmdepend_t *dep, alpm_list_t *dbs,
continue;
}
}
- return(pkg);
+ return pkg;
}
}
/* 2. satisfiers (skip literals here) */
@@ -591,7 +587,7 @@ static pmpkg_t *resolvedep(pmdepend_t *dep, alpm_list_t *dbs,
!_alpm_pkg_find(excluding, pkg->name)) {
if(_alpm_pkg_should_ignore(pkg)) {
int install = 0;
- if (prompt) {
+ if(prompt) {
QUESTION(handle->trans, PM_TRANS_CONV_INSTALL_IGNOREPKG,
pkg, NULL, NULL, &install);
} else {
@@ -613,13 +609,13 @@ static pmpkg_t *resolvedep(pmdepend_t *dep, alpm_list_t *dbs,
/* first check if one provider is already installed locally */
for(i = providers; i; i = i->next) {
pmpkg_t *pkg = i->data;
- if (_alpm_pkghash_find(_alpm_db_get_pkgcache_hash(handle->db_local), pkg->name)) {
+ if(_alpm_pkghash_find(_alpm_db_get_pkgcache_hash(handle->db_local), pkg->name)) {
alpm_list_free(providers);
- return(pkg);
+ return pkg;
}
}
count = alpm_list_count(providers);
- if (count >= 1) {
+ if(count >= 1) {
/* default to first provider if there is no QUESTION callback */
int index = 0;
if(count > 1) {
@@ -630,7 +626,7 @@ static pmpkg_t *resolvedep(pmdepend_t *dep, alpm_list_t *dbs,
if(index >= 0 && index < count) {
pmpkg_t *pkg = alpm_list_getdata(alpm_list_nth(providers, index));
alpm_list_free(providers);
- return(pkg);
+ return pkg;
}
alpm_list_free(providers);
providers = NULL;
@@ -641,7 +637,7 @@ static pmpkg_t *resolvedep(pmdepend_t *dep, alpm_list_t *dbs,
} else {
pm_errno = PM_ERR_PKG_NOT_FOUND;
}
- return(NULL);
+ return NULL;
}
/** Find a package satisfying a specified dependency.
@@ -657,13 +653,13 @@ pmpkg_t SYMEXPORT *alpm_find_dbs_satisfier(alpm_list_t *dbs, const char *depstri
pmdepend_t *dep;
pmpkg_t *pkg;
- ASSERT(dbs, return(NULL));
+ ASSERT(dbs, return NULL);
dep = _alpm_splitdep(depstring);
- ASSERT(dep, return(NULL));
+ ASSERT(dep, return NULL);
pkg = resolvedep(dep, dbs, NULL, 1);
_alpm_dep_free(dep);
- return(pkg);
+ return pkg;
}
/**
@@ -696,10 +692,8 @@ int _alpm_resolvedeps(alpm_list_t *localpkgs, alpm_list_t *dbs_sync, pmpkg_t *pk
alpm_list_t *deps = NULL;
alpm_list_t *packages_copy;
- ALPM_LOG_FUNC;
-
if(_alpm_pkg_find(*packages, pkg->name) != NULL) {
- return(0);
+ return 0;
}
/* Create a copy of the packages list, so that it can be restored
@@ -760,67 +754,55 @@ int _alpm_resolvedeps(alpm_list_t *localpkgs, alpm_list_t *dbs_sync, pmpkg_t *pk
alpm_list_free(packages_copy);
}
_alpm_log(PM_LOG_DEBUG, "finished resolving dependencies\n");
- return(ret);
+ return ret;
}
const char SYMEXPORT *alpm_miss_get_target(const pmdepmissing_t *miss)
{
- ALPM_LOG_FUNC;
-
/* Sanity checks */
- ASSERT(miss != NULL, return(NULL));
+ ASSERT(miss != NULL, return NULL);
- return(miss->target);
+ return miss->target;
}
const char SYMEXPORT *alpm_miss_get_causingpkg(const pmdepmissing_t *miss)
{
- ALPM_LOG_FUNC;
-
/* Sanity checks */
- ASSERT(miss != NULL, return(NULL));
+ ASSERT(miss != NULL, return NULL);
return miss->causingpkg;
}
pmdepend_t SYMEXPORT *alpm_miss_get_dep(pmdepmissing_t *miss)
{
- ALPM_LOG_FUNC;
-
/* Sanity checks */
- ASSERT(miss != NULL, return(NULL));
+ ASSERT(miss != NULL, return NULL);
- return(miss->depend);
+ return miss->depend;
}
pmdepmod_t SYMEXPORT alpm_dep_get_mod(const pmdepend_t *dep)
{
- ALPM_LOG_FUNC;
-
/* Sanity checks */
- ASSERT(dep != NULL, return(-1));
+ ASSERT(dep != NULL, return -1);
- return(dep->mod);
+ return dep->mod;
}
const char SYMEXPORT *alpm_dep_get_name(const pmdepend_t *dep)
{
- ALPM_LOG_FUNC;
-
/* Sanity checks */
- ASSERT(dep != NULL, return(NULL));
+ ASSERT(dep != NULL, return NULL);
- return(dep->name);
+ return dep->name;
}
const char SYMEXPORT *alpm_dep_get_version(const pmdepend_t *dep)
{
- ALPM_LOG_FUNC;
-
/* Sanity checks */
- ASSERT(dep != NULL, return(NULL));
+ ASSERT(dep != NULL, return NULL);
- return(dep->version);
+ return dep->version;
}
/** Reverse of splitdep; make a dep string from a pmdepend_t struct.
@@ -834,10 +816,8 @@ char SYMEXPORT *alpm_dep_compute_string(const pmdepend_t *dep)
char *str;
size_t len;
- ALPM_LOG_FUNC;
-
/* Sanity checks */
- ASSERT(dep != NULL, return(NULL));
+ ASSERT(dep != NULL, return NULL);
if(dep->name) {
name = dep->name;
@@ -882,6 +862,6 @@ char SYMEXPORT *alpm_dep_compute_string(const pmdepend_t *dep)
MALLOC(str, len, RET_ERR(PM_ERR_MEMORY, NULL));
snprintf(str, len, "%s%s%s", name, opr, ver);
- return(str);
+ return str;
}
/* vim: set ts=2 sw=2 noet: */