4 * Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>
5 * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
6 * Copyright (c) 2005 by Aurelien Foret <orelien@chez.com>
7 * Copyright (c) 2005, 2006 by Miklos Vajna <vmiklos@frugalware.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 #include "alpm_list.h"
40 void _alpm_dep_free(pmdepend_t
*dep
)
47 static pmdepmissing_t
*depmiss_new(const char *target
, pmdepend_t
*dep
,
48 const char *causingpkg
)
52 MALLOC(miss
, sizeof(pmdepmissing_t
), return NULL
);
54 STRDUP(miss
->target
, target
, return NULL
);
55 miss
->depend
= _alpm_dep_dup(dep
);
56 STRDUP(miss
->causingpkg
, causingpkg
, return NULL
);
61 void _alpm_depmiss_free(pmdepmissing_t
*miss
)
63 _alpm_dep_free(miss
->depend
);
65 FREE(miss
->causingpkg
);
69 /* Does pkg1 depend on pkg2, ie. does pkg2 satisfy a dependency of pkg1? */
70 static int _alpm_dep_edge(pmpkg_t
*pkg1
, pmpkg_t
*pkg2
)
73 for(i
= alpm_pkg_get_depends(pkg1
); i
; i
= i
->next
) {
74 if(_alpm_depcmp(pkg2
, i
->data
)) {
81 /* Convert a list of pmpkg_t * to a graph structure,
82 * with a edge for each dependency.
83 * Returns a list of vertices (one vertex = one package)
84 * (used by alpm_sortbydeps)
86 static alpm_list_t
*dep_graph_init(alpm_list_t
*targets
)
89 alpm_list_t
*vertices
= NULL
;
90 /* We create the vertices */
91 for(i
= targets
; i
; i
= i
->next
) {
92 pmgraph_t
*vertex
= _alpm_graph_new();
93 vertex
->data
= (void *)i
->data
;
94 vertices
= alpm_list_add(vertices
, vertex
);
97 /* We compute the edges */
98 for(i
= vertices
; i
; i
= i
->next
) {
99 pmgraph_t
*vertex_i
= i
->data
;
100 pmpkg_t
*p_i
= vertex_i
->data
;
101 /* TODO this should be somehow combined with alpm_checkdeps */
102 for(j
= vertices
; j
; j
= j
->next
) {
103 pmgraph_t
*vertex_j
= j
->data
;
104 pmpkg_t
*p_j
= vertex_j
->data
;
105 if(_alpm_dep_edge(p_i
, p_j
)) {
107 alpm_list_add(vertex_i
->children
, vertex_j
);
110 vertex_i
->childptr
= vertex_i
->children
;
115 /* Re-order a list of target packages with respect to their dependencies.
117 * Example (reverse == 0):
120 * Target order is A,B,C,D
122 * Should be re-ordered to C,A,B,D
124 * if reverse is > 0, the dependency order will be reversed.
126 * This function returns the new alpm_list_t* target list.
129 alpm_list_t
*_alpm_sortbydeps(pmhandle_t
*handle
,
130 alpm_list_t
*targets
, int reverse
)
132 alpm_list_t
*newtargs
= NULL
;
133 alpm_list_t
*vertices
= NULL
;
137 if(targets
== NULL
) {
141 _alpm_log(handle
, PM_LOG_DEBUG
, "started sorting dependencies\n");
143 vertices
= dep_graph_init(targets
);
146 vertex
= vertices
->data
;
148 /* mark that we touched the vertex */
151 while(vertex
->childptr
&& !found
) {
152 pmgraph_t
*nextchild
= vertex
->childptr
->data
;
153 vertex
->childptr
= vertex
->childptr
->next
;
154 if(nextchild
->state
== 0) {
156 nextchild
->parent
= vertex
;
159 else if(nextchild
->state
== -1) {
160 pmpkg_t
*vertexpkg
= vertex
->data
;
161 pmpkg_t
*childpkg
= nextchild
->data
;
164 _alpm_log(handle
, PM_LOG_WARNING
, _("dependency cycle detected:\n"));
166 message
=_("%s will be removed after its %s dependency\n");
168 message
=_("%s will be installed before its %s dependency\n");
170 _alpm_log(handle
, PM_LOG_WARNING
, message
, vertexpkg
->name
, childpkg
->name
);
174 newtargs
= alpm_list_add(newtargs
, vertex
->data
);
175 /* mark that we've left this vertex */
177 vertex
= vertex
->parent
;
182 if(vertex
->state
== 0) break;
189 _alpm_log(handle
, PM_LOG_DEBUG
, "sorting dependencies finished\n");
192 /* reverse the order */
193 alpm_list_t
*tmptargs
= alpm_list_reverse(newtargs
);
194 /* free the old one */
195 alpm_list_free(newtargs
);
199 alpm_list_free_inner(vertices
, _alpm_graph_free
);
200 alpm_list_free(vertices
);
205 static int no_dep_version(pmhandle_t
*handle
)
207 int flags
= alpm_trans_get_flags(handle
);
208 return flags
!= -1 && (flags
& PM_TRANS_FLAG_NODEPVERSION
);
211 static pmdepend_t
*filtered_depend(pmdepend_t
*dep
, int nodepversion
)
214 pmdepend_t
*newdep
= _alpm_dep_dup(dep
);
215 ASSERT(newdep
, return dep
);
216 newdep
->mod
= PM_DEP_MOD_ANY
;
222 static void release_filtered_depend(pmdepend_t
*dep
, int nodepversion
)
229 static pmpkg_t
*find_dep_satisfier(alpm_list_t
*pkgs
, pmdepend_t
*dep
)
233 for(i
= pkgs
; i
; i
= alpm_list_next(i
)) {
234 pmpkg_t
*pkg
= i
->data
;
235 if(_alpm_depcmp(pkg
, dep
)) {
242 /** Find a package satisfying a specified dependency.
243 * The dependency can include versions with depmod operators.
244 * @param pkgs an alpm_list_t* of pmpkg_t where the satisfier will be searched
245 * @param depstring package or provision name, versioned or not
246 * @return a pmpkg_t* satisfying depstring
248 pmpkg_t SYMEXPORT
*alpm_find_satisfier(alpm_list_t
*pkgs
, const char *depstring
)
250 pmdepend_t
*dep
= _alpm_splitdep(depstring
);
254 pmpkg_t
*pkg
= find_dep_satisfier(pkgs
, dep
);
259 /** Checks dependencies and returns missing ones in a list.
260 * Dependencies can include versions with depmod operators.
261 * @param handle the context handle
262 * @param pkglist the list of local packages
263 * @param remove an alpm_list_t* of packages to be removed
264 * @param upgrade an alpm_list_t* of packages to be upgraded (remove-then-upgrade)
265 * @param reversedeps handles the backward dependencies
266 * @return an alpm_list_t* of pmdepmissing_t pointers.
268 alpm_list_t SYMEXPORT
*alpm_checkdeps(pmhandle_t
*handle
, alpm_list_t
*pkglist
,
269 alpm_list_t
*remove
, alpm_list_t
*upgrade
, int reversedeps
)
272 alpm_list_t
*targets
, *dblist
= NULL
, *modified
= NULL
;
273 alpm_list_t
*baddeps
= NULL
;
276 CHECK_HANDLE(handle
, return NULL
);
278 targets
= alpm_list_join(alpm_list_copy(remove
), alpm_list_copy(upgrade
));
279 for(i
= pkglist
; i
; i
= i
->next
) {
280 pmpkg_t
*pkg
= i
->data
;
281 if(_alpm_pkg_find(targets
, pkg
->name
)) {
282 modified
= alpm_list_add(modified
, pkg
);
284 dblist
= alpm_list_add(dblist
, pkg
);
287 alpm_list_free(targets
);
289 nodepversion
= no_dep_version(handle
);
291 /* look for unsatisfied dependencies of the upgrade list */
292 for(i
= upgrade
; i
; i
= i
->next
) {
293 pmpkg_t
*tp
= i
->data
;
294 _alpm_log(handle
, PM_LOG_DEBUG
, "checkdeps: package %s-%s\n",
295 alpm_pkg_get_name(tp
), alpm_pkg_get_version(tp
));
297 for(j
= alpm_pkg_get_depends(tp
); j
; j
= j
->next
) {
298 pmdepend_t
*depend
= j
->data
;
299 depend
= filtered_depend(depend
, nodepversion
);
300 /* 1. we check the upgrade list */
301 /* 2. we check database for untouched satisfying packages */
302 if(!find_dep_satisfier(upgrade
, depend
) &&
303 !find_dep_satisfier(dblist
, depend
)) {
304 /* Unsatisfied dependency in the upgrade list */
305 pmdepmissing_t
*miss
;
306 char *missdepstring
= alpm_dep_compute_string(depend
);
307 _alpm_log(handle
, PM_LOG_DEBUG
, "checkdeps: missing dependency '%s' for package '%s'\n",
308 missdepstring
, alpm_pkg_get_name(tp
));
310 miss
= depmiss_new(alpm_pkg_get_name(tp
), depend
, NULL
);
311 baddeps
= alpm_list_add(baddeps
, miss
);
313 release_filtered_depend(depend
, nodepversion
);
318 /* reversedeps handles the backwards dependencies, ie,
319 * the packages listed in the requiredby field. */
320 for(i
= dblist
; i
; i
= i
->next
) {
321 pmpkg_t
*lp
= i
->data
;
322 for(j
= alpm_pkg_get_depends(lp
); j
; j
= j
->next
) {
323 pmdepend_t
*depend
= j
->data
;
324 depend
= filtered_depend(depend
, nodepversion
);
325 pmpkg_t
*causingpkg
= find_dep_satisfier(modified
, depend
);
326 /* we won't break this depend, if it is already broken, we ignore it */
327 /* 1. check upgrade list for satisfiers */
328 /* 2. check dblist for satisfiers */
330 !find_dep_satisfier(upgrade
, depend
) &&
331 !find_dep_satisfier(dblist
, depend
)) {
332 pmdepmissing_t
*miss
;
333 char *missdepstring
= alpm_dep_compute_string(depend
);
334 _alpm_log(handle
, PM_LOG_DEBUG
, "checkdeps: transaction would break '%s' dependency of '%s'\n",
335 missdepstring
, alpm_pkg_get_name(lp
));
337 miss
= depmiss_new(lp
->name
, depend
, alpm_pkg_get_name(causingpkg
));
338 baddeps
= alpm_list_add(baddeps
, miss
);
340 release_filtered_depend(depend
, nodepversion
);
345 alpm_list_free(modified
);
346 alpm_list_free(dblist
);
351 static int dep_vercmp(const char *version1
, pmdepmod_t mod
,
352 const char *version2
)
356 if(mod
== PM_DEP_MOD_ANY
) {
359 int cmp
= alpm_pkg_vercmp(version1
, version2
);
361 case PM_DEP_MOD_EQ
: equal
= (cmp
== 0); break;
362 case PM_DEP_MOD_GE
: equal
= (cmp
>= 0); break;
363 case PM_DEP_MOD_LE
: equal
= (cmp
<= 0); break;
364 case PM_DEP_MOD_LT
: equal
= (cmp
< 0); break;
365 case PM_DEP_MOD_GT
: equal
= (cmp
> 0); break;
366 default: equal
= 1; break;
372 int _alpm_depcmp(pmpkg_t
*pkg
, pmdepend_t
*dep
)
377 /* check (pkg->name, pkg->version) */
378 if(pkg
->name_hash
&& dep
->name_hash
379 && pkg
->name_hash
!= dep
->name_hash
) {
380 /* skip more expensive checks */
382 satisfy
= (strcmp(pkg
->name
, dep
->name
) == 0
383 && dep_vercmp(pkg
->version
, dep
->mod
, dep
->version
));
389 /* check provisions, format : "name=version" */
390 for(i
= alpm_pkg_get_provides(pkg
); i
&& !satisfy
; i
= i
->next
) {
391 const char *provision
= i
->data
;
392 const char *provver
= strchr(provision
, '=');
394 if(provver
== NULL
) { /* no provision version */
395 satisfy
= (dep
->mod
== PM_DEP_MOD_ANY
396 && strcmp(provision
, dep
->name
) == 0);
398 /* This is a bit tricker than the old code for performance reasons. To
399 * prevent the need to copy and duplicate strings, strncmp only the name
400 * portion if they are the same length, since there is a version and
401 * operator in play here. Cast is to silence sign conversion warning;
402 * we know provver >= provision if we are here. */
403 size_t namelen
= (size_t)(provver
- provision
);
405 satisfy
= (strlen(dep
->name
) == namelen
406 && strncmp(provision
, dep
->name
, namelen
) == 0
407 && dep_vercmp(provver
, dep
->mod
, dep
->version
));
414 pmdepend_t
*_alpm_splitdep(const char *depstring
)
417 const char *ptr
, *version
= NULL
;
419 if(depstring
== NULL
) {
423 CALLOC(depend
, 1, sizeof(pmdepend_t
), return NULL
);
425 /* Find a version comparator if one exists. If it does, set the type and
426 * increment the ptr accordingly so we can copy the right strings. */
427 if((ptr
= strstr(depstring
, ">="))) {
428 depend
->mod
= PM_DEP_MOD_GE
;
430 } else if((ptr
= strstr(depstring
, "<="))) {
431 depend
->mod
= PM_DEP_MOD_LE
;
433 } else if((ptr
= strstr(depstring
, "="))) {
434 /* Note: we must do =,<,> checks after <=, >= checks */
435 depend
->mod
= PM_DEP_MOD_EQ
;
437 } else if((ptr
= strstr(depstring
, "<"))) {
438 depend
->mod
= PM_DEP_MOD_LT
;
440 } else if((ptr
= strstr(depstring
, ">"))) {
441 depend
->mod
= PM_DEP_MOD_GT
;
444 /* no version specified, leave version and ptr NULL */
445 depend
->mod
= PM_DEP_MOD_ANY
;
448 /* copy the right parts to the right places */
449 STRNDUP(depend
->name
, depstring
, ptr
- depstring
, return NULL
);
450 depend
->name_hash
= _alpm_hash_sdbm(depend
->name
);
452 STRDUP(depend
->version
, version
, return NULL
);
458 pmdepend_t
*_alpm_dep_dup(const pmdepend_t
*dep
)
461 CALLOC(newdep
, 1, sizeof(pmdepend_t
), return NULL
);
463 STRDUP(newdep
->name
, dep
->name
, return NULL
);
464 newdep
->name_hash
= dep
->name_hash
;
465 STRDUP(newdep
->version
, dep
->version
, return NULL
);
466 newdep
->mod
= dep
->mod
;
471 /* These parameters are messy. We check if this package, given a list of
472 * targets and a db is safe to remove. We do NOT remove it if it is in the
473 * target list, or if if the package was explictly installed and
474 * include_explicit == 0 */
475 static int can_remove_package(pmdb_t
*db
, pmpkg_t
*pkg
, alpm_list_t
*targets
,
476 int include_explicit
)
480 if(_alpm_pkg_find(targets
, alpm_pkg_get_name(pkg
))) {
484 if(!include_explicit
) {
485 /* see if it was explicitly installed */
486 if(alpm_pkg_get_reason(pkg
) == PM_PKG_REASON_EXPLICIT
) {
487 _alpm_log(db
->handle
, PM_LOG_DEBUG
, "excluding %s -- explicitly installed\n",
488 alpm_pkg_get_name(pkg
));
493 /* TODO: checkdeps could be used here, it handles multiple providers
494 * better, but that also makes it slower.
495 * Also this would require to first add the package to the targets list,
496 * then call checkdeps with it, then remove the package from the targets list
497 * if checkdeps detected it would break something */
499 /* see if other packages need it */
500 for(i
= _alpm_db_get_pkgcache(db
); i
; i
= i
->next
) {
501 pmpkg_t
*lpkg
= i
->data
;
502 if(_alpm_dep_edge(lpkg
, pkg
) && !_alpm_pkg_find(targets
, lpkg
->name
)) {
507 /* it's ok to remove */
512 * @brief Adds unneeded dependencies to an existing list of packages.
513 * By unneeded, we mean dependencies that are only required by packages in the
514 * target list, so they can be safely removed.
515 * If the input list was topo sorted, the output list will be topo sorted too.
517 * @param db package database to do dependency tracing in
518 * @param *targs pointer to a list of packages
519 * @param include_explicit if 0, explicitly installed packages are not included
521 void _alpm_recursedeps(pmdb_t
*db
, alpm_list_t
*targs
, int include_explicit
)
525 if(db
== NULL
|| targs
== NULL
) {
529 for(i
= targs
; i
; i
= i
->next
) {
530 pmpkg_t
*pkg
= i
->data
;
531 for(j
= _alpm_db_get_pkgcache(db
); j
; j
= j
->next
) {
532 pmpkg_t
*deppkg
= j
->data
;
533 if(_alpm_dep_edge(pkg
, deppkg
)
534 && can_remove_package(db
, deppkg
, targs
, include_explicit
)) {
535 _alpm_log(db
->handle
, PM_LOG_DEBUG
, "adding '%s' to the targets\n",
536 alpm_pkg_get_name(deppkg
));
537 /* add it to the target list */
538 targs
= alpm_list_add(targs
, _alpm_pkg_dup(deppkg
));
545 * helper function for resolvedeps: search for dep satisfier in dbs
547 * @param handle the context handle
548 * @param dep is the dependency to search for
549 * @param dbs are the databases to search
550 * @param excluding are the packages to exclude from the search
551 * @param prompt if true, will cause an unresolvable dependency to issue an
552 * interactive prompt asking whether the package should be removed from
553 * the transaction or the transaction aborted; if false, simply returns
554 * an error code without prompting
555 * @return the resolved package
557 static pmpkg_t
*resolvedep(pmhandle_t
*handle
, pmdepend_t
*dep
,
558 alpm_list_t
*dbs
, alpm_list_t
*excluding
, int prompt
)
563 alpm_list_t
*providers
= NULL
;
567 for(i
= dbs
; i
; i
= i
->next
) {
568 pmpkg_t
*pkg
= _alpm_db_get_pkgfromcache(i
->data
, dep
->name
);
569 if(pkg
&& _alpm_depcmp(pkg
, dep
) && !_alpm_pkg_find(excluding
, pkg
->name
)) {
570 if(_alpm_pkg_should_ignore(handle
, pkg
)) {
573 QUESTION(handle
->trans
, PM_TRANS_CONV_INSTALL_IGNOREPKG
, pkg
,
574 NULL
, NULL
, &install
);
576 _alpm_log(handle
, PM_LOG_WARNING
, _("ignoring package %s-%s\n"), pkg
->name
, pkg
->version
);
586 /* 2. satisfiers (skip literals here) */
587 for(i
= dbs
; i
; i
= i
->next
) {
588 for(j
= _alpm_db_get_pkgcache(i
->data
); j
; j
= j
->next
) {
589 pmpkg_t
*pkg
= j
->data
;
590 if(_alpm_depcmp(pkg
, dep
) && strcmp(pkg
->name
, dep
->name
) != 0 &&
591 !_alpm_pkg_find(excluding
, pkg
->name
)) {
592 if(_alpm_pkg_should_ignore(handle
, pkg
)) {
595 QUESTION(handle
->trans
, PM_TRANS_CONV_INSTALL_IGNOREPKG
,
596 pkg
, NULL
, NULL
, &install
);
598 _alpm_log(handle
, PM_LOG_WARNING
, _("ignoring package %s-%s\n"), pkg
->name
, pkg
->version
);
605 _alpm_log(handle
, PM_LOG_DEBUG
, "provider found (%s provides %s)\n",
606 pkg
->name
, dep
->name
);
607 providers
= alpm_list_add(providers
, pkg
);
608 /* keep looking for other providers in the all dbs */
613 /* first check if one provider is already installed locally */
614 for(i
= providers
; i
; i
= i
->next
) {
615 pmpkg_t
*pkg
= i
->data
;
616 if(_alpm_pkghash_find(_alpm_db_get_pkgcache_hash(handle
->db_local
), pkg
->name
)) {
617 alpm_list_free(providers
);
621 count
= alpm_list_count(providers
);
623 /* default to first provider if there is no QUESTION callback */
626 /* if there is more than one provider, we ask the user */
627 QUESTION(handle
->trans
, PM_TRANS_CONV_SELECT_PROVIDER
,
628 providers
, dep
, NULL
, &index
);
630 if(index
>= 0 && index
< count
) {
631 pmpkg_t
*pkg
= alpm_list_getdata(alpm_list_nth(providers
, index
));
632 alpm_list_free(providers
);
635 alpm_list_free(providers
);
639 if(ignored
) { /* resolvedeps will override these */
640 handle
->pm_errno
= PM_ERR_PKG_IGNORED
;
642 handle
->pm_errno
= PM_ERR_PKG_NOT_FOUND
;
647 /** Find a package satisfying a specified dependency.
648 * First look for a literal, going through each db one by one. Then look for
649 * providers. The first satisfier found is returned.
650 * The dependency can include versions with depmod operators.
651 * @param handle the context handle
652 * @param dbs an alpm_list_t* of pmdb_t where the satisfier will be searched
653 * @param depstring package or provision name, versioned or not
654 * @return a pmpkg_t* satisfying depstring
656 pmpkg_t SYMEXPORT
*alpm_find_dbs_satisfier(pmhandle_t
*handle
,
657 alpm_list_t
*dbs
, const char *depstring
)
662 CHECK_HANDLE(handle
, return NULL
);
663 ASSERT(dbs
, RET_ERR(handle
, PM_ERR_WRONG_ARGS
, NULL
));
665 dep
= _alpm_splitdep(depstring
);
666 ASSERT(dep
, return NULL
);
667 pkg
= resolvedep(handle
, dep
, dbs
, NULL
, 1);
673 * Computes resolvable dependencies for a given package and adds that package
674 * and those resolvable dependencies to a list.
676 * @param handle the context handle
677 * @param localpkgs is the list of local packages
678 * @param pkg is the package to resolve
679 * @param packages is a pointer to a list of packages which will be
680 * searched first for any dependency packages needed to complete the
681 * resolve, and to which will be added any [pkg] and all of its
682 * dependencies not already on the list
683 * @param remove is the set of packages which will be removed in this
685 * @param data returns the dependency which could not be satisfied in the
687 * @return 0 on success, with [pkg] and all of its dependencies not already on
688 * the [*packages] list added to that list, or -1 on failure due to an
689 * unresolvable dependency, in which case the [*packages] list will be
690 * unmodified by this function
692 int _alpm_resolvedeps(pmhandle_t
*handle
, alpm_list_t
*localpkgs
, pmpkg_t
*pkg
,
693 alpm_list_t
*preferred
, alpm_list_t
**packages
,
694 alpm_list_t
*remove
, alpm_list_t
**data
)
699 alpm_list_t
*deps
= NULL
;
700 alpm_list_t
*packages_copy
;
702 if(_alpm_pkg_find(*packages
, pkg
->name
) != NULL
) {
706 /* Create a copy of the packages list, so that it can be restored
708 packages_copy
= alpm_list_copy(*packages
);
709 /* [pkg] has not already been resolved into the packages list, so put it
711 *packages
= alpm_list_add(*packages
, pkg
);
713 _alpm_log(handle
, PM_LOG_DEBUG
, "started resolving dependencies\n");
714 for(i
= alpm_list_last(*packages
); i
; i
= i
->next
) {
715 pmpkg_t
*tpkg
= i
->data
;
716 targ
= alpm_list_add(NULL
, tpkg
);
717 deps
= alpm_checkdeps(handle
, localpkgs
, remove
, targ
, 0);
718 alpm_list_free(targ
);
720 for(j
= deps
; j
; j
= j
->next
) {
721 pmdepmissing_t
*miss
= j
->data
;
722 pmdepend_t
*missdep
= miss
->depend
;
723 /* check if one of the packages in the [*packages] list already satisfies
725 if(find_dep_satisfier(*packages
, missdep
)) {
726 _alpm_depmiss_free(miss
);
729 /* check if one of the packages in the [preferred] list already satisfies
731 pmpkg_t
*spkg
= find_dep_satisfier(preferred
, missdep
);
733 /* find a satisfier package in the given repositories */
734 spkg
= resolvedep(handle
, missdep
, handle
->dbs_sync
, *packages
, 0);
737 handle
->pm_errno
= PM_ERR_UNSATISFIED_DEPS
;
738 char *missdepstring
= alpm_dep_compute_string(missdep
);
739 _alpm_log(handle
, PM_LOG_WARNING
,
740 _("cannot resolve \"%s\", a dependency of \"%s\"\n"),
741 missdepstring
, tpkg
->name
);
744 *data
= alpm_list_add(*data
, miss
);
748 _alpm_log(handle
, PM_LOG_DEBUG
, "pulling dependency %s (needed by %s)\n",
749 alpm_pkg_get_name(spkg
), alpm_pkg_get_name(tpkg
));
750 *packages
= alpm_list_add(*packages
, spkg
);
751 _alpm_depmiss_free(miss
);
754 alpm_list_free(deps
);
758 alpm_list_free(*packages
);
759 *packages
= packages_copy
;
761 alpm_list_free(packages_copy
);
763 _alpm_log(handle
, PM_LOG_DEBUG
, "finished resolving dependencies\n");
767 /** Reverse of splitdep; make a dep string from a pmdepend_t struct.
768 * The string must be freed!
769 * @param dep the depend to turn into a string
770 * @return a string-formatted dependency with operator if necessary
772 char SYMEXPORT
*alpm_dep_compute_string(const pmdepend_t
*dep
)
774 const char *name
, *opr
, *ver
;
778 ASSERT(dep
!= NULL
, return NULL
);
810 if(dep
->mod
!= PM_DEP_MOD_ANY
&& dep
->version
) {
816 /* we can always compute len and print the string like this because opr
817 * and ver will be empty when PM_DEP_MOD_ANY is the depend type. the
818 * reassignments above also ensure we do not do a strlen(NULL). */
819 len
= strlen(name
) + strlen(opr
) + strlen(ver
) + 1;
820 MALLOC(str
, len
, return NULL
);
821 snprintf(str
, len
, "%s%s%s", name
, opr
, ver
);
825 /* vim: set ts=2 sw=2 noet: */