2005-03-14 20:51:43 -05:00
|
|
|
/*
|
|
|
|
* deps.c
|
|
|
|
*
|
2006-01-02 14:55:35 -05:00
|
|
|
* Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
|
2005-03-14 20:51:43 -05:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
|
|
|
* USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
/* pacman */
|
|
|
|
#include "util.h"
|
|
|
|
#include "log.h"
|
2005-03-30 17:32:43 -05:00
|
|
|
#include "error.h"
|
2005-03-14 20:51:43 -05:00
|
|
|
#include "list.h"
|
|
|
|
#include "package.h"
|
|
|
|
#include "db.h"
|
|
|
|
#include "cache.h"
|
|
|
|
#include "provide.h"
|
|
|
|
#include "deps.h"
|
2005-12-26 11:48:37 -05:00
|
|
|
#include "versioncmp.h"
|
2005-04-24 16:06:00 -04:00
|
|
|
#include "handle.h"
|
|
|
|
|
|
|
|
extern pmhandle_t *handle;
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2006-02-17 17:35:26 -05:00
|
|
|
pmdepmissing_t *_alpm_depmiss_new(const char *target, unsigned char type, unsigned char depmod,
|
2006-01-18 17:37:16 -05:00
|
|
|
const char *depname, const char *depversion)
|
2006-01-15 10:55:16 -05:00
|
|
|
{
|
|
|
|
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);
|
2006-01-18 17:37:16 -05:00
|
|
|
if(depversion) {
|
|
|
|
STRNCPY(miss->depend.version, depversion, PKG_VERSION_LEN);
|
|
|
|
} else {
|
|
|
|
miss->depend.version[0] = 0;
|
|
|
|
}
|
2006-01-15 10:55:16 -05:00
|
|
|
|
|
|
|
return(miss);
|
|
|
|
}
|
|
|
|
|
2006-02-17 17:35:26 -05:00
|
|
|
int _alpm_depmiss_isin(pmdepmissing_t *needle, PMList *haystack)
|
2006-01-18 17:37:16 -05:00
|
|
|
{
|
|
|
|
PMList *i;
|
|
|
|
|
|
|
|
for(i = haystack; i; i = i->next) {
|
|
|
|
pmdepmissing_t *miss = i->data;
|
|
|
|
if(!memcmp(needle, miss, sizeof(pmdepmissing_t))
|
|
|
|
&& !memcmp(&needle->depend, &miss->depend, sizeof(pmdepend_t))) {
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2005-03-14 20:51:43 -05:00
|
|
|
/* Re-order a list of target packages with respect to their dependencies.
|
|
|
|
*
|
2005-03-25 17:09:14 -05:00
|
|
|
* Example (PM_TRANS_TYPE_ADD):
|
2005-03-14 20:51:43 -05:00
|
|
|
* A depends on C
|
|
|
|
* B depends on A
|
|
|
|
* Target order is A,B,C,D
|
|
|
|
*
|
|
|
|
* Should be re-ordered to C,A,B,D
|
|
|
|
*
|
2005-03-25 17:09:14 -05:00
|
|
|
* mode should be either PM_TRANS_TYPE_ADD or PM_TRANS_TYPE_REMOVE. This
|
|
|
|
* affects the dependency order sortbydeps() will use.
|
|
|
|
*
|
2005-03-14 20:51:43 -05:00
|
|
|
* This function returns the new PMList* target list.
|
|
|
|
*
|
|
|
|
*/
|
2006-02-17 17:35:26 -05:00
|
|
|
PMList *_alpm_sortbydeps(PMList *targets, int mode)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
|
|
|
PMList *newtargs = NULL;
|
|
|
|
PMList *i, *j, *k;
|
|
|
|
int change = 1;
|
|
|
|
int numscans = 0;
|
|
|
|
int numtargs = 0;
|
|
|
|
|
|
|
|
if(targets == NULL) {
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
2005-05-04 15:30:00 -04:00
|
|
|
for(i = targets; i; i = i->next) {
|
2006-02-17 17:35:26 -05:00
|
|
|
newtargs = _alpm_list_add(newtargs, i->data);
|
2005-05-04 15:30:00 -04:00
|
|
|
numtargs++;
|
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
|
|
|
|
while(change) {
|
2005-05-04 15:30:00 -04:00
|
|
|
PMList *tmptargs = NULL;
|
2005-03-14 20:51:43 -05:00
|
|
|
change = 0;
|
|
|
|
if(numscans > numtargs) {
|
2005-03-28 03:21:17 -05:00
|
|
|
_alpm_log(PM_LOG_WARNING, "possible dependency cycle detected");
|
2005-03-14 20:51:43 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
numscans++;
|
|
|
|
/* run thru targets, moving up packages as necessary */
|
2005-05-04 15:30:00 -04:00
|
|
|
for(i = newtargs; i; i = i->next) {
|
2005-03-14 20:51:43 -05:00
|
|
|
pmpkg_t *p = (pmpkg_t*)i->data;
|
|
|
|
for(j = p->depends; j; j = j->next) {
|
|
|
|
pmdepend_t dep;
|
|
|
|
pmpkg_t *q = NULL;
|
2006-02-17 17:35:26 -05:00
|
|
|
if(_alpm_splitdep(j->data, &dep)) {
|
2005-05-04 15:30:00 -04:00
|
|
|
continue;
|
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
/* look for dep.name -- if it's farther down in the list, then
|
|
|
|
* move it up above p
|
|
|
|
*/
|
2005-05-04 15:30:00 -04:00
|
|
|
for(k = i->next; k; k = k->next) {
|
|
|
|
q = (pmpkg_t *)k->data;
|
2005-03-14 20:51:43 -05:00
|
|
|
if(!strcmp(dep.name, q->name)) {
|
2006-02-17 17:35:26 -05:00
|
|
|
if(!_alpm_pkg_isin(q->name, tmptargs)) {
|
2005-05-04 15:30:00 -04:00
|
|
|
change = 1;
|
2006-02-17 17:35:26 -05:00
|
|
|
tmptargs = _alpm_list_add(tmptargs, q);
|
2005-05-04 15:30:00 -04:00
|
|
|
}
|
|
|
|
break;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-02-17 17:35:26 -05:00
|
|
|
if(!_alpm_pkg_isin(p->name, tmptargs)) {
|
|
|
|
tmptargs = _alpm_list_add(tmptargs, p);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
2005-05-04 15:30:00 -04:00
|
|
|
FREELISTPTR(newtargs);
|
|
|
|
newtargs = tmptargs;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
2005-05-04 15:30:00 -04:00
|
|
|
|
2005-03-25 17:09:14 -05:00
|
|
|
if(mode == PM_TRANS_TYPE_REMOVE) {
|
|
|
|
/* we're removing packages, so reverse the order */
|
2005-05-04 15:30:00 -04:00
|
|
|
PMList *tmptargs = _alpm_list_reverse(newtargs);
|
2005-03-25 17:09:14 -05:00
|
|
|
/* free the old one */
|
2005-05-04 15:30:00 -04:00
|
|
|
FREELISTPTR(newtargs);
|
|
|
|
newtargs = tmptargs;
|
2005-03-25 17:09:14 -05:00
|
|
|
}
|
|
|
|
|
2005-05-04 15:30:00 -04:00
|
|
|
return(newtargs);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns a PMList* of missing_t pointers.
|
|
|
|
*
|
2006-01-15 10:55:16 -05:00
|
|
|
* dependencies can include versions with depmod operators.
|
2005-03-14 20:51:43 -05:00
|
|
|
*
|
|
|
|
*/
|
2006-02-17 17:35:26 -05:00
|
|
|
PMList *_alpm_checkdeps(pmdb_t *db, unsigned char op, PMList *packages)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
|
|
|
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) {
|
|
|
|
/* PM_TRANS_TYPE_UPGRADE handles the backwards dependencies, ie, the packages
|
|
|
|
* listed in the requiredby field.
|
|
|
|
*/
|
|
|
|
for(i = packages; i; i = i->next) {
|
2005-04-20 15:46:53 -04:00
|
|
|
pmpkg_t *tp = i->data;
|
|
|
|
pmpkg_t *oldpkg;
|
|
|
|
if(tp == NULL) {
|
2005-03-14 20:51:43 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2006-02-17 17:35:26 -05:00
|
|
|
if((oldpkg = _alpm_db_get_pkgfromcache(db, tp->name)) == NULL) {
|
2005-03-14 20:51:43 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for(j = oldpkg->requiredby; j; j = j->next) {
|
|
|
|
char *ver;
|
|
|
|
pmpkg_t *p;
|
|
|
|
found = 0;
|
2006-02-17 17:35:26 -05:00
|
|
|
if((p = _alpm_db_get_pkgfromcache(db, j->data)) == NULL) {
|
2005-03-14 20:51:43 -05:00
|
|
|
/* hmmm... package isn't installed.. */
|
|
|
|
continue;
|
|
|
|
}
|
2006-02-17 17:35:26 -05:00
|
|
|
if(_alpm_pkg_isin(p->name, packages)) {
|
2005-03-14 20:51:43 -05:00
|
|
|
/* this package is also in the upgrade list, so don't worry about it */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for(k = p->depends; k && !found; k = k->next) {
|
|
|
|
/* find the dependency info in p->depends */
|
2006-02-17 17:35:26 -05:00
|
|
|
_alpm_splitdep(k->data, &depend);
|
2005-03-14 20:51:43 -05:00
|
|
|
if(!strcmp(depend.name, oldpkg->name)) {
|
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(found == 0) {
|
|
|
|
/* look for packages that list depend.name as a "provide" */
|
|
|
|
PMList *provides = _alpm_db_whatprovides(db, depend.name);
|
|
|
|
if(provides == NULL) {
|
|
|
|
/* not found */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* we found an installed package that provides depend.name */
|
2005-03-28 03:25:33 -05:00
|
|
|
FREELISTPTR(provides);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
found = 0;
|
2005-03-29 15:31:03 -05:00
|
|
|
if(depend.mod == PM_DEP_MOD_ANY) {
|
2005-03-14 20:51:43 -05:00
|
|
|
found = 1;
|
|
|
|
} else {
|
|
|
|
/* note that we use the version from the NEW package in the check */
|
|
|
|
ver = strdup(tp->version);
|
|
|
|
if(!index(depend.version,'-')) {
|
|
|
|
char *ptr;
|
|
|
|
for(ptr = ver; *ptr != '-'; ptr++);
|
|
|
|
*ptr = '\0';
|
|
|
|
}
|
2006-02-17 17:35:26 -05:00
|
|
|
cmp = _alpm_versioncmp(ver, depend.version);
|
2005-03-14 20:51:43 -05:00
|
|
|
switch(depend.mod) {
|
2005-03-29 15:31:03 -05:00
|
|
|
case PM_DEP_MOD_EQ: found = (cmp == 0); break;
|
|
|
|
case PM_DEP_MOD_GE: found = (cmp >= 0); break;
|
|
|
|
case PM_DEP_MOD_LE: found = (cmp <= 0); break;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
FREE(ver);
|
|
|
|
}
|
|
|
|
if(!found) {
|
2006-01-18 17:37:16 -05:00
|
|
|
_alpm_log(PM_LOG_DEBUG, "checkdeps: found %s as required by %s", depend.name, p->name);
|
2006-02-17 17:35:26 -05:00
|
|
|
miss = _alpm_depmiss_new(p->name, PM_DEP_TYPE_REQUIRED, depend.mod, depend.name, depend.version);
|
|
|
|
if(!_alpm_depmiss_isin(miss, baddeps)) {
|
|
|
|
baddeps = _alpm_list_add(baddeps, miss);
|
2005-04-20 15:41:54 -04:00
|
|
|
} else {
|
|
|
|
FREE(miss);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(op == PM_TRANS_TYPE_ADD || op == PM_TRANS_TYPE_UPGRADE) {
|
2006-01-15 10:55:16 -05:00
|
|
|
/* DEPENDENCIES -- look for unsatisfied dependencies */
|
2005-03-14 20:51:43 -05:00
|
|
|
for(i = packages; i; i = i->next) {
|
|
|
|
pmpkg_t *tp = i->data;
|
|
|
|
if(tp == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(j = tp->depends; j; j = j->next) {
|
|
|
|
/* split into name/version pairs */
|
2006-02-17 17:35:26 -05:00
|
|
|
_alpm_splitdep((char *)j->data, &depend);
|
2005-03-14 20:51:43 -05:00
|
|
|
found = 0;
|
|
|
|
/* check database for literal packages */
|
2006-02-17 17:35:26 -05:00
|
|
|
for(k = _alpm_db_get_pkgcache(db); k && !found; k = k->next) {
|
2005-03-14 20:51:43 -05:00
|
|
|
pmpkg_t *p = (pmpkg_t *)k->data;
|
|
|
|
if(!strcmp(p->name, depend.name)) {
|
2005-03-29 15:31:03 -05:00
|
|
|
if(depend.mod == PM_DEP_MOD_ANY) {
|
2005-03-14 20:51:43 -05:00
|
|
|
/* accept any version */
|
|
|
|
found = 1;
|
|
|
|
} else {
|
|
|
|
char *ver = strdup(p->version);
|
|
|
|
/* check for a release in depend.version. if it's
|
|
|
|
* missing remove it from p->version as well.
|
|
|
|
*/
|
|
|
|
if(!index(depend.version,'-')) {
|
|
|
|
char *ptr;
|
|
|
|
for(ptr = ver; *ptr != '-'; ptr++);
|
|
|
|
*ptr = '\0';
|
|
|
|
}
|
2006-02-17 17:35:26 -05:00
|
|
|
cmp = _alpm_versioncmp(ver, depend.version);
|
2005-03-14 20:51:43 -05:00
|
|
|
switch(depend.mod) {
|
2005-03-29 15:31:03 -05:00
|
|
|
case PM_DEP_MOD_EQ: found = (cmp == 0); break;
|
|
|
|
case PM_DEP_MOD_GE: found = (cmp >= 0); break;
|
|
|
|
case PM_DEP_MOD_LE: found = (cmp <= 0); break;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
FREE(ver);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* check other targets */
|
|
|
|
for(k = packages; k && !found; k = k->next) {
|
|
|
|
pmpkg_t *p = (pmpkg_t *)k->data;
|
|
|
|
/* see if the package names match OR if p provides depend.name */
|
2006-02-17 17:35:26 -05:00
|
|
|
if(!strcmp(p->name, depend.name) || _alpm_list_is_strin(depend.name, p->provides)) {
|
2005-03-29 15:31:03 -05:00
|
|
|
if(depend.mod == PM_DEP_MOD_ANY) {
|
2005-03-14 20:51:43 -05:00
|
|
|
/* accept any version */
|
|
|
|
found = 1;
|
|
|
|
} else {
|
|
|
|
char *ver = strdup(p->version);
|
|
|
|
/* check for a release in depend.version. if it's
|
|
|
|
* missing remove it from p->version as well.
|
|
|
|
*/
|
|
|
|
if(!index(depend.version,'-')) {
|
|
|
|
char *ptr;
|
|
|
|
for(ptr = ver; *ptr != '-'; ptr++);
|
|
|
|
*ptr = '\0';
|
|
|
|
}
|
2006-02-17 17:35:26 -05:00
|
|
|
cmp = _alpm_versioncmp(ver, depend.version);
|
2005-03-14 20:51:43 -05:00
|
|
|
switch(depend.mod) {
|
2005-03-29 15:31:03 -05:00
|
|
|
case PM_DEP_MOD_EQ: found = (cmp == 0); break;
|
|
|
|
case PM_DEP_MOD_GE: found = (cmp >= 0); break;
|
|
|
|
case PM_DEP_MOD_LE: found = (cmp <= 0); break;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
FREE(ver);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* check database for provides matches */
|
|
|
|
if(!found){
|
|
|
|
k = _alpm_db_whatprovides(db, depend.name);
|
|
|
|
if(k) {
|
|
|
|
/* grab the first one (there should only really be one, anyway) */
|
2005-04-24 07:17:39 -04:00
|
|
|
pmpkg_t *p = k->data;
|
2005-03-29 15:31:03 -05:00
|
|
|
if(depend.mod == PM_DEP_MOD_ANY) {
|
2005-03-14 20:51:43 -05:00
|
|
|
/* accept any version */
|
|
|
|
found = 1;
|
|
|
|
} else {
|
|
|
|
char *ver = strdup(p->version);
|
|
|
|
/* check for a release in depend.version. if it's
|
|
|
|
* missing remove it from p->version as well.
|
|
|
|
*/
|
|
|
|
if(!index(depend.version,'-')) {
|
|
|
|
char *ptr;
|
|
|
|
for(ptr = ver; *ptr != '-'; ptr++);
|
|
|
|
*ptr = '\0';
|
|
|
|
}
|
2006-02-17 17:35:26 -05:00
|
|
|
cmp = _alpm_versioncmp(ver, depend.version);
|
2005-03-14 20:51:43 -05:00
|
|
|
switch(depend.mod) {
|
2005-03-29 15:31:03 -05:00
|
|
|
case PM_DEP_MOD_EQ: found = (cmp == 0); break;
|
|
|
|
case PM_DEP_MOD_GE: found = (cmp >= 0); break;
|
|
|
|
case PM_DEP_MOD_LE: found = (cmp <= 0); break;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
FREE(ver);
|
|
|
|
}
|
2005-04-24 07:17:39 -04:00
|
|
|
FREELISTPTR(k);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* else if still not found... */
|
|
|
|
if(!found) {
|
2006-01-18 17:37:16 -05:00
|
|
|
_alpm_log(PM_LOG_DEBUG, "checkdeps: found %s as a dependency for %s",
|
|
|
|
depend.name, tp->name);
|
2006-02-17 17:35:26 -05:00
|
|
|
miss = _alpm_depmiss_new(tp->name, PM_DEP_TYPE_DEPEND, depend.mod, depend.name, depend.version);
|
|
|
|
if(!_alpm_depmiss_isin(miss, baddeps)) {
|
|
|
|
baddeps = _alpm_list_add(baddeps, miss);
|
2005-04-20 15:41:54 -04:00
|
|
|
} else {
|
|
|
|
FREE(miss);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if(op == PM_TRANS_TYPE_REMOVE) {
|
|
|
|
/* check requiredby fields */
|
|
|
|
for(i = packages; i; i = i->next) {
|
2006-01-14 10:05:59 -05:00
|
|
|
pmpkg_t *tp = i->data;
|
|
|
|
if(tp == NULL) {
|
2005-03-14 20:51:43 -05:00
|
|
|
continue;
|
|
|
|
}
|
2006-01-14 10:05:59 -05:00
|
|
|
|
2005-03-14 20:51:43 -05:00
|
|
|
for(j = tp->requiredby; j; j = j->next) {
|
2006-02-17 17:35:26 -05:00
|
|
|
if(!_alpm_list_is_strin((char *)j->data, packages)) {
|
2006-01-18 17:37:16 -05:00
|
|
|
_alpm_log(PM_LOG_DEBUG, "checkdeps: found %s as required by %s", (char *)j->data, tp->name);
|
2006-02-17 17:35:26 -05:00
|
|
|
miss = _alpm_depmiss_new(tp->name, PM_DEP_TYPE_REQUIRED, PM_DEP_MOD_ANY, j->data, NULL);
|
|
|
|
if(!_alpm_depmiss_isin(miss, baddeps)) {
|
|
|
|
baddeps = _alpm_list_add(baddeps, miss);
|
2005-04-20 15:41:54 -04:00
|
|
|
} else {
|
|
|
|
FREE(miss);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(baddeps);
|
|
|
|
}
|
|
|
|
|
2006-02-17 17:35:26 -05:00
|
|
|
int _alpm_splitdep(char *depstr, pmdepend_t *depend)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
|
|
|
char *str = NULL;
|
|
|
|
char *ptr = NULL;
|
|
|
|
|
2005-03-26 03:50:27 -05:00
|
|
|
if(depstr == NULL || depend == NULL) {
|
2005-03-26 15:23:03 -05:00
|
|
|
return(-1);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2005-03-26 03:50:27 -05:00
|
|
|
depend->mod = 0;
|
|
|
|
depend->name[0] = 0;
|
|
|
|
depend->version[0] = 0;
|
|
|
|
|
2005-03-14 20:51:43 -05:00
|
|
|
str = strdup(depstr);
|
|
|
|
|
|
|
|
if((ptr = strstr(str, ">="))) {
|
2005-03-29 15:31:03 -05:00
|
|
|
depend->mod = PM_DEP_MOD_GE;
|
2005-03-14 20:51:43 -05:00
|
|
|
} else if((ptr = strstr(str, "<="))) {
|
2005-03-29 15:31:03 -05:00
|
|
|
depend->mod = PM_DEP_MOD_LE;
|
2005-03-14 20:51:43 -05:00
|
|
|
} else if((ptr = strstr(str, "="))) {
|
2005-03-29 15:31:03 -05:00
|
|
|
depend->mod = PM_DEP_MOD_EQ;
|
2005-03-14 20:51:43 -05:00
|
|
|
} else {
|
|
|
|
/* no version specified - accept any */
|
2005-03-29 15:31:03 -05:00
|
|
|
depend->mod = PM_DEP_MOD_ANY;
|
2005-03-29 12:18:59 -05:00
|
|
|
STRNCPY(depend->name, str, PKG_NAME_LEN);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if(ptr == NULL) {
|
|
|
|
FREE(str);
|
2005-03-26 15:23:03 -05:00
|
|
|
return(0);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
*ptr = '\0';
|
2005-03-29 12:18:59 -05:00
|
|
|
STRNCPY(depend->name, str, PKG_NAME_LEN);
|
2005-03-14 20:51:43 -05:00
|
|
|
ptr++;
|
2005-03-29 15:31:03 -05:00
|
|
|
if(depend->mod != PM_DEP_MOD_EQ) {
|
2005-03-14 20:51:43 -05:00
|
|
|
ptr++;
|
|
|
|
}
|
2005-03-29 12:18:59 -05:00
|
|
|
STRNCPY(depend->version, ptr, PKG_VERSION_LEN);
|
2005-03-14 20:51:43 -05:00
|
|
|
FREE(str);
|
|
|
|
|
2005-03-26 15:23:03 -05:00
|
|
|
return(0);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* return a new PMList 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.
|
|
|
|
*/
|
2006-02-17 17:35:26 -05:00
|
|
|
PMList* _alpm_removedeps(pmdb_t *db, PMList *targs)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
|
|
|
PMList *i, *j, *k;
|
|
|
|
PMList *newtargs = targs;
|
|
|
|
|
|
|
|
if(db == NULL) {
|
|
|
|
return(newtargs);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i = targs; i; i = i->next) {
|
2006-01-02 18:13:42 -05:00
|
|
|
for(j = ((pmpkg_t *)i->data)->depends; j; j = j->next) {
|
2005-03-14 20:51:43 -05:00
|
|
|
pmdepend_t depend;
|
|
|
|
pmpkg_t *dep;
|
|
|
|
int needed = 0;
|
2006-01-02 18:13:42 -05:00
|
|
|
|
2006-02-17 17:35:26 -05:00
|
|
|
if(_alpm_splitdep(j->data, &depend)) {
|
2006-01-02 18:13:42 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2006-02-17 17:35:26 -05:00
|
|
|
dep = _alpm_db_get_pkgfromcache(db, depend.name);
|
2006-01-02 18:13:42 -05:00
|
|
|
if(dep == NULL) {
|
|
|
|
/* package not found... look for a provisio instead */
|
|
|
|
k = _alpm_db_whatprovides(db, depend.name);
|
|
|
|
if(k == NULL) {
|
|
|
|
_alpm_log(PM_LOG_WARNING, "cannot find package \"%s\" or anything that provides it!", depend.name);
|
|
|
|
continue;
|
|
|
|
}
|
2006-02-17 17:35:26 -05:00
|
|
|
dep = _alpm_db_get_pkgfromcache(db, ((pmpkg_t *)k->data)->name);
|
2006-01-02 18:13:42 -05:00
|
|
|
if(dep == NULL) {
|
|
|
|
_alpm_log(PM_LOG_ERROR, "dep is NULL!");
|
2006-01-18 17:37:16 -05:00
|
|
|
/* wtf */
|
2006-01-02 18:13:42 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
FREELISTPTR(k);
|
|
|
|
}
|
2006-02-17 17:35:26 -05:00
|
|
|
if(_alpm_pkg_isin(dep->name, targs)) {
|
2005-03-14 20:51:43 -05:00
|
|
|
continue;
|
|
|
|
}
|
2006-01-02 18:13:42 -05:00
|
|
|
|
2005-03-14 20:51:43 -05:00
|
|
|
/* see if it was explicitly installed */
|
|
|
|
if(dep->reason == PM_PKG_REASON_EXPLICIT) {
|
2005-03-28 03:21:17 -05:00
|
|
|
_alpm_log(PM_LOG_FLOW2, "excluding %s -- explicitly installed", dep->name);
|
2005-03-14 20:51:43 -05:00
|
|
|
needed = 1;
|
|
|
|
}
|
2006-01-02 18:13:42 -05:00
|
|
|
|
2005-03-14 20:51:43 -05:00
|
|
|
/* see if other packages need it */
|
|
|
|
for(k = dep->requiredby; k && !needed; k = k->next) {
|
2006-02-17 17:35:26 -05:00
|
|
|
pmpkg_t *dummy = _alpm_db_get_pkgfromcache(db, k->data);
|
|
|
|
if(!_alpm_pkg_isin(dummy->name, targs)) {
|
2005-03-14 20:51:43 -05:00
|
|
|
needed = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!needed) {
|
2005-04-24 07:17:39 -04:00
|
|
|
char *name;
|
2006-02-17 17:35:26 -05:00
|
|
|
pmpkg_t *pkg = _alpm_pkg_new(dep->name, dep->version);
|
2006-01-02 18:13:42 -05:00
|
|
|
if(pkg == NULL) {
|
|
|
|
_alpm_log(PM_LOG_ERROR, "could not allocate memory for a package structure");
|
|
|
|
continue;
|
|
|
|
}
|
2005-04-24 07:17:39 -04:00
|
|
|
asprintf(&name, "%s-%s", dep->name, dep->version);
|
2005-03-14 20:51:43 -05:00
|
|
|
/* add it to the target list */
|
2006-02-17 17:35:26 -05:00
|
|
|
_alpm_db_read(db, name, INFRQ_ALL, pkg);
|
|
|
|
newtargs = _alpm_list_add(newtargs, pkg);
|
2006-01-02 18:13:42 -05:00
|
|
|
_alpm_log(PM_LOG_FLOW2, "adding %s to the targets", pkg->name);
|
2006-02-17 17:35:26 -05:00
|
|
|
newtargs = _alpm_removedeps(db, newtargs);
|
2005-04-24 07:17:39 -04:00
|
|
|
FREE(name);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(newtargs);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* populates *list with packages that need to be installed to satisfy all
|
2005-04-06 14:29:17 -04:00
|
|
|
* dependencies (recursive) for syncpkg
|
2005-03-14 20:51:43 -05:00
|
|
|
*
|
|
|
|
* make sure *list and *trail are already initialized
|
|
|
|
*/
|
2006-02-17 17:35:26 -05:00
|
|
|
int _alpm_resolvedeps(pmdb_t *local, PMList *dbs_sync, pmpkg_t *syncpkg, PMList *list,
|
2006-01-21 13:28:38 -05:00
|
|
|
PMList *trail, pmtrans_t *trans, PMList **data)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
2006-01-18 17:37:16 -05:00
|
|
|
PMList *i, *j;
|
2005-03-28 03:25:33 -05:00
|
|
|
PMList *targ;
|
2005-03-14 20:51:43 -05:00
|
|
|
PMList *deps = NULL;
|
|
|
|
|
2005-04-02 15:30:09 -05:00
|
|
|
if(local == NULL || dbs_sync == NULL || syncpkg == NULL) {
|
|
|
|
return(-1);
|
|
|
|
}
|
2005-03-30 17:32:43 -05:00
|
|
|
|
2006-02-17 17:35:26 -05:00
|
|
|
targ = _alpm_list_add(NULL, syncpkg);
|
|
|
|
deps = _alpm_checkdeps(local, PM_TRANS_TYPE_ADD, targ);
|
2005-03-28 03:25:33 -05:00
|
|
|
FREELISTPTR(targ);
|
2005-03-14 20:51:43 -05:00
|
|
|
|
|
|
|
if(deps == NULL) {
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i = deps; i; i = i->next) {
|
|
|
|
int found = 0;
|
|
|
|
pmdepmissing_t *miss = i->data;
|
2006-01-15 10:55:16 -05:00
|
|
|
pmpkg_t *sync = NULL;
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2006-01-15 10:55:16 -05:00
|
|
|
/* check if one of the packages in *list already provides this dependency */
|
2006-01-18 17:37:16 -05:00
|
|
|
for(j = list; j && !found; j = j->next) {
|
|
|
|
pmpkg_t *sp = (pmpkg_t *)j->data;
|
2006-02-17 17:35:26 -05:00
|
|
|
if(_alpm_list_is_strin(miss->depend.name, sp->provides)) {
|
2006-01-18 17:37:16 -05:00
|
|
|
_alpm_log(PM_LOG_DEBUG, "%s provides dependency %s -- skipping",
|
|
|
|
sp->name, miss->depend.name);
|
|
|
|
found = 1;
|
2005-10-21 15:55:24 -04:00
|
|
|
}
|
2006-01-15 10:55:16 -05:00
|
|
|
}
|
2006-01-18 17:37:16 -05:00
|
|
|
if(found) {
|
2006-01-15 10:55:16 -05:00
|
|
|
continue;
|
|
|
|
}
|
2005-10-21 15:55:24 -04:00
|
|
|
|
2006-01-15 10:55:16 -05:00
|
|
|
/* find the package in one of the repositories */
|
|
|
|
/* check literals */
|
|
|
|
for(j = dbs_sync; !sync && j; j = j->next) {
|
2006-02-17 17:35:26 -05:00
|
|
|
sync = _alpm_db_get_pkgfromcache(j->data, miss->depend.name);
|
2006-01-15 10:55:16 -05:00
|
|
|
}
|
|
|
|
/* check provides */
|
|
|
|
for(j = dbs_sync; !sync && j; j = j->next) {
|
|
|
|
PMList *provides;
|
2006-01-18 17:37:16 -05:00
|
|
|
provides = _alpm_db_whatprovides(j->data, miss->depend.name);
|
2006-01-15 10:55:16 -05:00
|
|
|
if(provides) {
|
|
|
|
sync = provides->data;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
2006-01-15 10:55:16 -05:00
|
|
|
FREELISTPTR(provides);
|
|
|
|
}
|
|
|
|
if(sync == NULL) {
|
|
|
|
_alpm_log(PM_LOG_ERROR, "cannot resolve dependencies for \"%s\" (\"%s\" is not in the package set)",
|
|
|
|
miss->target, miss->depend.name);
|
2006-01-21 13:28:38 -05:00
|
|
|
if(data) {
|
|
|
|
if((miss = (pmdepmissing_t *)malloc(sizeof(pmdepmissing_t))) == NULL) {
|
|
|
|
FREELIST(*data);
|
|
|
|
pm_errno = PM_ERR_MEMORY;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
*miss = *(pmdepmissing_t *)i->data;
|
2006-02-17 17:35:26 -05:00
|
|
|
*data = _alpm_list_add(*data, miss);
|
2006-01-21 13:28:38 -05:00
|
|
|
}
|
|
|
|
pm_errno = PM_ERR_UNSATISFIED_DEPS;
|
2006-01-15 10:55:16 -05:00
|
|
|
goto error;
|
|
|
|
}
|
2006-02-17 17:35:26 -05:00
|
|
|
if(_alpm_pkg_isin(sync->name, list)) {
|
2006-01-15 10:55:16 -05:00
|
|
|
/* this dep is already in the target list */
|
2006-01-18 17:37:16 -05:00
|
|
|
_alpm_log(PM_LOG_DEBUG, "dependency %s is already in the target list -- skipping",
|
|
|
|
sync->name);
|
2006-01-15 10:55:16 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2006-02-17 17:35:26 -05:00
|
|
|
if(!_alpm_pkg_isin(sync->name, trail)) {
|
2006-01-15 10:55:16 -05:00
|
|
|
/* check pmo_ignorepkg and pmo_s_ignore to make sure we haven't pulled in
|
|
|
|
* something we're not supposed to.
|
|
|
|
*/
|
|
|
|
int usedep = 1;
|
2006-02-17 17:35:26 -05:00
|
|
|
if(_alpm_list_is_strin(sync->name, handle->ignorepkg)) {
|
|
|
|
pmpkg_t *dummypkg = _alpm_pkg_new(miss->target, NULL);
|
2006-01-15 10:55:16 -05:00
|
|
|
QUESTION(trans, PM_TRANS_CONV_INSTALL_IGNOREPKG, dummypkg, sync, NULL, &usedep);
|
|
|
|
FREEPKG(dummypkg);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
2006-01-15 10:55:16 -05:00
|
|
|
if(usedep) {
|
2006-02-17 17:35:26 -05:00
|
|
|
trail = _alpm_list_add(trail, sync);
|
|
|
|
if(_alpm_resolvedeps(local, dbs_sync, sync, list, trail, trans, data)) {
|
2005-03-14 20:51:43 -05:00
|
|
|
goto error;
|
|
|
|
}
|
2006-01-15 10:55:16 -05:00
|
|
|
_alpm_log(PM_LOG_DEBUG, "pulling dependency %s (needed by %s)",
|
|
|
|
sync->name, syncpkg->name);
|
2006-02-17 17:35:26 -05:00
|
|
|
list = _alpm_list_add(list, sync);
|
2005-03-14 20:51:43 -05:00
|
|
|
} else {
|
2006-01-15 10:55:16 -05:00
|
|
|
_alpm_log(PM_LOG_ERROR, "cannot resolve dependencies for \"%s\"", miss->target);
|
2006-01-21 13:28:38 -05:00
|
|
|
if(data) {
|
|
|
|
if((miss = (pmdepmissing_t *)malloc(sizeof(pmdepmissing_t))) == NULL) {
|
|
|
|
FREELIST(*data);
|
|
|
|
pm_errno = PM_ERR_MEMORY;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
*miss = *(pmdepmissing_t *)i->data;
|
2006-02-17 17:35:26 -05:00
|
|
|
*data = _alpm_list_add(*data, miss);
|
2006-01-21 13:28:38 -05:00
|
|
|
}
|
|
|
|
pm_errno = PM_ERR_UNSATISFIED_DEPS;
|
2006-01-15 10:55:16 -05:00
|
|
|
goto error;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
2006-01-15 10:55:16 -05:00
|
|
|
} else {
|
|
|
|
/* cycle detected -- skip it */
|
|
|
|
_alpm_log(PM_LOG_DEBUG, "dependency cycle detected: %s", sync->name);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FREELIST(deps);
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
|
|
|
|
error:
|
|
|
|
FREELIST(deps);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vim: set ts=2 sw=2 noet: */
|