#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "util.h"
#include "log.h"
#include "error.h"
#include "list.h"
#include "package.h"
#include "db.h"
#include "cache.h"
#include "provide.h"
#include "deps.h"
#include "versioncmp.h"
#include "handle.h"
extern pmhandle_t *handle;
static pmdepmissing_t *depmissing_new(const char *target, unsigned char type, unsigned char depmod,
const char *depname, const char *depversion)
{
pmdepmissing_t *miss;
miss = (pmdepmissing_t *)malloc(sizeof(pmdepmissing_t));
if(miss == NULL) {
return(NULL);
}
STRNCPY(miss->target, target, PKG_NAME_LEN);
miss->type = type;
miss->depend.mod = depmod;
STRNCPY(miss->depend.name, depname, PKG_NAME_LEN);
STRNCPY(miss->depend.version, depversion, PKG_VERSION_LEN);
return(miss);
}
PMList *sortbydeps(PMList *targets, int mode)
{
PMList *newtargs = NULL;
PMList *i, *j, *k;
int change = 1;
int numscans = 0;
int numtargs = 0;
if(targets == NULL) {
return(NULL);
}
for(i = targets; i; i = i->next) {
newtargs = pm_list_add(newtargs, i->data);
numtargs++;
}
while(change) {
PMList *tmptargs = NULL;
change = 0;
if(numscans > numtargs) {
_alpm_log(PM_LOG_WARNING, "possible dependency cycle detected");
continue;
}
numscans++;
for(i = newtargs; i; i = i->next) {
pmpkg_t *p = (pmpkg_t*)i->data;
for(j = p->depends; j; j = j->next) {
pmdepend_t dep;
pmpkg_t *q = NULL;
if(splitdep(j->data, &dep)) {
continue;
}
for(k = i->next; k; k = k->next) {
q = (pmpkg_t *)k->data;
if(!strcmp(dep.name, q->name)) {
if(!pkg_isin(q, tmptargs)) {
change = 1;
tmptargs = pm_list_add(tmptargs, q);
}
break;
}
}
}
if(!pkg_isin(p, tmptargs)) {
tmptargs = pm_list_add(tmptargs, p);
}
}
FREELISTPTR(newtargs);
newtargs = tmptargs;
}
if(mode == PM_TRANS_TYPE_REMOVE) {
PMList *tmptargs = _alpm_list_reverse(newtargs);
FREELISTPTR(newtargs);
newtargs = tmptargs;
}
return(newtargs);
}
PMList *checkdeps(pmdb_t *db, unsigned char op, PMList *packages)
{
pmdepend_t depend;
PMList *i, *j, *k;
int cmp;
int found = 0;
PMList *baddeps = NULL;
pmdepmissing_t *miss = NULL;
if(db == NULL) {
return(NULL);
}
if(op == PM_TRANS_TYPE_UPGRADE) {
for(i = packages; i; i = i->next) {
pmpkg_t *tp = i->data;
pmpkg_t *oldpkg;
if(tp == NULL) {
continue;
}
if((oldpkg = db_get_pkgfromcache(db, tp->name)) == NULL) {
continue;
}
for(j = oldpkg->requiredby; j; j = j->next) {
char *ver;
pmpkg_t *p;
found = 0;
|