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"
39 void _alpm_dep_free(pmdepend_t
*dep
)
46 static pmdepmissing_t
*depmiss_new(const char *target
, pmdepend_t
*dep
,
47 const char *causingpkg
)
51 MALLOC(miss
, sizeof(pmdepmissing_t
), RET_ERR(PM_ERR_MEMORY
, NULL
));
53 STRDUP(miss
->target
, target
, RET_ERR(PM_ERR_MEMORY
, NULL
));
54 miss
->depend
= _alpm_dep_dup(dep
);
55 STRDUP(miss
->causingpkg
, causingpkg
, RET_ERR(PM_ERR_MEMORY
, NULL
));
60 void _alpm_depmiss_free(pmdepmissing_t
*miss
)
62 _alpm_dep_free(miss
->depend
);
64 FREE(miss
->causingpkg
);
68 /* Does pkg1 depend on pkg2, ie. does pkg2 satisfy a dependency of pkg1? */
69 static int _alpm_dep_edge(pmpkg_t
*pkg1
, pmpkg_t
*pkg2
)
72 for(i
= alpm_pkg_get_depends(pkg1
); i
; i
= i
->next
) {
73 if(_alpm_depcmp(pkg2
, i
->data
)) {
80 /* Convert a list of pmpkg_t * to a graph structure,
81 * with a edge for each dependency.
82 * Returns a list of vertices (one vertex = one package)
83 * (used by alpm_sortbydeps)
85 static alpm_list_t
*dep_graph_init(alpm_list_t
*targets
)
88 alpm_list_t
*vertices
= NULL
;
89 /* We create the vertices */
90 for(i
= targets
; i
; i
= i
->next
) {
91 pmgraph_t
*vertex
= _alpm_graph_new();
92 vertex
->data
= (void *)i
->data
;
93 vertices
= alpm_list_add(vertices
, vertex
);
96 /* We compute the edges */
97 for(i
= vertices
; i
; i
= i
->next
) {
98 pmgraph_t
*vertex_i
= i
->data
;
99 pmpkg_t
*p_i
= vertex_i
->data
;
100 /* TODO this should be somehow combined with alpm_checkdeps */
101 for(j
= vertices
; j
; j
= j
->next
) {
102 pmgraph_t
*vertex_j
= j
->data
;
103 pmpkg_t
*p_j
= vertex_j
->data
;
104 if(_alpm_dep_edge(p_i
, p_j
)) {
106 alpm_list_add(vertex_i
->children
, vertex_j
);
109 vertex_i
->childptr
= vertex_i
->children
;
114 /* Re-order a list of target packages with respect to their dependencies.
116 * Example (reverse == 0):
119 * Target order is A,B,C,D
121 * Should be re-ordered to C,A,B,D
123 * if reverse is > 0, the dependency order will be reversed.
125 * This function returns the new alpm_list_t* target list.
128 alpm_list_t
*_alpm_sortbydeps(alpm_list_t
*targets
, int reverse
)
130 alpm_list_t
*newtargs
= NULL
;
131 alpm_list_t
*vertices
= NULL
;
135 if(targets
== NULL
) {
139 _alpm_log(PM_LOG_DEBUG
, "started sorting dependencies\n");
141 vertices
= dep_graph_init(targets
);
144 vertex
= vertices
->data
;
146 /* mark that we touched the vertex */
149 while(vertex
->childptr
&& !found
) {
150 pmgraph_t
*nextchild
= vertex
->childptr
->data
;
151 vertex
->childptr
= vertex
->childptr
->next
;
152 if(nextchild
->state
== 0) {
154 nextchild
->parent
= vertex
;
157 else if(nextchild
->state
== -1) {
158 pmpkg_t
*vertexpkg
= vertex
->data
;
159 pmpkg_t
*childpkg
= nextchild
->data
;
162 _alpm_log(PM_LOG_WARNING
, _("dependency cycle detected:\n"));
164 message
=_("%s will be removed after its %s dependency\n");
166 message
=_("%s will be installed before its %s dependency\n");
168 _alpm_log(PM_LOG_WARNING
, message
, vertexpkg
->name
, childpkg
->name
);
172 newtargs
= alpm_list_add(newtargs
, vertex
->data
);
173 /* mark that we've left this vertex */
175 vertex
= vertex
->parent
;
180 if(vertex
->state
== 0) break;
187 _alpm_log(PM_LOG_DEBUG
, "sorting dependencies finished\n");
190 /* reverse the order */
191 alpm_list_t
*tmptargs
= alpm_list_reverse(newtargs
);
192 /* free the old one */
193 alpm_list_free(newtargs
);
197 alpm_list_free_inner(vertices
, _alpm_graph_free
);
198 alpm_list_free(vertices
);
203 static int no_dep_version(void)
205 int flags
= alpm_trans_get_flags();
206 return flags
!= -1 && (flags
& PM_TRANS_FLAG_NODEPVERSION
);
209 static pmdepend_t
*filtered_depend(pmdepend_t
*dep
, int nodepversion
)
212 pmdepend_t
*newdep
= _alpm_dep_dup(dep
);
213 ASSERT(newdep
, return dep
);
214 newdep
->mod
= PM_DEP_MOD_ANY
;
220 static void release_filtered_depend(pmdepend_t
*dep
, int nodepversion
)
227 static pmpkg_t
*find_dep_satisfier(alpm_list_t
*pkgs
, pmdepend_t
*dep
)
231 for(i
= pkgs
; i
; i
= alpm_list_next(i
)) {
232 pmpkg_t
*pkg
= i
->data
;
233 if(_alpm_depcmp(pkg
, dep
)) {
240 /** Find a package satisfying a specified dependency.
241 * The dependency can include versions with depmod operators.
242 * @param pkgs an alpm_list_t* of pmpkg_t where the satisfier will be searched
243 * @param depstring package or provision name, versioned or not
244 * @return a pmpkg_t* satisfying depstring
246 pmpkg_t SYMEXPORT
*alpm_find_satisfier(alpm_list_t
*pkgs
, const char *depstring
)
248 pmdepend_t
*dep
= _alpm_splitdep(depstring
);
249 pmpkg_t
*pkg
= find_dep_satisfier(pkgs
, dep
);
254 /** Checks dependencies and returns missing ones in a list.
255 * Dependencies can include versions with depmod operators.
256 * @param pkglist the list of local packages
257 * @param reversedeps handles the backward dependencies
258 * @param remove an alpm_list_t* of packages to be removed
259 * @param upgrade an alpm_list_t* of packages to be upgraded (remove-then-upgrade)
260 * @return an alpm_list_t* of pmdepmissing_t pointers.
262 alpm_list_t SYMEXPORT
*alpm_checkdeps(alpm_list_t
*pkglist
, int reversedeps
,
263 alpm_list_t
*remove
, alpm_list_t
*upgrade
)
266 alpm_list_t
*targets
, *dblist
= NULL
, *modified
= NULL
;
267 alpm_list_t
*baddeps
= NULL
;
270 targets
= alpm_list_join(alpm_list_copy(remove
), alpm_list_copy(upgrade
));
271 for(i
= pkglist
; i
; i
= i
->next
) {
272 pmpkg_t
*pkg
= i
->data
;
273 if(_alpm_pkg_find(targets
, pkg
->name
)) {
274 modified
= alpm_list_add(modified
, pkg
);
276 dblist
= alpm_list_add(dblist
, pkg
);
279 alpm_list_free(targets
);
281 nodepversion
= no_dep_version();
283 /* look for unsatisfied dependencies of the upgrade list */
284 for(i
= upgrade
; i
; i
= i
->next
) {
285 pmpkg_t
*tp
= i
->data
;
286 _alpm_log(PM_LOG_DEBUG
, "checkdeps: package %s-%s\n",
287 alpm_pkg_get_name(tp
), alpm_pkg_get_version(tp
));
289 for(j
= alpm_pkg_get_depends(tp
); j
; j
= j
->next
) {
290 pmdepend_t
*depend
= j
->data
;
291 depend
= filtered_depend(depend
, nodepversion
);
292 /* 1. we check the upgrade list */
293 /* 2. we check database for untouched satisfying packages */
294 if(!find_dep_satisfier(upgrade
, depend
) &&
295 !find_dep_satisfier(dblist
, depend
)) {
296 /* Unsatisfied dependency in the upgrade list */
297 pmdepmissing_t
*miss
;
298 char *missdepstring
= alpm_dep_compute_string(depend
);
299 _alpm_log(PM_LOG_DEBUG
, "checkdeps: missing dependency '%s' for package '%s'\n",
300 missdepstring
, alpm_pkg_get_name(tp
));
302 miss
= depmiss_new(alpm_pkg_get_name(tp
), depend
, NULL
);
303 baddeps
= alpm_list_add(baddeps
, miss
);
305 release_filtered_depend(depend
, nodepversion
);
310 /* reversedeps handles the backwards dependencies, ie,
311 * the packages listed in the requiredby field. */
312 for(i
= dblist
; i
; i
= i
->next
) {
313 pmpkg_t
*lp
= i
->data
;
314 for(j
= alpm_pkg_get_depends(lp
); j
; j
= j
->next
) {
315 pmdepend_t
*depend
= j
->data
;
316 depend
= filtered_depend(depend
, nodepversion
);
317 pmpkg_t
*causingpkg
= find_dep_satisfier(modified
, depend
);
318 /* we won't break this depend, if it is already broken, we ignore it */
319 /* 1. check upgrade list for satisfiers */
320 /* 2. check dblist for satisfiers */
322 !find_dep_satisfier(upgrade
, depend
) &&
323 !find_dep_satisfier(dblist
, depend
)) {
324 pmdepmissing_t
*miss
;
325 char *missdepstring
= alpm_dep_compute_string(depend
);
326 _alpm_log(PM_LOG_DEBUG
, "checkdeps: transaction would break '%s' dependency of '%s'\n",
327 missdepstring
, alpm_pkg_get_name(lp
));
329 miss
= depmiss_new(lp
->name
, depend
, alpm_pkg_get_name(causingpkg
));
330 baddeps
= alpm_list_add(baddeps
, miss
);
332 release_filtered_depend(depend
, nodepversion
);
337 alpm_list_free(modified
);
338 alpm_list_free(dblist
);
343 static int dep_vercmp(const char *version1
, pmdepmod_t mod
,
344 const char *version2
)
348 if(mod
== PM_DEP_MOD_ANY
) {
351 int cmp
= alpm_pkg_vercmp(version1
, version2
);
353 case PM_DEP_MOD_EQ
: equal
= (cmp
== 0); break;
354 case PM_DEP_MOD_GE
: equal
= (cmp
>= 0); break;
355 case PM_DEP_MOD_LE
: equal
= (cmp
<= 0); break;
356 case PM_DEP_MOD_LT
: equal
= (cmp
< 0); break;
357 case PM_DEP_MOD_GT
: equal
= (cmp
> 0); break;
358 default: equal
= 1; break;
364 int _alpm_depcmp(pmpkg_t
*pkg
, pmdepend_t
*dep
)
369 /* check (pkg->name, pkg->version) */
370 if(pkg
->name_hash
&& dep
->name_hash
371 && pkg
->name_hash
!= dep
->name_hash
) {
372 /* skip more expensive checks */
374 satisfy
= (strcmp(pkg
->name
, dep
->name
) == 0
375 && dep_vercmp(pkg
->version
, dep
->mod
, dep
->version
));
381 /* check provisions, format : "name=version" */
382 for(i
= alpm_pkg_get_provides(pkg
); i
&& !satisfy
; i
= i
->next
) {
383 const char *provision
= i
->data
;
384 const char *provver
= strchr(provision
, '=');
386 if(provver
== NULL
) { /* no provision version */
387 satisfy
= (dep
->mod
== PM_DEP_MOD_ANY
388 && strcmp(provision
, dep
->name
) == 0);
390 /* This is a bit tricker than the old code for performance reasons. To
391 * prevent the need to copy and duplicate strings, strncmp only the name
392 * portion if they are the same length, since there is a version and
393 * operator in play here. Cast is to silence sign conversion warning;
394 * we know provver >= provision if we are here. */
395 size_t namelen
= (size_t)(provver
- provision
);
397 satisfy
= (strlen(dep
->name
) == namelen
398 && strncmp(provision
, dep
->name
, namelen
) == 0
399 && dep_vercmp(provver
, dep
->mod
, dep
->version
));
406 pmdepend_t
*_alpm_splitdep(const char *depstring
)
409 const char *ptr
, *version
= NULL
;
411 if(depstring
== NULL
) {
415 CALLOC(depend
, 1, sizeof(pmdepend_t
), RET_ERR(PM_ERR_MEMORY
, NULL
));
417 /* Find a version comparator if one exists. If it does, set the type and
418 * increment the ptr accordingly so we can copy the right strings. */
419 if((ptr
= strstr(depstring
, ">="))) {
420 depend
->mod
= PM_DEP_MOD_GE
;
422 } else if((ptr
= strstr(depstring
, "<="))) {
423 depend
->mod
= PM_DEP_MOD_LE
;
425 } else if((ptr
= strstr(depstring
, "="))) {
426 /* Note: we must do =,<,> checks after <=, >= checks */
427 depend
->mod
= PM_DEP_MOD_EQ
;
429 } else if((ptr
= strstr(depstring
, "<"))) {
430 depend
->mod
= PM_DEP_MOD_LT
;
432 } else if((ptr
= strstr(depstring
, ">"))) {
433 depend
->mod
= PM_DEP_MOD_GT
;
436 /* no version specified, leave version and ptr NULL */
437 depend
->mod
= PM_DEP_MOD_ANY
;
440 /* copy the right parts to the right places */
441 STRNDUP(depend
->name
, depstring
, ptr
- depstring
,
442 RET_ERR(PM_ERR_MEMORY
, NULL
));
443 depend
->name_hash
= _alpm_hash_sdbm(depend
->name
);
445 STRDUP(depend
->version
, version
, RET_ERR(PM_ERR_MEMORY
, NULL
));
451 pmdepend_t
*_alpm_dep_dup(const pmdepend_t
*dep
)
454 CALLOC(newdep
, 1, sizeof(pmdepend_t
), RET_ERR(PM_ERR_MEMORY
, NULL
));
456 STRDUP(newdep
->name
, dep
->name
, RET_ERR(PM_ERR_MEMORY
, NULL
));
457 newdep
->name_hash
= dep
->name_hash
;
458 STRDUP(newdep
->version
, dep
->version
, RET_ERR(PM_ERR_MEMORY
, NULL
));
459 newdep
->mod
= dep
->mod
;
464 /* These parameters are messy. We check if this package, given a list of
465 * targets and a db is safe to remove. We do NOT remove it if it is in the
466 * target list, or if if the package was explictly installed and
467 * include_explicit == 0 */
468 static int can_remove_package(pmdb_t
*db
, pmpkg_t
*pkg
, alpm_list_t
*targets
,
469 int include_explicit
)
473 if(_alpm_pkg_find(targets
, alpm_pkg_get_name(pkg
))) {
477 if(!include_explicit
) {
478 /* see if it was explicitly installed */
479 if(alpm_pkg_get_reason(pkg
) == PM_PKG_REASON_EXPLICIT
) {
480 _alpm_log(PM_LOG_DEBUG
, "excluding %s -- explicitly installed\n",
481 alpm_pkg_get_name(pkg
));
486 /* TODO: checkdeps could be used here, it handles multiple providers
487 * better, but that also makes it slower.
488 * Also this would require to first add the package to the targets list,
489 * then call checkdeps with it, then remove the package from the targets list
490 * if checkdeps detected it would break something */
492 /* see if other packages need it */
493 for(i
= _alpm_db_get_pkgcache(db
); i
; i
= i
->next
) {
494 pmpkg_t
*lpkg
= i
->data
;
495 if(_alpm_dep_edge(lpkg
, pkg
) && !_alpm_pkg_find(targets
, lpkg
->name
)) {
500 /* it's ok to remove */
505 * @brief Adds unneeded dependencies to an existing list of packages.
506 * By unneeded, we mean dependencies that are only required by packages in the
507 * target list, so they can be safely removed.
508 * If the input list was topo sorted, the output list will be topo sorted too.
510 * @param db package database to do dependency tracing in
511 * @param *targs pointer to a list of packages
512 * @param include_explicit if 0, explicitly installed packages are not included
514 void _alpm_recursedeps(pmdb_t
*db
, alpm_list_t
*targs
, int include_explicit
)
518 if(db
== NULL
|| targs
== NULL
) {
522 for(i
= targs
; i
; i
= i
->next
) {
523 pmpkg_t
*pkg
= i
->data
;
524 for(j
= _alpm_db_get_pkgcache(db
); j
; j
= j
->next
) {
525 pmpkg_t
*deppkg
= j
->data
;
526 if(_alpm_dep_edge(pkg
, deppkg
)
527 && can_remove_package(db
, deppkg
, targs
, include_explicit
)) {
528 _alpm_log(PM_LOG_DEBUG
, "adding '%s' to the targets\n",
529 alpm_pkg_get_name(deppkg
));
530 /* add it to the target list */
531 targs
= alpm_list_add(targs
, _alpm_pkg_dup(deppkg
));
538 * helper function for resolvedeps: search for dep satisfier in dbs
540 * @param dep is the dependency to search for
541 * @param dbs are the databases to search
542 * @param excluding are the packages to exclude from the search
543 * @param prompt if true, will cause an unresolvable dependency to issue an
544 * interactive prompt asking whether the package should be removed from
545 * the transaction or the transaction aborted; if false, simply returns
546 * an error code without prompting
547 * @return the resolved package
549 static pmpkg_t
*resolvedep(pmdepend_t
*dep
, alpm_list_t
*dbs
,
550 alpm_list_t
*excluding
, int prompt
)
555 alpm_list_t
*providers
= NULL
;
559 for(i
= dbs
; i
; i
= i
->next
) {
560 pmpkg_t
*pkg
= _alpm_db_get_pkgfromcache(i
->data
, dep
->name
);
561 if(pkg
&& _alpm_depcmp(pkg
, dep
) && !_alpm_pkg_find(excluding
, pkg
->name
)) {
562 if(_alpm_pkg_should_ignore(pkg
)) {
565 QUESTION(handle
->trans
, PM_TRANS_CONV_INSTALL_IGNOREPKG
, pkg
,
566 NULL
, NULL
, &install
);
568 _alpm_log(PM_LOG_WARNING
, _("ignoring package %s-%s\n"), pkg
->name
, pkg
->version
);
578 /* 2. satisfiers (skip literals here) */
579 for(i
= dbs
; i
; i
= i
->next
) {
580 for(j
= _alpm_db_get_pkgcache(i
->data
); j
; j
= j
->next
) {
581 pmpkg_t
*pkg
= j
->data
;
582 if(_alpm_depcmp(pkg
, dep
) && strcmp(pkg
->name
, dep
->name
) != 0 &&
583 !_alpm_pkg_find(excluding
, pkg
->name
)) {
584 if(_alpm_pkg_should_ignore(pkg
)) {
587 QUESTION(handle
->trans
, PM_TRANS_CONV_INSTALL_IGNOREPKG
,
588 pkg
, NULL
, NULL
, &install
);
590 _alpm_log(PM_LOG_WARNING
, _("ignoring package %s-%s\n"), pkg
->name
, pkg
->version
);
597 _alpm_log(PM_LOG_DEBUG
, "provider found (%s provides %s)\n",
598 pkg
->name
, dep
->name
);
599 providers
= alpm_list_add(providers
, pkg
);
600 /* keep looking for other providers in the all dbs */
605 /* first check if one provider is already installed locally */
606 for(i
= providers
; i
; i
= i
->next
) {
607 pmpkg_t
*pkg
= i
->data
;
608 if(_alpm_pkghash_find(_alpm_db_get_pkgcache_hash(handle
->db_local
), pkg
->name
)) {
609 alpm_list_free(providers
);
613 count
= alpm_list_count(providers
);
615 /* default to first provider if there is no QUESTION callback */
618 /* if there is more than one provider, we ask the user */
619 QUESTION(handle
->trans
, PM_TRANS_CONV_SELECT_PROVIDER
,
620 providers
, dep
, NULL
, &index
);
622 if(index
>= 0 && index
< count
) {
623 pmpkg_t
*pkg
= alpm_list_getdata(alpm_list_nth(providers
, index
));
624 alpm_list_free(providers
);
627 alpm_list_free(providers
);
631 if(ignored
) { /* resolvedeps will override these */
632 pm_errno
= PM_ERR_PKG_IGNORED
;
634 pm_errno
= PM_ERR_PKG_NOT_FOUND
;
639 /** Find a package satisfying a specified dependency.
640 * First look for a literal, going through each db one by one. Then look for
641 * providers. The first satisfier found is returned.
642 * The dependency can include versions with depmod operators.
643 * @param dbs an alpm_list_t* of pmdb_t where the satisfier will be searched
644 * @param depstring package or provision name, versioned or not
645 * @return a pmpkg_t* satisfying depstring
647 pmpkg_t SYMEXPORT
*alpm_find_dbs_satisfier(alpm_list_t
*dbs
, const char *depstring
)
652 ASSERT(dbs
, return NULL
);
654 dep
= _alpm_splitdep(depstring
);
655 ASSERT(dep
, return NULL
);
656 pkg
= resolvedep(dep
, dbs
, NULL
, 1);
662 * Computes resolvable dependencies for a given package and adds that package
663 * and those resolvable dependencies to a list.
665 * @param localpkgs is the list of local packages
666 * @param dbs_sync are the sync databases
667 * @param pkg is the package to resolve
668 * @param packages is a pointer to a list of packages which will be
669 * searched first for any dependency packages needed to complete the
670 * resolve, and to which will be added any [pkg] and all of its
671 * dependencies not already on the list
672 * @param remove is the set of packages which will be removed in this
674 * @param data returns the dependency which could not be satisfied in the
676 * @return 0 on success, with [pkg] and all of its dependencies not already on
677 * the [*packages] list added to that list, or -1 on failure due to an
678 * unresolvable dependency, in which case the [*packages] list will be
679 * unmodified by this function
681 int _alpm_resolvedeps(alpm_list_t
*localpkgs
, alpm_list_t
*dbs_sync
, pmpkg_t
*pkg
,
682 alpm_list_t
*preferred
, alpm_list_t
**packages
,
683 alpm_list_t
*remove
, alpm_list_t
**data
)
688 alpm_list_t
*deps
= NULL
;
689 alpm_list_t
*packages_copy
;
691 if(_alpm_pkg_find(*packages
, pkg
->name
) != NULL
) {
695 /* Create a copy of the packages list, so that it can be restored
697 packages_copy
= alpm_list_copy(*packages
);
698 /* [pkg] has not already been resolved into the packages list, so put it
700 *packages
= alpm_list_add(*packages
, pkg
);
702 _alpm_log(PM_LOG_DEBUG
, "started resolving dependencies\n");
703 for(i
= alpm_list_last(*packages
); i
; i
= i
->next
) {
704 pmpkg_t
*tpkg
= i
->data
;
705 targ
= alpm_list_add(NULL
, tpkg
);
706 deps
= alpm_checkdeps(localpkgs
, 0, remove
, targ
);
707 alpm_list_free(targ
);
709 for(j
= deps
; j
; j
= j
->next
) {
710 pmdepmissing_t
*miss
= j
->data
;
711 pmdepend_t
*missdep
= alpm_miss_get_dep(miss
);
712 /* check if one of the packages in the [*packages] list already satisfies
714 if(find_dep_satisfier(*packages
, missdep
)) {
715 _alpm_depmiss_free(miss
);
718 /* check if one of the packages in the [preferred] list already satisfies
720 pmpkg_t
*spkg
= find_dep_satisfier(preferred
, missdep
);
722 /* find a satisfier package in the given repositories */
723 spkg
= resolvedep(missdep
, dbs_sync
, *packages
, 0);
726 pm_errno
= PM_ERR_UNSATISFIED_DEPS
;
727 char *missdepstring
= alpm_dep_compute_string(missdep
);
728 _alpm_log(PM_LOG_WARNING
,
729 _("cannot resolve \"%s\", a dependency of \"%s\"\n"),
730 missdepstring
, tpkg
->name
);
733 *data
= alpm_list_add(*data
, miss
);
737 _alpm_log(PM_LOG_DEBUG
, "pulling dependency %s (needed by %s)\n",
738 alpm_pkg_get_name(spkg
), alpm_pkg_get_name(tpkg
));
739 *packages
= alpm_list_add(*packages
, spkg
);
740 _alpm_depmiss_free(miss
);
743 alpm_list_free(deps
);
747 alpm_list_free(*packages
);
748 *packages
= packages_copy
;
750 alpm_list_free(packages_copy
);
752 _alpm_log(PM_LOG_DEBUG
, "finished resolving dependencies\n");
756 const char SYMEXPORT
*alpm_miss_get_target(const pmdepmissing_t
*miss
)
759 ASSERT(miss
!= NULL
, return NULL
);
764 const char SYMEXPORT
*alpm_miss_get_causingpkg(const pmdepmissing_t
*miss
)
767 ASSERT(miss
!= NULL
, return NULL
);
769 return miss
->causingpkg
;
772 pmdepend_t SYMEXPORT
*alpm_miss_get_dep(pmdepmissing_t
*miss
)
775 ASSERT(miss
!= NULL
, return NULL
);
780 pmdepmod_t SYMEXPORT
alpm_dep_get_mod(const pmdepend_t
*dep
)
783 ASSERT(dep
!= NULL
, return -1);
788 const char SYMEXPORT
*alpm_dep_get_name(const pmdepend_t
*dep
)
791 ASSERT(dep
!= NULL
, return NULL
);
796 const char SYMEXPORT
*alpm_dep_get_version(const pmdepend_t
*dep
)
799 ASSERT(dep
!= NULL
, return NULL
);
804 /** Reverse of splitdep; make a dep string from a pmdepend_t struct.
805 * The string must be freed!
806 * @param dep the depend to turn into a string
807 * @return a string-formatted dependency with operator if necessary
809 char SYMEXPORT
*alpm_dep_compute_string(const pmdepend_t
*dep
)
811 const char *name
, *opr
, *ver
;
816 ASSERT(dep
!= NULL
, return NULL
);
848 if(dep
->mod
!= PM_DEP_MOD_ANY
&& dep
->version
) {
854 /* we can always compute len and print the string like this because opr
855 * and ver will be empty when PM_DEP_MOD_ANY is the depend type. the
856 * reassignments above also ensure we do not do a strlen(NULL). */
857 len
= strlen(name
) + strlen(opr
) + strlen(ver
) + 1;
858 MALLOC(str
, len
, RET_ERR(PM_ERR_MEMORY
, NULL
));
859 snprintf(str
, len
, "%s%s%s", name
, opr
, ver
);
863 /* vim: set ts=2 sw=2 noet: */