2005-03-14 20:51:43 -05:00
|
|
|
/*
|
|
|
|
* deps.c
|
2007-11-16 21:18:45 -05:00
|
|
|
*
|
2016-01-02 22:48:43 -05:00
|
|
|
* Copyright (c) 2006-2016 Pacman Development Team <pacman-dev@archlinux.org>
|
2009-07-01 03:08:33 -04:00
|
|
|
* Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
|
2006-10-15 15:31:03 -04:00
|
|
|
* Copyright (c) 2005 by Aurelien Foret <orelien@chez.com>
|
|
|
|
* Copyright (c) 2005, 2006 by Miklos Vajna <vmiklos@frugalware.org>
|
2007-11-16 21:18:45 -05:00
|
|
|
*
|
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
|
2007-12-10 23:55:22 -05:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2005-03-14 20:51:43 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2007-03-05 17:13:33 -05:00
|
|
|
|
|
|
|
/* libalpm */
|
|
|
|
#include "deps.h"
|
|
|
|
#include "alpm_list.h"
|
2005-03-14 20:51:43 -05:00
|
|
|
#include "util.h"
|
|
|
|
#include "log.h"
|
2008-02-15 21:57:30 -05:00
|
|
|
#include "graph.h"
|
2005-03-14 20:51:43 -05:00
|
|
|
#include "package.h"
|
|
|
|
#include "db.h"
|
2005-04-24 16:06:00 -04:00
|
|
|
#include "handle.h"
|
2011-06-03 17:42:41 -04:00
|
|
|
#include "trans.h"
|
2005-04-24 16:06:00 -04:00
|
|
|
|
2014-09-15 12:06:47 -04:00
|
|
|
void SYMEXPORT alpm_dep_free(alpm_depend_t *dep)
|
2008-01-11 02:00:15 -05:00
|
|
|
{
|
2015-10-25 07:39:27 -04:00
|
|
|
ASSERT(dep != NULL, return);
|
2008-01-11 02:00:15 -05:00
|
|
|
FREE(dep->name);
|
|
|
|
FREE(dep->version);
|
2011-12-12 14:34:48 -05:00
|
|
|
FREE(dep->desc);
|
2008-01-11 02:00:15 -05:00
|
|
|
FREE(dep);
|
|
|
|
}
|
|
|
|
|
2011-06-28 00:32:09 -04:00
|
|
|
static alpm_depmissing_t *depmiss_new(const char *target, alpm_depend_t *dep,
|
2007-11-18 12:45:46 -05:00
|
|
|
const char *causingpkg)
|
2006-01-15 10:55:16 -05:00
|
|
|
{
|
2011-06-28 00:32:09 -04:00
|
|
|
alpm_depmissing_t *miss;
|
2006-01-15 10:55:16 -05:00
|
|
|
|
2014-12-23 20:55:49 -05:00
|
|
|
CALLOC(miss, 1, sizeof(alpm_depmissing_t), return NULL);
|
2006-01-15 10:55:16 -05:00
|
|
|
|
2014-12-21 08:48:48 -05:00
|
|
|
STRDUP(miss->target, target, goto error);
|
2008-01-11 02:00:15 -05:00
|
|
|
miss->depend = _alpm_dep_dup(dep);
|
2014-12-21 08:48:48 -05:00
|
|
|
STRDUP(miss->causingpkg, causingpkg, goto error);
|
2006-01-15 10:55:16 -05:00
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return miss;
|
2014-12-21 08:48:48 -05:00
|
|
|
|
|
|
|
error:
|
|
|
|
alpm_depmissing_free(miss);
|
|
|
|
return NULL;
|
2006-01-15 10:55:16 -05:00
|
|
|
}
|
|
|
|
|
2014-02-03 12:09:18 -05:00
|
|
|
void SYMEXPORT alpm_depmissing_free(alpm_depmissing_t *miss)
|
2008-01-11 01:01:58 -05:00
|
|
|
{
|
2015-10-25 07:39:27 -04:00
|
|
|
ASSERT(miss != NULL, return);
|
2014-09-15 12:06:47 -04:00
|
|
|
alpm_dep_free(miss->depend);
|
2008-01-11 01:01:58 -05:00
|
|
|
FREE(miss->target);
|
2007-11-18 12:45:46 -05:00
|
|
|
FREE(miss->causingpkg);
|
2008-01-11 01:01:58 -05:00
|
|
|
FREE(miss);
|
|
|
|
}
|
|
|
|
|
2013-05-18 15:53:32 -04:00
|
|
|
/** Check if pkg2 satisfies a dependency of pkg1 */
|
|
|
|
static int _alpm_pkg_depends_on(alpm_pkg_t *pkg1, alpm_pkg_t *pkg2)
|
2011-03-25 15:45:42 -04:00
|
|
|
{
|
|
|
|
alpm_list_t *i;
|
|
|
|
for(i = alpm_pkg_get_depends(pkg1); i; i = i->next) {
|
|
|
|
if(_alpm_depcmp(pkg2, i->data)) {
|
2011-03-27 21:41:23 -04:00
|
|
|
return 1;
|
2011-03-25 15:45:42 -04:00
|
|
|
}
|
|
|
|
}
|
2011-03-27 21:41:23 -04:00
|
|
|
return 0;
|
2011-03-25 15:45:42 -04:00
|
|
|
}
|
|
|
|
|
2013-05-18 15:53:32 -04:00
|
|
|
static alpm_pkg_t *find_dep_satisfier(alpm_list_t *pkgs, alpm_depend_t *dep)
|
|
|
|
{
|
|
|
|
alpm_list_t *i;
|
|
|
|
|
|
|
|
for(i = pkgs; i; i = i->next) {
|
|
|
|
alpm_pkg_t *pkg = i->data;
|
|
|
|
if(_alpm_depcmp(pkg, dep)) {
|
|
|
|
return pkg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-06-28 09:26:39 -04:00
|
|
|
/* Convert a list of alpm_pkg_t * to a graph structure,
|
2007-07-17 08:23:18 -04:00
|
|
|
* with a edge for each dependency.
|
|
|
|
* Returns a list of vertices (one vertex = one package)
|
|
|
|
* (used by alpm_sortbydeps)
|
|
|
|
*/
|
2013-10-17 23:38:58 -04:00
|
|
|
static alpm_list_t *dep_graph_init(alpm_handle_t *handle,
|
|
|
|
alpm_list_t *targets, alpm_list_t *ignore)
|
2007-07-17 08:23:18 -04:00
|
|
|
{
|
2008-07-01 16:53:13 -04:00
|
|
|
alpm_list_t *i, *j;
|
2007-07-17 08:23:18 -04:00
|
|
|
alpm_list_t *vertices = NULL;
|
2013-10-17 23:38:58 -04:00
|
|
|
alpm_list_t *localpkgs = alpm_list_diff(
|
2015-09-15 01:08:16 -04:00
|
|
|
alpm_db_get_pkgcache(handle->db_local), targets, _alpm_pkg_cmp);
|
|
|
|
|
|
|
|
if(ignore) {
|
|
|
|
alpm_list_t *oldlocal = localpkgs;
|
|
|
|
localpkgs = alpm_list_diff(oldlocal, ignore, _alpm_pkg_cmp);
|
|
|
|
alpm_list_free(oldlocal);
|
|
|
|
}
|
2013-10-17 23:38:58 -04:00
|
|
|
|
2007-07-17 08:23:18 -04:00
|
|
|
/* We create the vertices */
|
|
|
|
for(i = targets; i; i = i->next) {
|
2011-06-28 00:54:19 -04:00
|
|
|
alpm_graph_t *vertex = _alpm_graph_new();
|
2007-07-17 08:23:18 -04:00
|
|
|
vertex->data = (void *)i->data;
|
|
|
|
vertices = alpm_list_add(vertices, vertex);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We compute the edges */
|
|
|
|
for(i = vertices; i; i = i->next) {
|
2011-06-28 00:54:19 -04:00
|
|
|
alpm_graph_t *vertex_i = i->data;
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *p_i = vertex_i->data;
|
2007-08-12 16:26:54 -04:00
|
|
|
/* TODO this should be somehow combined with alpm_checkdeps */
|
2007-07-17 08:23:18 -04:00
|
|
|
for(j = vertices; j; j = j->next) {
|
2011-06-28 00:54:19 -04:00
|
|
|
alpm_graph_t *vertex_j = j->data;
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *p_j = vertex_j->data;
|
2013-10-17 23:38:58 -04:00
|
|
|
if(_alpm_pkg_depends_on(p_i, p_j)) {
|
|
|
|
vertex_i->children =
|
|
|
|
alpm_list_add(vertex_i->children, vertex_j);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* lazily add local packages to the dep graph so they don't
|
|
|
|
* get resolved unnecessarily */
|
|
|
|
j = localpkgs;
|
|
|
|
while(j) {
|
|
|
|
alpm_list_t *next = j->next;
|
|
|
|
if(_alpm_pkg_depends_on(p_i, j->data)) {
|
|
|
|
alpm_graph_t *vertex_j = _alpm_graph_new();
|
|
|
|
vertex_j->data = (void *)j->data;
|
|
|
|
vertices = alpm_list_add(vertices, vertex_j);
|
2015-09-15 01:08:16 -04:00
|
|
|
vertex_i->children = alpm_list_add(vertex_i->children, vertex_j);
|
2013-10-17 23:38:58 -04:00
|
|
|
localpkgs = alpm_list_remove_item(localpkgs, j);
|
|
|
|
free(j);
|
2007-07-17 08:23:18 -04:00
|
|
|
}
|
2013-10-17 23:38:58 -04:00
|
|
|
j = next;
|
2007-07-17 08:23:18 -04:00
|
|
|
}
|
2013-10-17 23:38:58 -04:00
|
|
|
|
2007-07-17 08:23:18 -04:00
|
|
|
vertex_i->childptr = vertex_i->children;
|
|
|
|
}
|
2013-10-17 23:38:58 -04:00
|
|
|
alpm_list_free(localpkgs);
|
2011-03-20 20:45:57 -04:00
|
|
|
return vertices;
|
2007-07-17 08:23:18 -04:00
|
|
|
}
|
|
|
|
|
2005-03-14 20:51:43 -05:00
|
|
|
/* Re-order a list of target packages with respect to their dependencies.
|
|
|
|
*
|
2008-03-16 17:36:31 -04:00
|
|
|
* Example (reverse == 0):
|
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
|
2007-11-16 21:18:45 -05:00
|
|
|
*
|
2013-10-17 23:38:58 -04:00
|
|
|
* packages listed in ignore will not be used to detect indirect dependencies
|
|
|
|
*
|
2008-03-16 17:36:31 -04:00
|
|
|
* if reverse is > 0, the dependency order will be reversed.
|
2005-03-25 17:09:14 -05:00
|
|
|
*
|
2007-01-19 04:28:44 -05:00
|
|
|
* This function returns the new alpm_list_t* target list.
|
2005-03-14 20:51:43 -05:00
|
|
|
*
|
2007-11-16 21:18:45 -05:00
|
|
|
*/
|
2011-06-28 00:04:00 -04:00
|
|
|
alpm_list_t *_alpm_sortbydeps(alpm_handle_t *handle,
|
2013-10-17 23:38:58 -04:00
|
|
|
alpm_list_t *targets, alpm_list_t *ignore, int reverse)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
2007-01-19 04:28:44 -05:00
|
|
|
alpm_list_t *newtargs = NULL;
|
2007-06-10 17:51:20 -04:00
|
|
|
alpm_list_t *vertices = NULL;
|
|
|
|
alpm_list_t *vptr;
|
2011-06-28 00:54:19 -04:00
|
|
|
alpm_graph_t *vertex;
|
2005-03-14 20:51:43 -05:00
|
|
|
|
|
|
|
if(targets == NULL) {
|
2011-03-20 20:45:57 -04:00
|
|
|
return NULL;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "started sorting dependencies\n");
|
2007-06-10 17:51:20 -04:00
|
|
|
|
2013-10-17 23:38:58 -04:00
|
|
|
vertices = dep_graph_init(handle, targets, ignore);
|
2007-01-30 00:41:13 -05:00
|
|
|
|
2007-06-10 17:51:20 -04:00
|
|
|
vptr = vertices;
|
|
|
|
vertex = vertices->data;
|
|
|
|
while(vptr) {
|
|
|
|
/* mark that we touched the vertex */
|
|
|
|
vertex->state = -1;
|
|
|
|
int found = 0;
|
|
|
|
while(vertex->childptr && !found) {
|
2011-06-28 00:54:19 -04:00
|
|
|
alpm_graph_t *nextchild = vertex->childptr->data;
|
2011-02-25 08:51:58 -05:00
|
|
|
vertex->childptr = vertex->childptr->next;
|
2011-04-20 20:45:16 -04:00
|
|
|
if(nextchild->state == 0) {
|
2007-06-10 17:51:20 -04:00
|
|
|
found = 1;
|
|
|
|
nextchild->parent = vertex;
|
|
|
|
vertex = nextchild;
|
2013-10-17 23:38:58 -04:00
|
|
|
} else if(nextchild->state == -1) {
|
|
|
|
/* child is an ancestor of vertex */
|
|
|
|
alpm_graph_t *transvertex = vertex;
|
|
|
|
|
2014-08-01 17:19:48 -04:00
|
|
|
if(!alpm_list_find_ptr(targets, nextchild->data)) {
|
2013-10-17 23:38:58 -04:00
|
|
|
/* child is not part of the transaction, not a problem */
|
|
|
|
continue;
|
|
|
|
}
|
2011-02-25 08:55:16 -05:00
|
|
|
|
2013-10-17 23:38:58 -04:00
|
|
|
/* find the nearest parent that's part of the transaction */
|
|
|
|
while(transvertex) {
|
2014-08-01 17:19:48 -04:00
|
|
|
if(alpm_list_find_ptr(targets, transvertex->data)) {
|
2013-10-17 23:38:58 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
transvertex = transvertex->parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!transvertex || transvertex == nextchild) {
|
|
|
|
/* no transaction package in our ancestry or the package has
|
|
|
|
* a circular dependency with itself, not a problem */
|
2007-11-20 19:03:08 -05:00
|
|
|
} else {
|
2013-10-17 23:38:58 -04:00
|
|
|
alpm_pkg_t *transpkg = transvertex->data;
|
|
|
|
alpm_pkg_t *childpkg = nextchild->data;
|
|
|
|
_alpm_log(handle, ALPM_LOG_WARNING, _("dependency cycle detected:\n"));
|
|
|
|
if(reverse) {
|
|
|
|
_alpm_log(handle, ALPM_LOG_WARNING,
|
|
|
|
_("%s will be removed after its %s dependency\n"),
|
|
|
|
transpkg->name, childpkg->name);
|
|
|
|
} else {
|
|
|
|
_alpm_log(handle, ALPM_LOG_WARNING,
|
|
|
|
_("%s will be installed before its %s dependency\n"),
|
|
|
|
transpkg->name, childpkg->name);
|
|
|
|
}
|
2007-11-20 19:03:08 -05:00
|
|
|
}
|
2007-06-10 17:51:20 -04:00
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
2007-06-10 17:51:20 -04:00
|
|
|
if(!found) {
|
2014-08-01 17:19:48 -04:00
|
|
|
if(alpm_list_find_ptr(targets, vertex->data)) {
|
2013-10-17 23:38:58 -04:00
|
|
|
newtargs = alpm_list_add(newtargs, vertex->data);
|
|
|
|
}
|
2007-06-10 17:51:20 -04:00
|
|
|
/* mark that we've left this vertex */
|
|
|
|
vertex->state = 1;
|
|
|
|
vertex = vertex->parent;
|
|
|
|
if(!vertex) {
|
2013-10-17 23:38:58 -04:00
|
|
|
/* top level vertex reached, move to the next unprocessed vertex */
|
|
|
|
for( vptr = vptr->next; vptr; vptr = vptr->next) {
|
2007-06-10 17:51:20 -04:00
|
|
|
vertex = vptr->data;
|
2013-10-17 23:38:58 -04:00
|
|
|
if(vertex->state == 0) {
|
|
|
|
break;
|
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-06-10 17:51:20 -04:00
|
|
|
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "sorting dependencies finished\n");
|
2005-05-04 15:30:00 -04:00
|
|
|
|
2008-03-16 17:36:31 -04:00
|
|
|
if(reverse) {
|
|
|
|
/* reverse the order */
|
2007-01-19 04:28:44 -05:00
|
|
|
alpm_list_t *tmptargs = alpm_list_reverse(newtargs);
|
2005-03-25 17:09:14 -05:00
|
|
|
/* free the old one */
|
2007-04-28 03:54:25 -04:00
|
|
|
alpm_list_free(newtargs);
|
2005-05-04 15:30:00 -04:00
|
|
|
newtargs = tmptargs;
|
2005-03-25 17:09:14 -05:00
|
|
|
}
|
|
|
|
|
2007-06-10 17:51:20 -04:00
|
|
|
alpm_list_free_inner(vertices, _alpm_graph_free);
|
2007-09-29 00:22:32 -04:00
|
|
|
alpm_list_free(vertices);
|
2007-06-10 17:51:20 -04:00
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return newtargs;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2011-06-28 00:04:00 -04:00
|
|
|
static int no_dep_version(alpm_handle_t *handle)
|
2011-03-25 16:37:18 -04:00
|
|
|
{
|
2012-01-18 23:09:43 -05:00
|
|
|
if(!handle->trans) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return (handle->trans->flags & ALPM_TRANS_FLAG_NODEPVERSION);
|
2011-03-25 16:37:18 -04:00
|
|
|
}
|
|
|
|
|
2010-10-12 14:13:32 -04:00
|
|
|
/** Find a package satisfying a specified dependency.
|
|
|
|
* The dependency can include versions with depmod operators.
|
2011-06-28 09:26:39 -04:00
|
|
|
* @param pkgs an alpm_list_t* of alpm_pkg_t where the satisfier will be searched
|
2010-10-12 14:13:32 -04:00
|
|
|
* @param depstring package or provision name, versioned or not
|
2011-06-28 09:26:39 -04:00
|
|
|
* @return a alpm_pkg_t* satisfying depstring
|
2010-10-12 14:13:32 -04:00
|
|
|
*/
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t SYMEXPORT *alpm_find_satisfier(alpm_list_t *pkgs, const char *depstring)
|
2010-10-12 14:13:32 -04:00
|
|
|
{
|
2014-09-15 12:06:47 -04:00
|
|
|
alpm_depend_t *dep = alpm_dep_from_string(depstring);
|
2011-06-07 17:06:16 -04:00
|
|
|
if(!dep) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *pkg = find_dep_satisfier(pkgs, dep);
|
2014-09-15 12:06:47 -04:00
|
|
|
alpm_dep_free(dep);
|
2011-03-20 20:45:57 -04:00
|
|
|
return pkg;
|
2010-10-12 14:13:32 -04:00
|
|
|
}
|
|
|
|
|
2007-08-25 19:14:34 -04:00
|
|
|
/** Checks dependencies and returns missing ones in a list.
|
|
|
|
* Dependencies can include versions with depmod operators.
|
2011-06-07 15:05:42 -04:00
|
|
|
* @param handle the context handle
|
2008-08-17 13:30:36 -04:00
|
|
|
* @param pkglist the list of local packages
|
2007-08-12 16:26:54 -04:00
|
|
|
* @param remove an alpm_list_t* of packages to be removed
|
|
|
|
* @param upgrade an alpm_list_t* of packages to be upgraded (remove-then-upgrade)
|
2011-06-07 15:05:42 -04:00
|
|
|
* @param reversedeps handles the backward dependencies
|
2011-06-28 00:32:09 -04:00
|
|
|
* @return an alpm_list_t* of alpm_depmissing_t pointers.
|
2005-03-14 20:51:43 -05:00
|
|
|
*/
|
2011-08-11 00:28:57 -04:00
|
|
|
alpm_list_t SYMEXPORT *alpm_checkdeps(alpm_handle_t *handle,
|
2012-05-08 17:23:58 -04:00
|
|
|
alpm_list_t *pkglist, alpm_list_t *rem, alpm_list_t *upgrade,
|
2011-08-11 00:28:57 -04:00
|
|
|
int reversedeps)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
2007-11-29 07:54:44 -05:00
|
|
|
alpm_list_t *i, *j;
|
2011-07-03 14:39:13 -04:00
|
|
|
alpm_list_t *dblist = NULL, *modified = NULL;
|
2007-01-19 04:28:44 -05:00
|
|
|
alpm_list_t *baddeps = NULL;
|
2011-03-25 16:37:18 -04:00
|
|
|
int nodepversion;
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2011-06-14 11:01:08 -04:00
|
|
|
CHECK_HANDLE(handle, return NULL);
|
|
|
|
|
2008-08-17 13:30:36 -04:00
|
|
|
for(i = pkglist; i; i = i->next) {
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *pkg = i->data;
|
2012-08-12 06:48:53 -04:00
|
|
|
if(alpm_pkg_find(rem, pkg->name) || alpm_pkg_find(upgrade, pkg->name)) {
|
2008-01-10 09:33:09 -05:00
|
|
|
modified = alpm_list_add(modified, pkg);
|
|
|
|
} else {
|
|
|
|
dblist = alpm_list_add(dblist, pkg);
|
|
|
|
}
|
|
|
|
}
|
2007-11-29 07:54:44 -05:00
|
|
|
|
2011-06-07 14:29:05 -04:00
|
|
|
nodepversion = no_dep_version(handle);
|
2011-03-25 16:37:18 -04:00
|
|
|
|
2007-08-12 16:26:54 -04:00
|
|
|
/* look for unsatisfied dependencies of the upgrade list */
|
|
|
|
for(i = upgrade; i; i = i->next) {
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *tp = i->data;
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "checkdeps: package %s-%s\n",
|
2011-08-11 00:28:57 -04:00
|
|
|
tp->name, tp->version);
|
2007-08-12 16:26:54 -04:00
|
|
|
|
|
|
|
for(j = alpm_pkg_get_depends(tp); j; j = j->next) {
|
2011-06-28 00:29:55 -04:00
|
|
|
alpm_depend_t *depend = j->data;
|
2013-11-14 21:02:07 -05:00
|
|
|
alpm_depmod_t orig_mod = depend->mod;
|
|
|
|
if(nodepversion) {
|
|
|
|
depend->mod = ALPM_DEP_MOD_ANY;
|
|
|
|
}
|
2007-08-12 16:26:54 -04:00
|
|
|
/* 1. we check the upgrade list */
|
|
|
|
/* 2. we check database for untouched satisfying packages */
|
2014-07-04 17:12:01 -04:00
|
|
|
/* 3. we check the dependency ignore list */
|
2011-03-25 15:45:42 -04:00
|
|
|
if(!find_dep_satisfier(upgrade, depend) &&
|
2014-07-04 17:12:01 -04:00
|
|
|
!find_dep_satisfier(dblist, depend) &&
|
|
|
|
!_alpm_depcmp_provides(depend, handle->assumeinstalled)) {
|
2007-11-29 07:54:44 -05:00
|
|
|
/* Unsatisfied dependency in the upgrade list */
|
2011-06-28 00:32:09 -04:00
|
|
|
alpm_depmissing_t *miss;
|
2008-08-26 06:57:08 -04:00
|
|
|
char *missdepstring = alpm_dep_compute_string(depend);
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "checkdeps: missing dependency '%s' for package '%s'\n",
|
2011-08-11 00:28:57 -04:00
|
|
|
missdepstring, tp->name);
|
2007-08-12 16:26:54 -04:00
|
|
|
free(missdepstring);
|
2011-08-11 00:28:57 -04:00
|
|
|
miss = depmiss_new(tp->name, depend, NULL);
|
2007-11-29 07:54:44 -05:00
|
|
|
baddeps = alpm_list_add(baddeps, miss);
|
2007-08-12 16:26:54 -04:00
|
|
|
}
|
2013-11-14 21:02:07 -05:00
|
|
|
depend->mod = orig_mod;
|
2007-08-12 16:26:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(reversedeps) {
|
|
|
|
/* reversedeps handles the backwards dependencies, ie,
|
|
|
|
* the packages listed in the requiredby field. */
|
2007-11-29 07:54:44 -05:00
|
|
|
for(i = dblist; i; i = i->next) {
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *lp = i->data;
|
2007-11-29 07:54:44 -05:00
|
|
|
for(j = alpm_pkg_get_depends(lp); j; j = j->next) {
|
2011-06-28 00:29:55 -04:00
|
|
|
alpm_depend_t *depend = j->data;
|
2013-11-14 21:02:07 -05:00
|
|
|
alpm_depmod_t orig_mod = depend->mod;
|
|
|
|
if(nodepversion) {
|
|
|
|
depend->mod = ALPM_DEP_MOD_ANY;
|
|
|
|
}
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *causingpkg = find_dep_satisfier(modified, depend);
|
2007-11-29 07:54:44 -05:00
|
|
|
/* we won't break this depend, if it is already broken, we ignore it */
|
|
|
|
/* 1. check upgrade list for satisfiers */
|
|
|
|
/* 2. check dblist for satisfiers */
|
2014-07-04 17:12:01 -04:00
|
|
|
/* 3. we check the dependency ignore list */
|
2007-11-18 12:45:46 -05:00
|
|
|
if(causingpkg &&
|
2013-11-08 00:44:40 -05:00
|
|
|
!find_dep_satisfier(upgrade, depend) &&
|
2014-07-04 17:12:01 -04:00
|
|
|
!find_dep_satisfier(dblist, depend) &&
|
|
|
|
!_alpm_depcmp_provides(depend, handle->assumeinstalled)) {
|
2011-06-28 00:32:09 -04:00
|
|
|
alpm_depmissing_t *miss;
|
2008-08-26 06:57:08 -04:00
|
|
|
char *missdepstring = alpm_dep_compute_string(depend);
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "checkdeps: transaction would break '%s' dependency of '%s'\n",
|
2011-08-11 00:28:57 -04:00
|
|
|
missdepstring, lp->name);
|
2007-08-12 16:26:54 -04:00
|
|
|
free(missdepstring);
|
2011-08-11 00:28:57 -04:00
|
|
|
miss = depmiss_new(lp->name, depend, causingpkg->name);
|
2007-11-29 07:54:44 -05:00
|
|
|
baddeps = alpm_list_add(baddeps, miss);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
2013-11-14 21:02:07 -05:00
|
|
|
depend->mod = orig_mod;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-02-25 08:51:58 -05:00
|
|
|
|
2008-01-10 09:33:09 -05:00
|
|
|
alpm_list_free(modified);
|
2007-11-29 07:54:44 -05:00
|
|
|
alpm_list_free(dblist);
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return baddeps;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2011-06-27 23:56:46 -04:00
|
|
|
static int dep_vercmp(const char *version1, alpm_depmod_t mod,
|
2007-07-16 12:27:42 -04:00
|
|
|
const char *version2)
|
|
|
|
{
|
|
|
|
int equal = 0;
|
|
|
|
|
2011-07-01 12:01:38 -04:00
|
|
|
if(mod == ALPM_DEP_MOD_ANY) {
|
2007-07-16 12:27:42 -04:00
|
|
|
equal = 1;
|
|
|
|
} else {
|
2008-05-14 01:37:51 -04:00
|
|
|
int cmp = alpm_pkg_vercmp(version1, version2);
|
2007-07-16 12:27:42 -04:00
|
|
|
switch(mod) {
|
2011-07-01 12:01:38 -04:00
|
|
|
case ALPM_DEP_MOD_EQ: equal = (cmp == 0); break;
|
|
|
|
case ALPM_DEP_MOD_GE: equal = (cmp >= 0); break;
|
|
|
|
case ALPM_DEP_MOD_LE: equal = (cmp <= 0); break;
|
|
|
|
case ALPM_DEP_MOD_LT: equal = (cmp < 0); break;
|
|
|
|
case ALPM_DEP_MOD_GT: equal = (cmp > 0); break;
|
2007-07-16 12:27:42 -04:00
|
|
|
default: equal = 1; break;
|
|
|
|
}
|
|
|
|
}
|
2011-03-20 20:45:57 -04:00
|
|
|
return equal;
|
2007-07-16 12:27:42 -04:00
|
|
|
}
|
|
|
|
|
2011-08-18 01:11:19 -04:00
|
|
|
int _alpm_depcmp_literal(alpm_pkg_t *pkg, alpm_depend_t *dep)
|
|
|
|
{
|
|
|
|
if(pkg->name_hash != dep->name_hash
|
|
|
|
|| strcmp(pkg->name, dep->name) != 0) {
|
|
|
|
/* skip more expensive checks */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return dep_vercmp(pkg->version, dep->mod, dep->version);
|
|
|
|
}
|
|
|
|
|
2014-08-06 05:36:51 -04:00
|
|
|
/**
|
2016-04-29 17:32:13 -04:00
|
|
|
* @param dep dependency to check against the provision list
|
2014-08-06 05:36:51 -04:00
|
|
|
* @param provisions provision list
|
|
|
|
* @return 1 if provider is found, 0 otherwise
|
|
|
|
*/
|
|
|
|
int _alpm_depcmp_provides(alpm_depend_t *dep, alpm_list_t *provisions)
|
2007-07-12 15:20:43 -04:00
|
|
|
{
|
2014-08-06 05:36:51 -04:00
|
|
|
int satisfy = 0;
|
2007-11-16 16:37:57 -05:00
|
|
|
alpm_list_t *i;
|
2007-07-16 12:27:42 -04:00
|
|
|
|
2011-08-09 02:00:16 -04:00
|
|
|
/* check provisions, name and version if available */
|
2014-08-06 05:36:51 -04:00
|
|
|
for(i = provisions; i && !satisfy; i = i->next) {
|
2011-08-09 02:00:16 -04:00
|
|
|
alpm_depend_t *provision = i->data;
|
|
|
|
|
|
|
|
if(dep->mod == ALPM_DEP_MOD_ANY) {
|
|
|
|
/* any version will satisfy the requirement */
|
|
|
|
satisfy = (provision->name_hash == dep->name_hash
|
|
|
|
&& strcmp(provision->name, dep->name) == 0);
|
2011-12-06 23:37:32 -05:00
|
|
|
} else if(provision->mod == ALPM_DEP_MOD_EQ) {
|
2011-08-09 02:00:16 -04:00
|
|
|
/* provision specifies a version, so try it out */
|
|
|
|
satisfy = (provision->name_hash == dep->name_hash
|
|
|
|
&& strcmp(provision->name, dep->name) == 0
|
|
|
|
&& dep_vercmp(provision->version, dep->mod, dep->version));
|
2007-07-12 15:20:43 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return satisfy;
|
2007-07-12 15:20:43 -04:00
|
|
|
}
|
|
|
|
|
2014-08-06 05:36:51 -04:00
|
|
|
int _alpm_depcmp(alpm_pkg_t *pkg, alpm_depend_t *dep)
|
|
|
|
{
|
|
|
|
return _alpm_depcmp_literal(pkg, dep)
|
|
|
|
|| _alpm_depcmp_provides(dep, alpm_pkg_get_provides(pkg));
|
|
|
|
}
|
|
|
|
|
2014-09-15 12:06:47 -04:00
|
|
|
alpm_depend_t SYMEXPORT *alpm_dep_from_string(const char *depstring)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
2011-06-28 00:29:55 -04:00
|
|
|
alpm_depend_t *depend;
|
2011-12-12 14:34:48 -05:00
|
|
|
const char *ptr, *version, *desc;
|
2011-08-29 00:29:53 -04:00
|
|
|
size_t deplen;
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2007-03-03 04:43:16 -05:00
|
|
|
if(depstring == NULL) {
|
2011-03-20 20:45:57 -04:00
|
|
|
return NULL;
|
2007-03-03 04:43:16 -05:00
|
|
|
}
|
2007-11-16 21:18:45 -05:00
|
|
|
|
2014-12-23 20:55:49 -05:00
|
|
|
CALLOC(depend, 1, sizeof(alpm_depend_t), return NULL);
|
2011-12-12 14:34:48 -05:00
|
|
|
|
|
|
|
/* Note the extra space in ": " to avoid matching the epoch */
|
|
|
|
if((desc = strstr(depstring, ": ")) != NULL) {
|
2014-12-22 02:42:41 -05:00
|
|
|
STRDUP(depend->desc, desc + 2, goto error);
|
2011-12-12 14:34:48 -05:00
|
|
|
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;
|
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2007-03-03 04:43:16 -05:00
|
|
|
/* 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. */
|
2011-08-29 00:29:53 -04:00
|
|
|
if((ptr = memchr(depstring, '<', deplen))) {
|
|
|
|
if(ptr[1] == '=') {
|
|
|
|
depend->mod = ALPM_DEP_MOD_LE;
|
|
|
|
version = ptr + 2;
|
|
|
|
} else {
|
|
|
|
depend->mod = ALPM_DEP_MOD_LT;
|
|
|
|
version = ptr + 1;
|
|
|
|
}
|
|
|
|
} else if((ptr = memchr(depstring, '>', deplen))) {
|
|
|
|
if(ptr[1] == '=') {
|
|
|
|
depend->mod = ALPM_DEP_MOD_GE;
|
|
|
|
version = ptr + 2;
|
|
|
|
} else {
|
|
|
|
depend->mod = ALPM_DEP_MOD_GT;
|
|
|
|
version = ptr + 1;
|
|
|
|
}
|
|
|
|
} else if((ptr = memchr(depstring, '=', deplen))) {
|
2010-12-21 16:40:04 -05:00
|
|
|
/* Note: we must do =,<,> checks after <=, >= checks */
|
2011-07-01 12:01:38 -04:00
|
|
|
depend->mod = ALPM_DEP_MOD_EQ;
|
2011-01-19 13:00:39 -05:00
|
|
|
version = ptr + 1;
|
2005-03-14 20:51:43 -05:00
|
|
|
} else {
|
2011-12-12 14:34:48 -05:00
|
|
|
/* no version specified, set ptr to end of string and version to NULL */
|
|
|
|
ptr = depstring + deplen;
|
2011-07-01 12:01:38 -04:00
|
|
|
depend->mod = ALPM_DEP_MOD_ANY;
|
2011-09-27 18:47:40 -04:00
|
|
|
depend->version = NULL;
|
|
|
|
version = NULL;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
2007-02-18 13:29:28 -05:00
|
|
|
|
2011-01-19 13:00:39 -05:00
|
|
|
/* copy the right parts to the right places */
|
2014-12-22 02:42:41 -05:00
|
|
|
STRNDUP(depend->name, depstring, ptr - depstring, goto error);
|
2010-12-21 16:40:04 -05:00
|
|
|
depend->name_hash = _alpm_hash_sdbm(depend->name);
|
2011-01-19 13:00:39 -05:00
|
|
|
if(version) {
|
2014-12-22 02:42:41 -05:00
|
|
|
STRNDUP(depend->version, version, desc - version, goto error);
|
2011-01-19 13:00:39 -05:00
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return depend;
|
2014-12-22 02:42:41 -05:00
|
|
|
|
|
|
|
error:
|
|
|
|
alpm_dep_free(depend);
|
|
|
|
return NULL;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2011-06-28 00:29:55 -04:00
|
|
|
alpm_depend_t *_alpm_dep_dup(const alpm_depend_t *dep)
|
2008-01-11 02:00:15 -05:00
|
|
|
{
|
2011-06-28 00:29:55 -04:00
|
|
|
alpm_depend_t *newdep;
|
|
|
|
CALLOC(newdep, 1, sizeof(alpm_depend_t), return NULL);
|
2008-01-11 02:00:15 -05:00
|
|
|
|
2014-12-21 09:08:24 -05:00
|
|
|
STRDUP(newdep->name, dep->name, goto error);
|
|
|
|
STRDUP(newdep->version, dep->version, goto error);
|
|
|
|
STRDUP(newdep->desc, dep->desc, goto error);
|
2011-12-12 14:34:48 -05:00
|
|
|
newdep->name_hash = dep->name_hash;
|
2008-01-11 02:00:15 -05:00
|
|
|
newdep->mod = dep->mod;
|
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return newdep;
|
2014-12-21 09:08:24 -05:00
|
|
|
|
|
|
|
error:
|
|
|
|
alpm_dep_free(newdep);
|
|
|
|
return NULL;
|
2008-01-11 02:00:15 -05:00
|
|
|
}
|
|
|
|
|
2016-05-23 08:27:29 -04:00
|
|
|
/** Move package dependencies from one list to another
|
|
|
|
* @param from list to scan for dependencies
|
|
|
|
* @param to list to add dependencies to
|
|
|
|
* @param pkg package whose dependencies are moved
|
|
|
|
* @param explicit if 0, explicitly installed packages are not moved
|
|
|
|
*/
|
|
|
|
static void _alpm_select_depends(alpm_list_t **from, alpm_list_t **to,
|
|
|
|
alpm_pkg_t *pkg, int explicit)
|
2007-02-20 03:44:32 -05:00
|
|
|
{
|
2016-05-23 08:27:29 -04:00
|
|
|
alpm_list_t *i, *next;
|
|
|
|
if(!alpm_pkg_get_depends(pkg)) {
|
|
|
|
return;
|
2007-02-20 03:44:32 -05:00
|
|
|
}
|
2016-05-23 08:27:29 -04:00
|
|
|
for(i = *from; i; i = next) {
|
|
|
|
alpm_pkg_t *deppkg = i->data;
|
|
|
|
next = i->next;
|
|
|
|
if((explicit || alpm_pkg_get_reason(deppkg) != ALPM_PKG_REASON_EXPLICIT)
|
|
|
|
&& _alpm_pkg_depends_on(pkg, deppkg)) {
|
|
|
|
*to = alpm_list_add(*to, deppkg);
|
|
|
|
*from = alpm_list_remove_item(*from, i);
|
|
|
|
free(i);
|
2007-07-13 09:30:37 -04:00
|
|
|
}
|
2007-02-20 03:44:32 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-13 09:30:37 -04:00
|
|
|
/**
|
|
|
|
* @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.
|
2007-11-14 06:42:15 -05:00
|
|
|
* If the input list was topo sorted, the output list will be topo sorted too.
|
2007-07-13 09:30:37 -04:00
|
|
|
*
|
|
|
|
* @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
|
2011-08-19 12:06:55 -04:00
|
|
|
* @return 0 on success, -1 on errors
|
2005-03-14 20:51:43 -05:00
|
|
|
*/
|
2013-10-25 23:20:24 -04:00
|
|
|
int _alpm_recursedeps(alpm_db_t *db, alpm_list_t **targs, int include_explicit)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
2016-05-23 08:27:29 -04:00
|
|
|
alpm_list_t *i, *keep, *rem = NULL;
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2007-07-13 09:30:37 -04:00
|
|
|
if(db == NULL || targs == NULL) {
|
2011-08-19 12:06:55 -04:00
|
|
|
return -1;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2016-05-23 08:27:29 -04:00
|
|
|
keep = alpm_list_copy(_alpm_db_get_pkgcache(db));
|
2013-10-25 23:20:24 -04:00
|
|
|
for(i = *targs; i; i = i->next) {
|
2016-05-23 08:27:29 -04:00
|
|
|
keep = alpm_list_remove(keep, i->data, _alpm_pkg_cmp, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* recursively select all dependencies for removal */
|
|
|
|
for(i = *targs; i; i = i->next) {
|
|
|
|
_alpm_select_depends(&keep, &rem, i->data, include_explicit);
|
|
|
|
}
|
|
|
|
for(i = rem; i; i = i->next) {
|
|
|
|
_alpm_select_depends(&keep, &rem, i->data, include_explicit);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* recursively select any still needed packages to keep */
|
|
|
|
for(i = keep; i && rem; i = i->next) {
|
|
|
|
_alpm_select_depends(&rem, &keep, i->data, 1);
|
|
|
|
}
|
|
|
|
alpm_list_free(keep);
|
|
|
|
|
|
|
|
/* copy selected packages into the target list */
|
|
|
|
for(i = rem; i; i = i->next) {
|
|
|
|
alpm_pkg_t *pkg = i->data, *copy = NULL;
|
|
|
|
_alpm_log(db->handle, ALPM_LOG_DEBUG,
|
|
|
|
"adding '%s' to the targets\n", pkg->name);
|
|
|
|
if(_alpm_pkg_dup(pkg, ©)) {
|
|
|
|
/* we return memory on "non-fatal" error in _alpm_pkg_dup */
|
|
|
|
_alpm_pkg_free(copy);
|
|
|
|
alpm_list_free(rem);
|
|
|
|
return -1;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
2016-05-23 08:27:29 -04:00
|
|
|
*targs = alpm_list_add(*targs, copy);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
2016-05-23 08:27:29 -04:00
|
|
|
alpm_list_free(rem);
|
|
|
|
|
2011-08-19 12:06:55 -04:00
|
|
|
return 0;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2009-02-22 05:25:32 -05:00
|
|
|
/**
|
|
|
|
* helper function for resolvedeps: search for dep satisfier in dbs
|
|
|
|
*
|
2011-06-07 15:05:42 -04:00
|
|
|
* @param handle the context handle
|
2009-02-22 05:25:32 -05:00
|
|
|
* @param dep is the dependency to search for
|
|
|
|
* @param dbs are the databases to search
|
|
|
|
* @param excluding are the packages to exclude from the search
|
|
|
|
* @param prompt if true, will cause an unresolvable dependency to issue an
|
|
|
|
* interactive prompt asking whether the package should be removed from
|
|
|
|
* the transaction or the transaction aborted; if false, simply returns
|
|
|
|
* an error code without prompting
|
|
|
|
* @return the resolved package
|
|
|
|
**/
|
2011-06-28 00:29:55 -04:00
|
|
|
static alpm_pkg_t *resolvedep(alpm_handle_t *handle, alpm_depend_t *dep,
|
2011-06-07 15:05:42 -04:00
|
|
|
alpm_list_t *dbs, alpm_list_t *excluding, int prompt)
|
Resolvedeps rework
I divided resolvedeps into 2 functions. The new _alpm_resolvedep function
will resolve one dependency, for example the 'foo>=1.0-1' dependency. It
can be useful in sync_addtarget refactoring.
The resolvedeps parameters were changed, to be coherent with recursedeps:
* the target-list is an alpm_list* instead of alpm_list**. This is OK,
because alpm_list_add == alpm_list_add_last
* syncpkg param was removed. list contains the to-be-installed packages,
resolvedeps will add the required dependencies into this list
* trans param was removed, it was used in QUESTION() only, which can be used
on the main (handle->trans) transaction only (because the front-end cannot
access our pseudo-transactions at all!).
The patch fixes some wrong dynamic pmdepmissing_t usage.
I did a behavior change (and sync1003.py was modified accordingly), which
needs some explanation: The old resolvedeps didn't elect packages from
'remove' list. I've dropped this because I don't want that 2nd excluding
list param. In fact, in real life, we ~never need this rule. Resolvedeps is
called before checkconflicts, so only -Su's %REPLACES% packages are sitting
in 'remove' list. This means, that we have the replacement packages in our
target list. Usually "foo replaces bar" means, that bar isn't in our repos
any more, so resolvedeps *cannot* elect it; but usually it won't try it at
all, because foo is in the target list, and it is expected to satisfy
'bar>=1.0-1'-like dependencies too. Since checkdeps and checkconflicts is
done after resolvedeps, this cannot cause any harm.
Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu>
Signed-off-by: Dan McGee <dan@archlinux.org>
2008-07-05 19:22:13 -04:00
|
|
|
{
|
|
|
|
alpm_list_t *i, *j;
|
2008-11-09 11:34:49 -05:00
|
|
|
int ignored = 0;
|
2010-10-16 06:28:01 -04:00
|
|
|
|
|
|
|
alpm_list_t *providers = NULL;
|
|
|
|
int count;
|
|
|
|
|
Resolvedeps rework
I divided resolvedeps into 2 functions. The new _alpm_resolvedep function
will resolve one dependency, for example the 'foo>=1.0-1' dependency. It
can be useful in sync_addtarget refactoring.
The resolvedeps parameters were changed, to be coherent with recursedeps:
* the target-list is an alpm_list* instead of alpm_list**. This is OK,
because alpm_list_add == alpm_list_add_last
* syncpkg param was removed. list contains the to-be-installed packages,
resolvedeps will add the required dependencies into this list
* trans param was removed, it was used in QUESTION() only, which can be used
on the main (handle->trans) transaction only (because the front-end cannot
access our pseudo-transactions at all!).
The patch fixes some wrong dynamic pmdepmissing_t usage.
I did a behavior change (and sync1003.py was modified accordingly), which
needs some explanation: The old resolvedeps didn't elect packages from
'remove' list. I've dropped this because I don't want that 2nd excluding
list param. In fact, in real life, we ~never need this rule. Resolvedeps is
called before checkconflicts, so only -Su's %REPLACES% packages are sitting
in 'remove' list. This means, that we have the replacement packages in our
target list. Usually "foo replaces bar" means, that bar isn't in our repos
any more, so resolvedeps *cannot* elect it; but usually it won't try it at
all, because foo is in the target list, and it is expected to satisfy
'bar>=1.0-1'-like dependencies too. Since checkdeps and checkconflicts is
done after resolvedeps, this cannot cause any harm.
Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu>
Signed-off-by: Dan McGee <dan@archlinux.org>
2008-07-05 19:22:13 -04:00
|
|
|
/* 1. literals */
|
|
|
|
for(i = dbs; i; i = i->next) {
|
2013-03-09 18:28:28 -05:00
|
|
|
alpm_pkg_t *pkg;
|
|
|
|
alpm_db_t *db = i->data;
|
|
|
|
|
|
|
|
if(!(db->usage & (ALPM_DB_USAGE_INSTALL|ALPM_DB_USAGE_UPGRADE))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
pkg = _alpm_db_get_pkgfromcache(db, dep->name);
|
2011-08-18 01:24:41 -04:00
|
|
|
if(pkg && _alpm_depcmp_literal(pkg, dep)
|
2012-08-12 06:48:53 -04:00
|
|
|
&& !alpm_pkg_find(excluding, pkg->name)) {
|
2013-10-15 22:23:11 -04:00
|
|
|
if(alpm_pkg_should_ignore(handle, pkg)) {
|
2014-06-15 13:42:40 -04:00
|
|
|
alpm_question_install_ignorepkg_t question = {
|
|
|
|
.type = ALPM_QUESTION_INSTALL_IGNOREPKG,
|
|
|
|
.install = 0,
|
|
|
|
.pkg = pkg
|
|
|
|
};
|
2011-04-20 20:45:16 -04:00
|
|
|
if(prompt) {
|
2014-06-15 13:42:40 -04:00
|
|
|
QUESTION(handle, &question);
|
2009-03-04 14:34:06 -05:00
|
|
|
} else {
|
2011-08-18 01:24:41 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_WARNING, _("ignoring package %s-%s\n"),
|
|
|
|
pkg->name, pkg->version);
|
2009-02-22 05:25:32 -05:00
|
|
|
}
|
2014-06-15 13:42:40 -04:00
|
|
|
if(!question.install) {
|
2008-11-09 11:34:49 -05:00
|
|
|
ignored = 1;
|
Resolvedeps rework
I divided resolvedeps into 2 functions. The new _alpm_resolvedep function
will resolve one dependency, for example the 'foo>=1.0-1' dependency. It
can be useful in sync_addtarget refactoring.
The resolvedeps parameters were changed, to be coherent with recursedeps:
* the target-list is an alpm_list* instead of alpm_list**. This is OK,
because alpm_list_add == alpm_list_add_last
* syncpkg param was removed. list contains the to-be-installed packages,
resolvedeps will add the required dependencies into this list
* trans param was removed, it was used in QUESTION() only, which can be used
on the main (handle->trans) transaction only (because the front-end cannot
access our pseudo-transactions at all!).
The patch fixes some wrong dynamic pmdepmissing_t usage.
I did a behavior change (and sync1003.py was modified accordingly), which
needs some explanation: The old resolvedeps didn't elect packages from
'remove' list. I've dropped this because I don't want that 2nd excluding
list param. In fact, in real life, we ~never need this rule. Resolvedeps is
called before checkconflicts, so only -Su's %REPLACES% packages are sitting
in 'remove' list. This means, that we have the replacement packages in our
target list. Usually "foo replaces bar" means, that bar isn't in our repos
any more, so resolvedeps *cannot* elect it; but usually it won't try it at
all, because foo is in the target list, and it is expected to satisfy
'bar>=1.0-1'-like dependencies too. Since checkdeps and checkconflicts is
done after resolvedeps, this cannot cause any harm.
Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu>
Signed-off-by: Dan McGee <dan@archlinux.org>
2008-07-05 19:22:13 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2011-03-20 20:45:57 -04:00
|
|
|
return pkg;
|
Resolvedeps rework
I divided resolvedeps into 2 functions. The new _alpm_resolvedep function
will resolve one dependency, for example the 'foo>=1.0-1' dependency. It
can be useful in sync_addtarget refactoring.
The resolvedeps parameters were changed, to be coherent with recursedeps:
* the target-list is an alpm_list* instead of alpm_list**. This is OK,
because alpm_list_add == alpm_list_add_last
* syncpkg param was removed. list contains the to-be-installed packages,
resolvedeps will add the required dependencies into this list
* trans param was removed, it was used in QUESTION() only, which can be used
on the main (handle->trans) transaction only (because the front-end cannot
access our pseudo-transactions at all!).
The patch fixes some wrong dynamic pmdepmissing_t usage.
I did a behavior change (and sync1003.py was modified accordingly), which
needs some explanation: The old resolvedeps didn't elect packages from
'remove' list. I've dropped this because I don't want that 2nd excluding
list param. In fact, in real life, we ~never need this rule. Resolvedeps is
called before checkconflicts, so only -Su's %REPLACES% packages are sitting
in 'remove' list. This means, that we have the replacement packages in our
target list. Usually "foo replaces bar" means, that bar isn't in our repos
any more, so resolvedeps *cannot* elect it; but usually it won't try it at
all, because foo is in the target list, and it is expected to satisfy
'bar>=1.0-1'-like dependencies too. Since checkdeps and checkconflicts is
done after resolvedeps, this cannot cause any harm.
Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu>
Signed-off-by: Dan McGee <dan@archlinux.org>
2008-07-05 19:22:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* 2. satisfiers (skip literals here) */
|
|
|
|
for(i = dbs; i; i = i->next) {
|
2013-03-09 18:28:28 -05:00
|
|
|
alpm_db_t *db = i->data;
|
|
|
|
if(!(db->usage & (ALPM_DB_USAGE_INSTALL|ALPM_DB_USAGE_UPGRADE))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for(j = _alpm_db_get_pkgcache(db); j; j = j->next) {
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *pkg = j->data;
|
2011-08-18 01:24:41 -04:00
|
|
|
/* with hash != hash, we can even skip the strcmp() as we know they can't
|
|
|
|
* possibly be the same string */
|
|
|
|
if(pkg->name_hash != dep->name_hash && _alpm_depcmp(pkg, dep)
|
2012-08-12 06:48:53 -04:00
|
|
|
&& !alpm_pkg_find(excluding, pkg->name)) {
|
2013-10-15 22:23:11 -04:00
|
|
|
if(alpm_pkg_should_ignore(handle, pkg)) {
|
2014-06-15 13:42:40 -04:00
|
|
|
alpm_question_install_ignorepkg_t question = {
|
|
|
|
.type = ALPM_QUESTION_INSTALL_IGNOREPKG,
|
|
|
|
.install = 0,
|
|
|
|
.pkg = pkg
|
|
|
|
};
|
2011-04-20 20:45:16 -04:00
|
|
|
if(prompt) {
|
2014-06-15 13:42:40 -04:00
|
|
|
QUESTION(handle, &question);
|
2009-03-04 14:34:06 -05:00
|
|
|
} else {
|
2011-08-18 01:24:41 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_WARNING, _("ignoring package %s-%s\n"),
|
|
|
|
pkg->name, pkg->version);
|
2009-02-22 05:25:32 -05:00
|
|
|
}
|
2014-06-15 13:42:40 -04:00
|
|
|
if(!question.install) {
|
2008-11-09 11:34:49 -05:00
|
|
|
ignored = 1;
|
Resolvedeps rework
I divided resolvedeps into 2 functions. The new _alpm_resolvedep function
will resolve one dependency, for example the 'foo>=1.0-1' dependency. It
can be useful in sync_addtarget refactoring.
The resolvedeps parameters were changed, to be coherent with recursedeps:
* the target-list is an alpm_list* instead of alpm_list**. This is OK,
because alpm_list_add == alpm_list_add_last
* syncpkg param was removed. list contains the to-be-installed packages,
resolvedeps will add the required dependencies into this list
* trans param was removed, it was used in QUESTION() only, which can be used
on the main (handle->trans) transaction only (because the front-end cannot
access our pseudo-transactions at all!).
The patch fixes some wrong dynamic pmdepmissing_t usage.
I did a behavior change (and sync1003.py was modified accordingly), which
needs some explanation: The old resolvedeps didn't elect packages from
'remove' list. I've dropped this because I don't want that 2nd excluding
list param. In fact, in real life, we ~never need this rule. Resolvedeps is
called before checkconflicts, so only -Su's %REPLACES% packages are sitting
in 'remove' list. This means, that we have the replacement packages in our
target list. Usually "foo replaces bar" means, that bar isn't in our repos
any more, so resolvedeps *cannot* elect it; but usually it won't try it at
all, because foo is in the target list, and it is expected to satisfy
'bar>=1.0-1'-like dependencies too. Since checkdeps and checkconflicts is
done after resolvedeps, this cannot cause any harm.
Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu>
Signed-off-by: Dan McGee <dan@archlinux.org>
2008-07-05 19:22:13 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "provider found (%s provides %s)\n",
|
2010-10-16 06:28:01 -04:00
|
|
|
pkg->name, dep->name);
|
|
|
|
providers = alpm_list_add(providers, pkg);
|
|
|
|
/* keep looking for other providers in the all dbs */
|
Resolvedeps rework
I divided resolvedeps into 2 functions. The new _alpm_resolvedep function
will resolve one dependency, for example the 'foo>=1.0-1' dependency. It
can be useful in sync_addtarget refactoring.
The resolvedeps parameters were changed, to be coherent with recursedeps:
* the target-list is an alpm_list* instead of alpm_list**. This is OK,
because alpm_list_add == alpm_list_add_last
* syncpkg param was removed. list contains the to-be-installed packages,
resolvedeps will add the required dependencies into this list
* trans param was removed, it was used in QUESTION() only, which can be used
on the main (handle->trans) transaction only (because the front-end cannot
access our pseudo-transactions at all!).
The patch fixes some wrong dynamic pmdepmissing_t usage.
I did a behavior change (and sync1003.py was modified accordingly), which
needs some explanation: The old resolvedeps didn't elect packages from
'remove' list. I've dropped this because I don't want that 2nd excluding
list param. In fact, in real life, we ~never need this rule. Resolvedeps is
called before checkconflicts, so only -Su's %REPLACES% packages are sitting
in 'remove' list. This means, that we have the replacement packages in our
target list. Usually "foo replaces bar" means, that bar isn't in our repos
any more, so resolvedeps *cannot* elect it; but usually it won't try it at
all, because foo is in the target list, and it is expected to satisfy
'bar>=1.0-1'-like dependencies too. Since checkdeps and checkconflicts is
done after resolvedeps, this cannot cause any harm.
Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu>
Signed-off-by: Dan McGee <dan@archlinux.org>
2008-07-05 19:22:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-10-16 06:28:01 -04:00
|
|
|
|
|
|
|
/* first check if one provider is already installed locally */
|
|
|
|
for(i = providers; i; i = i->next) {
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *pkg = i->data;
|
2011-11-15 10:12:18 -05:00
|
|
|
if(_alpm_db_get_pkgfromcache(handle->db_local, pkg->name)) {
|
2010-10-16 06:28:01 -04:00
|
|
|
alpm_list_free(providers);
|
2011-03-20 20:45:57 -04:00
|
|
|
return pkg;
|
2010-10-16 06:28:01 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
count = alpm_list_count(providers);
|
2011-04-20 20:45:16 -04:00
|
|
|
if(count >= 1) {
|
2014-06-15 13:42:40 -04:00
|
|
|
alpm_question_select_provider_t question = {
|
|
|
|
.type = ALPM_QUESTION_SELECT_PROVIDER,
|
|
|
|
/* default to first provider if there is no QUESTION callback */
|
|
|
|
.use_index = 0,
|
|
|
|
.providers = providers,
|
|
|
|
.depend = dep
|
|
|
|
};
|
2010-10-16 06:28:01 -04:00
|
|
|
if(count > 1) {
|
|
|
|
/* if there is more than one provider, we ask the user */
|
2014-06-15 13:42:40 -04:00
|
|
|
QUESTION(handle, &question);
|
2010-10-16 06:28:01 -04:00
|
|
|
}
|
2014-06-15 13:42:40 -04:00
|
|
|
if(question.use_index >= 0 && question.use_index < count) {
|
|
|
|
alpm_list_t *nth = alpm_list_nth(providers, question.use_index);
|
2011-09-19 15:32:53 -04:00
|
|
|
alpm_pkg_t *pkg = nth->data;
|
2010-10-16 06:28:01 -04:00
|
|
|
alpm_list_free(providers);
|
2011-03-20 20:45:57 -04:00
|
|
|
return pkg;
|
2010-10-16 06:28:01 -04:00
|
|
|
}
|
|
|
|
alpm_list_free(providers);
|
|
|
|
providers = NULL;
|
|
|
|
}
|
|
|
|
|
2008-11-09 11:34:49 -05:00
|
|
|
if(ignored) { /* resolvedeps will override these */
|
2011-07-01 12:01:39 -04:00
|
|
|
handle->pm_errno = ALPM_ERR_PKG_IGNORED;
|
2008-11-09 11:34:49 -05:00
|
|
|
} else {
|
2011-07-01 12:01:39 -04:00
|
|
|
handle->pm_errno = ALPM_ERR_PKG_NOT_FOUND;
|
2008-11-09 11:34:49 -05:00
|
|
|
}
|
2011-03-20 20:45:57 -04:00
|
|
|
return NULL;
|
Resolvedeps rework
I divided resolvedeps into 2 functions. The new _alpm_resolvedep function
will resolve one dependency, for example the 'foo>=1.0-1' dependency. It
can be useful in sync_addtarget refactoring.
The resolvedeps parameters were changed, to be coherent with recursedeps:
* the target-list is an alpm_list* instead of alpm_list**. This is OK,
because alpm_list_add == alpm_list_add_last
* syncpkg param was removed. list contains the to-be-installed packages,
resolvedeps will add the required dependencies into this list
* trans param was removed, it was used in QUESTION() only, which can be used
on the main (handle->trans) transaction only (because the front-end cannot
access our pseudo-transactions at all!).
The patch fixes some wrong dynamic pmdepmissing_t usage.
I did a behavior change (and sync1003.py was modified accordingly), which
needs some explanation: The old resolvedeps didn't elect packages from
'remove' list. I've dropped this because I don't want that 2nd excluding
list param. In fact, in real life, we ~never need this rule. Resolvedeps is
called before checkconflicts, so only -Su's %REPLACES% packages are sitting
in 'remove' list. This means, that we have the replacement packages in our
target list. Usually "foo replaces bar" means, that bar isn't in our repos
any more, so resolvedeps *cannot* elect it; but usually it won't try it at
all, because foo is in the target list, and it is expected to satisfy
'bar>=1.0-1'-like dependencies too. Since checkdeps and checkconflicts is
done after resolvedeps, this cannot cause any harm.
Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu>
Signed-off-by: Dan McGee <dan@archlinux.org>
2008-07-05 19:22:13 -04:00
|
|
|
}
|
|
|
|
|
2011-03-25 15:38:39 -04:00
|
|
|
/** Find a package satisfying a specified dependency.
|
|
|
|
* First look for a literal, going through each db one by one. Then look for
|
|
|
|
* providers. The first satisfier found is returned.
|
|
|
|
* The dependency can include versions with depmod operators.
|
2011-06-07 15:05:42 -04:00
|
|
|
* @param handle the context handle
|
2011-06-28 00:11:43 -04:00
|
|
|
* @param dbs an alpm_list_t* of alpm_db_t where the satisfier will be searched
|
2011-03-25 15:38:39 -04:00
|
|
|
* @param depstring package or provision name, versioned or not
|
2011-06-28 09:26:39 -04:00
|
|
|
* @return a alpm_pkg_t* satisfying depstring
|
2011-03-25 15:38:39 -04:00
|
|
|
*/
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t SYMEXPORT *alpm_find_dbs_satisfier(alpm_handle_t *handle,
|
2011-06-07 15:05:42 -04:00
|
|
|
alpm_list_t *dbs, const char *depstring)
|
2011-03-25 15:38:39 -04:00
|
|
|
{
|
2011-06-28 00:29:55 -04:00
|
|
|
alpm_depend_t *dep;
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *pkg;
|
2011-03-25 15:38:39 -04:00
|
|
|
|
2011-06-14 11:01:08 -04:00
|
|
|
CHECK_HANDLE(handle, return NULL);
|
2011-07-01 12:01:39 -04:00
|
|
|
ASSERT(dbs, RET_ERR(handle, ALPM_ERR_WRONG_ARGS, NULL));
|
2011-03-25 15:38:39 -04:00
|
|
|
|
2014-09-15 12:06:47 -04:00
|
|
|
dep = alpm_dep_from_string(depstring);
|
2011-03-27 21:41:23 -04:00
|
|
|
ASSERT(dep, return NULL);
|
2011-06-07 15:05:42 -04:00
|
|
|
pkg = resolvedep(handle, dep, dbs, NULL, 1);
|
2014-09-15 12:06:47 -04:00
|
|
|
alpm_dep_free(dep);
|
2011-03-27 21:41:23 -04:00
|
|
|
return pkg;
|
2011-03-25 15:38:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Computes resolvable dependencies for a given package and adds that package
|
2009-01-26 07:48:39 -05:00
|
|
|
* and those resolvable dependencies to a list.
|
2005-03-14 20:51:43 -05:00
|
|
|
*
|
2011-06-07 15:05:42 -04:00
|
|
|
* @param handle the context handle
|
2010-05-16 20:33:28 -04:00
|
|
|
* @param localpkgs is the list of local packages
|
2009-01-26 07:48:39 -05:00
|
|
|
* @param pkg is the package to resolve
|
2011-09-22 17:29:03 -04:00
|
|
|
* @param preferred packages to prefer when resolving
|
2009-01-26 07:48:39 -05:00
|
|
|
* @param packages is a pointer to a list of packages which will be
|
|
|
|
* searched first for any dependency packages needed to complete the
|
|
|
|
* resolve, and to which will be added any [pkg] and all of its
|
|
|
|
* dependencies not already on the list
|
|
|
|
* @param remove is the set of packages which will be removed in this
|
|
|
|
* transaction
|
|
|
|
* @param data returns the dependency which could not be satisfied in the
|
|
|
|
* event of an error
|
|
|
|
* @return 0 on success, with [pkg] and all of its dependencies not already on
|
|
|
|
* the [*packages] list added to that list, or -1 on failure due to an
|
|
|
|
* unresolvable dependency, in which case the [*packages] list will be
|
|
|
|
* unmodified by this function
|
2005-03-14 20:51:43 -05:00
|
|
|
*/
|
2011-08-11 00:28:57 -04:00
|
|
|
int _alpm_resolvedeps(alpm_handle_t *handle, alpm_list_t *localpkgs,
|
|
|
|
alpm_pkg_t *pkg, alpm_list_t *preferred, alpm_list_t **packages,
|
2012-05-08 17:23:58 -04:00
|
|
|
alpm_list_t *rem, alpm_list_t **data)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
2011-02-25 08:55:16 -05:00
|
|
|
int ret = 0;
|
2012-09-16 12:53:40 -04:00
|
|
|
alpm_list_t *j;
|
2007-01-19 04:28:44 -05:00
|
|
|
alpm_list_t *targ;
|
|
|
|
alpm_list_t *deps = NULL;
|
2009-01-26 07:48:39 -05:00
|
|
|
alpm_list_t *packages_copy;
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2012-08-12 06:48:53 -04:00
|
|
|
if(alpm_pkg_find(*packages, pkg->name) != NULL) {
|
2011-03-20 20:45:57 -04:00
|
|
|
return 0;
|
2009-01-26 07:48:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Create a copy of the packages list, so that it can be restored
|
|
|
|
on error */
|
|
|
|
packages_copy = alpm_list_copy(*packages);
|
|
|
|
/* [pkg] has not already been resolved into the packages list, so put it
|
|
|
|
on that list */
|
|
|
|
*packages = alpm_list_add(*packages, pkg);
|
|
|
|
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "started resolving dependencies\n");
|
2012-09-16 12:53:40 -04:00
|
|
|
targ = alpm_list_add(NULL, pkg);
|
|
|
|
deps = alpm_checkdeps(handle, localpkgs, rem, targ, 0);
|
|
|
|
alpm_list_free(targ);
|
|
|
|
targ = NULL;
|
|
|
|
|
|
|
|
for(j = deps; j; j = j->next) {
|
|
|
|
alpm_depmissing_t *miss = j->data;
|
|
|
|
alpm_depend_t *missdep = miss->depend;
|
|
|
|
/* check if one of the packages in the [*packages] list already satisfies
|
|
|
|
* this dependency */
|
|
|
|
if(find_dep_satisfier(*packages, missdep)) {
|
2014-02-03 12:09:18 -05:00
|
|
|
alpm_depmissing_free(miss);
|
2012-09-16 12:53:40 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* check if one of the packages in the [preferred] list already satisfies
|
|
|
|
* this dependency */
|
|
|
|
alpm_pkg_t *spkg = find_dep_satisfier(preferred, missdep);
|
|
|
|
if(!spkg) {
|
|
|
|
/* find a satisfier package in the given repositories */
|
|
|
|
spkg = resolvedep(handle, missdep, handle->dbs_sync, *packages, 0);
|
|
|
|
}
|
|
|
|
if(spkg && _alpm_resolvedeps(handle, localpkgs, spkg, preferred, packages, rem, data) == 0) {
|
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG,
|
|
|
|
"pulling dependency %s (needed by %s)\n",
|
|
|
|
spkg->name, pkg->name);
|
2014-02-03 12:09:18 -05:00
|
|
|
alpm_depmissing_free(miss);
|
2012-09-16 12:53:40 -04:00
|
|
|
} else if(resolvedep(handle, missdep, (targ = alpm_list_add(NULL, handle->db_local)), rem, 0)) {
|
2014-02-03 12:09:18 -05:00
|
|
|
alpm_depmissing_free(miss);
|
2012-09-16 12:53:40 -04:00
|
|
|
} else {
|
|
|
|
handle->pm_errno = ALPM_ERR_UNSATISFIED_DEPS;
|
|
|
|
char *missdepstring = alpm_dep_compute_string(missdep);
|
|
|
|
_alpm_log(handle, ALPM_LOG_WARNING,
|
|
|
|
_("cannot resolve \"%s\", a dependency of \"%s\"\n"),
|
|
|
|
missdepstring, pkg->name);
|
|
|
|
free(missdepstring);
|
|
|
|
if(data) {
|
|
|
|
*data = alpm_list_add(*data, miss);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
2012-09-16 12:53:40 -04:00
|
|
|
ret = -1;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
2014-01-06 11:52:25 -05:00
|
|
|
alpm_list_free(targ);
|
|
|
|
targ = NULL;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
2012-09-16 12:53:40 -04:00
|
|
|
alpm_list_free(deps);
|
2011-02-25 08:55:16 -05:00
|
|
|
|
|
|
|
if(ret != 0) {
|
|
|
|
alpm_list_free(*packages);
|
|
|
|
*packages = packages_copy;
|
|
|
|
} else {
|
|
|
|
alpm_list_free(packages_copy);
|
|
|
|
}
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "finished resolving dependencies\n");
|
2011-03-20 20:45:57 -04:00
|
|
|
return ret;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2011-06-28 00:29:55 -04:00
|
|
|
/** Reverse of splitdep; make a dep string from a alpm_depend_t struct.
|
2007-11-12 23:48:15 -05:00
|
|
|
* The string must be freed!
|
|
|
|
* @param dep the depend to turn into a string
|
|
|
|
* @return a string-formatted dependency with operator if necessary
|
|
|
|
*/
|
2011-06-28 00:29:55 -04:00
|
|
|
char SYMEXPORT *alpm_dep_compute_string(const alpm_depend_t *dep)
|
2007-10-24 20:31:28 -04:00
|
|
|
{
|
2011-12-12 14:34:48 -05:00
|
|
|
const char *name, *opr, *ver, *desc_delim, *desc;
|
2011-03-25 15:51:31 -04:00
|
|
|
char *str;
|
2007-11-12 23:48:15 -05:00
|
|
|
size_t len;
|
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
ASSERT(dep != NULL, return NULL);
|
2007-10-24 20:31:28 -04:00
|
|
|
|
2008-01-11 01:01:58 -05:00
|
|
|
if(dep->name) {
|
|
|
|
name = dep->name;
|
|
|
|
} else {
|
|
|
|
name = "";
|
|
|
|
}
|
|
|
|
|
2007-10-24 20:31:28 -04:00
|
|
|
switch(dep->mod) {
|
2011-07-01 12:01:38 -04:00
|
|
|
case ALPM_DEP_MOD_ANY:
|
2007-11-12 23:48:15 -05:00
|
|
|
opr = "";
|
2007-10-24 20:31:28 -04:00
|
|
|
break;
|
2011-07-01 12:01:38 -04:00
|
|
|
case ALPM_DEP_MOD_GE:
|
2007-11-12 23:48:15 -05:00
|
|
|
opr = ">=";
|
2007-10-24 20:31:28 -04:00
|
|
|
break;
|
2011-07-01 12:01:38 -04:00
|
|
|
case ALPM_DEP_MOD_LE:
|
2007-11-12 23:48:15 -05:00
|
|
|
opr = "<=";
|
|
|
|
break;
|
2011-07-01 12:01:38 -04:00
|
|
|
case ALPM_DEP_MOD_EQ:
|
2007-11-12 23:48:15 -05:00
|
|
|
opr = "=";
|
|
|
|
break;
|
2011-07-01 12:01:38 -04:00
|
|
|
case ALPM_DEP_MOD_LT:
|
2007-12-18 08:24:44 -05:00
|
|
|
opr = "<";
|
|
|
|
break;
|
2011-07-01 12:01:38 -04:00
|
|
|
case ALPM_DEP_MOD_GT:
|
2007-12-18 08:24:44 -05:00
|
|
|
opr = ">";
|
|
|
|
break;
|
2007-11-12 23:48:15 -05:00
|
|
|
default:
|
|
|
|
opr = "";
|
2007-10-24 20:31:28 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-07-01 12:01:38 -04:00
|
|
|
if(dep->mod != ALPM_DEP_MOD_ANY && dep->version) {
|
2008-01-11 01:01:58 -05:00
|
|
|
ver = dep->version;
|
|
|
|
} else {
|
|
|
|
ver = "";
|
|
|
|
}
|
|
|
|
|
2011-12-12 14:34:48 -05:00
|
|
|
if(dep->desc) {
|
|
|
|
desc_delim = ": ";
|
|
|
|
desc = dep->desc;
|
|
|
|
} else {
|
|
|
|
desc_delim = "";
|
|
|
|
desc = "";
|
|
|
|
}
|
|
|
|
|
2007-11-12 23:48:15 -05:00
|
|
|
/* we can always compute len and print the string like this because opr
|
2011-07-01 12:01:38 -04:00
|
|
|
* and ver will be empty when ALPM_DEP_MOD_ANY is the depend type. the
|
2008-01-11 01:01:58 -05:00
|
|
|
* reassignments above also ensure we do not do a strlen(NULL). */
|
2011-12-12 14:34:48 -05:00
|
|
|
len = strlen(name) + strlen(opr) + strlen(ver)
|
|
|
|
+ strlen(desc_delim) + strlen(desc) + 1;
|
2011-06-07 17:06:16 -04:00
|
|
|
MALLOC(str, len, return NULL);
|
2011-12-12 14:34:48 -05:00
|
|
|
snprintf(str, len, "%s%s%s%s%s", name, opr, ver, desc_delim, desc);
|
2007-11-12 23:48:15 -05:00
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return str;
|
2007-10-24 20:31:28 -04:00
|
|
|
}
|
2014-01-22 18:06:11 -05:00
|
|
|
/* vim: set noet: */
|