1 /* pkg_depends.c - the opkg package management system
5 Copyright (C) 2002 Compaq Computer Corporation
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2, or (at
10 your option) any later version.
12 This program is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
22 #include "opkg_utils.h"
24 #include "opkg_message.h"
25 #include "pkg_parse.h"
26 #include "hash_table.h"
27 #include "libbb/libbb.h"
29 static int parseDepends(compound_depend_t * compound_depend, char *depend_str);
30 static depend_t *depend_init(void);
31 static char **add_unresolved_dep(pkg_t * pkg, char **the_lost, int ref_ndx);
32 static char **merge_unresolved(char **oldstuff, char **newstuff);
33 static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
35 static int pkg_installed_and_constraint_satisfied(pkg_t * pkg, void *cdata)
37 depend_t *depend = (depend_t *) cdata;
38 if ((pkg->state_status == SS_INSTALLED
39 || pkg->state_status == SS_UNPACKED)
40 && version_constraints_satisfied(depend, pkg))
46 static int pkg_constraint_satisfied(pkg_t * pkg, void *cdata)
48 depend_t *depend = (depend_t *) cdata;
49 if (version_constraints_satisfied(depend, pkg))
55 /* returns ndependencies or negative error value */
57 pkg_hash_fetch_unsatisfied_dependencies(pkg_t * pkg, pkg_vec_t * unsatisfied,
60 pkg_t *satisfier_entry_pkg;
64 abstract_pkg_t *ab_pkg;
65 compound_depend_t *compound_depend;
68 * this is a setup to check for redundant/cyclic dependency checks,
69 * which are marked at the abstract_pkg level
71 if (!(ab_pkg = pkg->parent)) {
72 opkg_msg(ERROR, "Internal error, with pkg %s.\n", pkg->name);
76 if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
80 ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
83 compound_depend = pkg_get_ptr(pkg, PKG_DEPENDS);
85 if (!compound_depend || !compound_depend->type) {
92 /* foreach dependency */
93 for (; compound_depend && compound_depend->type; compound_depend++) {
94 depend_t **possible_satisfiers =
95 compound_depend->possibilities;;
97 satisfier_entry_pkg = NULL;
99 if (compound_depend->type == GREEDY_DEPEND) {
100 /* foreach possible satisfier */
101 for (j = 0; j < compound_depend->possibility_count; j++) {
102 /* foreach provided_by, which includes the abstract_pkg itself */
103 abstract_pkg_t *abpkg =
104 possible_satisfiers[j]->pkg;
105 abstract_pkg_vec_t *ab_provider_vec =
107 int nposs = ab_provider_vec->len;
108 abstract_pkg_t **ab_providers =
109 ab_provider_vec->pkgs;
111 for (l = 0; l < nposs; l++) {
112 pkg_vec_t *test_vec =
113 ab_providers[l]->pkgs;
114 /* if no depends on this one, try the first package that Provides this one */
115 if (!test_vec) { /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
119 /* cruise this possiblity's pkg_vec looking for an installed version */
120 for (k = 0; k < test_vec->len; k++) {
123 /* not installed, and not already known about? */
124 if ((pkg_scout->state_want !=
126 && !pkg_scout->parent->
130 (unsatisfied, pkg_scout)) {
131 char **newstuff = NULL;
135 /* check for not-already-installed dependencies */
136 rc = pkg_hash_fetch_unsatisfied_dependencies(pkg_scout, tmp_vec, &newstuff);
137 if (newstuff == NULL) {
155 "Not installing %s due"
156 " to requirement for %s.\n",
167 /* mark this one for installation */
170 "Adding satisfier for greedy"
180 "Not installing %s due to "
194 /* foreach possible satisfier, look for installed package */
195 for (j = 0; j < compound_depend->possibility_count; j++) {
196 /* foreach provided_by, which includes the abstract_pkg itself */
197 depend_t *dependence_to_satisfy =
198 possible_satisfiers[j];
199 abstract_pkg_t *satisfying_apkg =
200 possible_satisfiers[j]->pkg;
201 pkg_t *satisfying_pkg =
202 pkg_hash_fetch_best_installation_candidate
204 pkg_installed_and_constraint_satisfied,
205 dependence_to_satisfy, 1);
206 /* Being that I can't test constraing in pkg_hash, I will test it here */
207 if (satisfying_pkg != NULL) {
208 if (!pkg_installed_and_constraint_satisfied
209 (satisfying_pkg, dependence_to_satisfy)) {
210 satisfying_pkg = NULL;
213 opkg_msg(DEBUG, "satisfying_pkg=%p\n", satisfying_pkg);
214 if (satisfying_pkg != NULL) {
220 /* if nothing installed matches, then look for uninstalled satisfier */
222 /* foreach possible satisfier, look for installed package */
223 for (j = 0; j < compound_depend->possibility_count; j++) {
224 /* foreach provided_by, which includes the abstract_pkg itself */
225 depend_t *dependence_to_satisfy =
226 possible_satisfiers[j];
227 abstract_pkg_t *satisfying_apkg =
228 possible_satisfiers[j]->pkg;
229 pkg_t *satisfying_pkg =
230 pkg_hash_fetch_best_installation_candidate
232 pkg_constraint_satisfied,
233 dependence_to_satisfy, 1);
234 /* Being that I can't test constraing in pkg_hash, I will test it here too */
235 if (satisfying_pkg != NULL) {
236 if (!pkg_constraint_satisfied
238 dependence_to_satisfy)) {
239 satisfying_pkg = NULL;
243 /* user request overrides package recommendation */
244 if (satisfying_pkg != NULL
245 && (compound_depend->type == RECOMMEND
246 || compound_depend->type == SUGGEST)
247 && (satisfying_pkg->state_want ==
249 || satisfying_pkg->state_want ==
252 "%s: ignoring recommendation for "
253 "%s at user request\n",
255 satisfying_pkg->name);
259 opkg_msg(DEBUG, "satisfying_pkg=%p\n",
261 if (satisfying_pkg != NULL) {
262 satisfier_entry_pkg = satisfying_pkg;
268 /* we didn't find one, add something to the unsatisfied vector */
270 if (!satisfier_entry_pkg) {
271 /* failure to meet recommendations is not an error */
272 if (compound_depend->type != RECOMMEND
273 && compound_depend->type != SUGGEST)
275 add_unresolved_dep(pkg, the_lost,
279 "%s: unsatisfied recommendation for %s\n",
282 possibilities[0]->pkg->name);
284 if (compound_depend->type == SUGGEST) {
285 /* just mention it politely */
287 "package %s suggests installing %s\n",
289 satisfier_entry_pkg->name);
291 char **newstuff = NULL;
293 if (satisfier_entry_pkg != pkg &&
294 !is_pkg_in_pkg_vec(unsatisfied,
295 satisfier_entry_pkg))
297 pkg_vec_insert(unsatisfied,
298 satisfier_entry_pkg);
299 pkg_hash_fetch_unsatisfied_dependencies
300 (satisfier_entry_pkg,
301 unsatisfied, &newstuff);
303 merge_unresolved(the_lost,
312 *unresolved = the_lost;
314 return unsatisfied->len;
317 /*checking for conflicts !in replaces
318 If a packages conflicts with another but is also replacing it, I should not consider it a
320 returns 0 if conflicts <> replaces or 1 if conflicts == replaces
322 static int is_pkg_a_replaces(pkg_t * pkg_scout, pkg_t * pkg)
324 abstract_pkg_t **replaces = pkg_get_ptr(pkg, PKG_REPLACES);
326 if (!replaces || !*replaces)
330 if (strcmp(pkg_scout->name, (*replaces)->name) == 0) { // Found
331 opkg_msg(DEBUG2, "Seems I've found a replace %s %s\n",
332 pkg_scout->name, (*replaces)->name);
341 pkg_vec_t *pkg_hash_fetch_conflicts(pkg_t * pkg)
343 pkg_vec_t *installed_conflicts, *test_vec;
344 compound_depend_t *conflicts, *conflict;
345 depend_t **possible_satisfiers;
346 depend_t *possible_satisfier;
348 abstract_pkg_t *ab_pkg;
353 * this is a setup to check for redundant/cyclic dependency checks,
354 * which are marked at the abstract_pkg level
356 if (!(ab_pkg = pkg->parent)) {
357 opkg_msg(ERROR, "Internal error: %s not in hash table\n",
359 return (pkg_vec_t *) NULL;
362 conflicts = pkg_get_ptr(pkg, PKG_CONFLICTS);
364 return (pkg_vec_t *) NULL;
366 installed_conflicts = pkg_vec_alloc();
368 /* foreach conflict */
369 for (conflict = conflicts; conflict->type; conflict++ ) {
370 possible_satisfiers = conflicts->possibilities;
372 /* foreach possible satisfier */
373 for (j = 0; j < conflicts->possibility_count; j++) {
374 possible_satisfier = possible_satisfiers[j];
375 if (!possible_satisfier)
377 "Internal error: possible_satisfier=NULL\n");
378 if (!possible_satisfier->pkg)
380 "Internal error: possible_satisfier->pkg=NULL\n");
381 test_vec = possible_satisfier->pkg->pkgs;
383 /* pkg_vec found, it is an actual package conflict
384 * cruise this possiblity's pkg_vec looking for an installed version */
385 pkg_scouts = test_vec->pkgs;
386 for (k = 0; k < test_vec->len; k++) {
387 pkg_scout = pkg_scouts[k];
390 "Internal error: pkg_scout=NULL\n");
393 if ((pkg_scout->state_status ==
395 || pkg_scout->state_want ==
398 version_constraints_satisfied
399 (possible_satisfier, pkg_scout)
400 && !is_pkg_a_replaces(pkg_scout,
402 if (!is_pkg_in_pkg_vec
403 (installed_conflicts,
406 (installed_conflicts,
416 if (installed_conflicts->len)
417 return installed_conflicts;
418 pkg_vec_free(installed_conflicts);
419 return (pkg_vec_t *) NULL;
422 int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
427 if (depends->constraint == NONE)
432 parse_version(temp, depends->version);
434 comparison = pkg_compare_versions(pkg, temp);
439 if ((depends->constraint == EARLIER) && (comparison < 0))
441 else if ((depends->constraint == LATER) && (comparison > 0))
443 else if (comparison == 0)
445 else if ((depends->constraint == LATER_EQUAL) && (comparison >= 0))
447 else if ((depends->constraint == EARLIER_EQUAL) && (comparison <= 0))
453 int pkg_dependence_satisfiable(depend_t * depend)
455 abstract_pkg_t *apkg = depend->pkg;
456 abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
457 int n_providers = provider_apkgs->len;
458 abstract_pkg_t **apkgs = provider_apkgs->pkgs;
464 for (i = 0; i < n_providers; i++) {
465 abstract_pkg_t *papkg = apkgs[i];
466 pkg_vec = papkg->pkgs;
468 n_pkgs = pkg_vec->len;
469 for (j = 0; j < n_pkgs; j++) {
470 pkg_t *pkg = pkg_vec->pkgs[j];
471 if (version_constraints_satisfied(depend, pkg)) {
480 int pkg_dependence_satisfied(depend_t * depend)
482 abstract_pkg_t *apkg = depend->pkg;
483 abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
484 int n_providers = provider_apkgs->len;
485 abstract_pkg_t **apkgs = provider_apkgs->pkgs;
490 for (i = 0; i < n_providers; i++) {
491 abstract_pkg_t *papkg = apkgs[i];
492 pkg_vec_t *pkg_vec = papkg->pkgs;
494 n_pkgs = pkg_vec->len;
495 for (j = 0; j < n_pkgs; j++) {
496 pkg_t *pkg = pkg_vec->pkgs[j];
497 if (version_constraints_satisfied(depend, pkg)) {
498 if (pkg->state_status == SS_INSTALLED
499 || pkg->state_status == SS_UNPACKED)
508 static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
512 pkg_t **pkgs = vec->pkgs;
513 arch1 = pkg_get_architecture(pkg);
515 for (i = 0; i < vec->len; i++) {
516 arch2 = pkg_get_architecture(*(pkgs + i));
518 if ((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
519 && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
520 && (strcmp(arch1, arch2) == 0))
527 * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
530 int pkg_replaces(pkg_t * pkg, pkg_t * replacee)
532 abstract_pkg_t **replaces = pkg_get_ptr(pkg, PKG_REPLACES);
533 abstract_pkg_t **provides = pkg_get_ptr(replacee, PKG_PROVIDES);
534 abstract_pkg_t **r, **p;
536 for (r = replaces; r && *r; r++)
537 for (p = provides; p && *p; p++)
545 * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
548 int pkg_conflicts_abstract(pkg_t * pkg, abstract_pkg_t * conflictee)
550 compound_depend_t *conflicts, *conflict;
552 conflicts = pkg_get_ptr(pkg, PKG_CONFLICTS);
555 for (conflict = conflicts; conflict->type; conflict++) {
556 int possibility_count = conflict->possibility_count;
557 struct depend **possibilities = conflict->possibilities;
558 for (j = 0; j < possibility_count; j++) {
559 if (possibilities[j]->pkg == conflictee) {
568 * pkg_conflicts returns 1 if pkg->conflicts contains one of
569 * conflictee's provides and 0 otherwise.
571 int pkg_conflicts(pkg_t * pkg, pkg_t * conflictee)
574 int possibility_count;
575 struct depend **possibilities;
576 compound_depend_t *conflicts, *conflict;
577 abstract_pkg_t **conflictee_provides, **provider, *possibility;
579 conflicts = pkg_get_ptr(pkg, PKG_CONFLICTS);
580 conflictee_provides = pkg_get_ptr(conflictee, PKG_PROVIDES);
582 for (conflict = conflicts; conflict->type; conflict++) {
583 possibility_count = conflict->possibility_count;
584 possibilities = conflict->possibilities;
585 for (j = 0; j < possibility_count; j++) {
586 possibility = possibilities[j]->pkg;
587 for (provider = conflictee_provides; provider && *provider; provider++) {
588 if (possibility == *provider) {
597 static char **merge_unresolved(char **oldstuff, char **newstuff)
599 int oldlen = 0, newlen = 0;
606 while (oldstuff && oldstuff[oldlen])
608 while (newstuff && newstuff[newlen])
611 result = xrealloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
613 for (i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
614 *(result + i) = *(newstuff + j);
616 *(result + i) = NULL;
622 * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
623 * this is null terminated, no count is carried around
625 char **add_unresolved_dep(pkg_t * pkg, char **the_lost, int ref_ndx)
631 while (the_lost && the_lost[count])
634 count++; /* need one to hold the null */
635 resized = xrealloc(the_lost, sizeof(char *) * (count + 1));
636 resized[count - 1] = pkg_depend_str(pkg, ref_ndx);
637 resized[count] = NULL;
642 abstract_pkg_t **init_providelist(pkg_t *pkg, int *count)
644 abstract_pkg_t *ab_pkg;
645 abstract_pkg_t **provides = pkg_get_ptr(pkg, PKG_PROVIDES);
648 provides = calloc(2, sizeof(abstract_pkg_t *));
657 ab_pkg = ensure_abstract_pkg_by_name(pkg->name);
660 ab_pkg->pkgs = pkg_vec_alloc();
662 abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
664 provides[0] = ab_pkg;
670 pkg_set_ptr(pkg, PKG_PROVIDES, provides);
673 for (*count = 1; *provides; provides++)
680 void parse_providelist(pkg_t *pkg, char *list)
684 abstract_pkg_t *ab_pkg, *provided_abpkg, **tmp, **provides;
686 provides = init_providelist(pkg, &count);
687 ab_pkg = ensure_abstract_pkg_by_name(pkg->name);
689 if (!provides || !ab_pkg)
692 for (item = strtok_r(list, ", ", &tok); item;
693 count++, item = strtok_r(NULL, ", ", &tok)) {
694 tmp = realloc(provides, sizeof(abstract_pkg_t *) * (count + 1));
699 provided_abpkg = ensure_abstract_pkg_by_name(item);
701 abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
704 provides[count - 1] = provided_abpkg;
707 provides[count - 1] = NULL;
709 pkg_set_ptr(pkg, PKG_PROVIDES, provides);
712 void parse_replacelist(pkg_t *pkg, char *list)
716 abstract_pkg_t *ab_pkg, *old_abpkg, **tmp, **replaces = NULL;
718 ab_pkg = ensure_abstract_pkg_by_name(pkg->name);
721 ab_pkg->pkgs = pkg_vec_alloc();
723 abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
725 for (count = 1, item = strtok_r(list, ", ", &tok);
727 count++, item = strtok_r(NULL, ", ", &tok), count++) {
728 tmp = realloc(replaces, sizeof(abstract_pkg_t *) * (count + 1));
733 old_abpkg = ensure_abstract_pkg_by_name(item);
735 if (!old_abpkg->replaced_by)
736 old_abpkg->replaced_by = abstract_pkg_vec_alloc();
738 /* if a package pkg both replaces and conflicts old_abpkg,
739 * then add it to the replaced_by vector so that old_abpkg
740 * will be upgraded to ab_pkg automatically */
741 if (pkg_conflicts_abstract(pkg, old_abpkg))
742 abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
745 replaces[count - 1] = old_abpkg;
751 replaces[count - 1] = NULL;
753 pkg_set_ptr(pkg, PKG_REPLACES, replaces);
756 void buildProvides(abstract_pkg_t * ab_pkg, pkg_t * pkg)
761 /* every pkg provides itself */
762 pkg->provides_count++;
763 abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
764 pkg->provides = xcalloc(pkg->provides_count, sizeof(abstract_pkg_t *));
765 pkg->provides[0] = ab_pkg;
766 for (i = 1; i < pkg->provides_count; i++) {
767 abstract_pkg_t *provided_abpkg =
768 ensure_abstract_pkg_by_name(pkg->provides_str[i - 1]);
769 free(pkg->provides_str[i - 1]);
771 pkg->provides[i] = provided_abpkg;
773 abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
775 if (pkg->provides_str)
776 free(pkg->provides_str);
780 void buildConflicts(pkg_t * pkg)
784 compound_depend_t *conflicts, *conflict;
786 if (!pkg->conflicts_count)
789 conflicts = pkg->conflicts =
790 xcalloc(pkg->conflicts_count, sizeof(compound_depend_t));
791 for (i = 0; i < pkg->conflicts_count; i++) {
792 conflicts->type = CONFLICTS;
793 parseDepends(conflicts, pkg->conflicts_str[i]);
794 free(pkg->conflicts_str[i]);
797 if (pkg->conflicts_str)
798 free(pkg->conflicts_str);
802 void buildReplaces(abstract_pkg_t * ab_pkg, pkg_t * pkg)
807 if (!pkg->replaces_count)
810 pkg->replaces = xcalloc(pkg->replaces_count, sizeof(abstract_pkg_t *));
812 for (i = 0; i < pkg->replaces_count; i++) {
813 abstract_pkg_t *old_abpkg =
814 ensure_abstract_pkg_by_name(pkg->replaces_str[i]);
816 pkg->replaces[i] = old_abpkg;
817 free(pkg->replaces_str[i]);
819 if (!old_abpkg->replaced_by)
820 old_abpkg->replaced_by = abstract_pkg_vec_alloc();
821 /* if a package pkg both replaces and conflicts old_abpkg,
822 * then add it to the replaced_by vector so that old_abpkg
823 * will be upgraded to ab_pkg automatically */
824 if (pkg_conflicts_abstract(pkg, old_abpkg))
825 abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
828 if (pkg->replaces_str)
829 free(pkg->replaces_str);
833 void parse_deplist(pkg_t *pkg, enum depend_type type, char *list)
837 compound_depend_t *tmp, *deps;
857 deps = pkg_get_ptr(pkg, id);
859 for (tmp = deps, count = 1; tmp && tmp->type; tmp++)
862 for (item = strtok_r(list, ",", &tok); item; item = strtok_r(NULL, ",", &tok), count++) {
863 tmp = realloc(deps, sizeof(compound_depend_t) * (count + 1));
870 memset(deps + count - 1, 0, sizeof(compound_depend_t));
871 parseDepends(deps + count - 1, item);
873 deps[count - 1].type = type;
879 memset(deps + count - 1, 0, sizeof(compound_depend_t));
880 pkg_set_ptr(pkg, id, deps);
883 void buildDepends(pkg_t * pkg)
888 compound_depend_t *depends;
892 pkg->pre_depends_count + pkg->depends_count +
893 pkg->recommends_count + pkg->suggests_count))
896 depends = pkg->depends = xcalloc(count, sizeof(compound_depend_t));
898 for (i = 0; i < pkg->pre_depends_count; i++) {
899 parseDepends(depends, pkg->pre_depends_str[i]);
900 free(pkg->pre_depends_str[i]);
901 depends->type = PREDEPEND;
904 if (pkg->pre_depends_str)
905 free(pkg->pre_depends_str);
907 for (i = 0; i < pkg->depends_count; i++) {
908 parseDepends(depends, pkg->depends_str[i]);
909 free(pkg->depends_str[i]);
912 if (pkg->depends_str)
913 free(pkg->depends_str);
915 for (i = 0; i < pkg->recommends_count; i++) {
916 parseDepends(depends, pkg->recommends_str[i]);
917 free(pkg->recommends_str[i]);
918 depends->type = RECOMMEND;
921 if (pkg->recommends_str)
922 free(pkg->recommends_str);
924 for (i = 0; i < pkg->suggests_count; i++) {
925 parseDepends(depends, pkg->suggests_str[i]);
926 free(pkg->suggests_str[i]);
927 depends->type = SUGGEST;
930 if (pkg->suggests_str)
931 free(pkg->suggests_str);
936 const char *constraint_to_str(enum version_constraint c)
957 * Returns a printable string for pkg's dependency at the specified idx. The
958 * resultant string must be passed to free() by the caller.
960 char *pkg_depend_str(pkg_t * pkg, int idx)
965 compound_depend_t *cdep = NULL, *p;
968 for (i = 0, p = pkg_get_ptr(pkg, PKG_DEPENDS); p && p->type; i++, p++)
979 /* calculate string length */
980 for (i = 0; i < cdep->possibility_count; i++) {
981 dep = cdep->possibilities[i];
984 len += 3; /* space, pipe, space */
986 len += strlen(dep->pkg->name);
989 len += 2; /* space, left parenthesis */
990 len += 3; /* constraint string (<=, >=, etc), space */
991 len += strlen(dep->version);
992 len += 1; /* right parenthesis */
996 str = xmalloc(len + 1); /* +1 for the NULL terminator */
999 for (i = 0; i < cdep->possibility_count; i++) {
1000 dep = cdep->possibilities[i];
1003 strncat(str, " | ", len);
1005 strncat(str, dep->pkg->name, len);
1008 strncat(str, " (", len);
1009 strncat(str, constraint_to_str(dep->constraint), len);
1010 strncat(str, dep->version, len);
1011 strncat(str, ")", len);
1018 void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
1020 compound_depend_t *depends;
1023 abstract_pkg_t *ab_depend;
1024 abstract_pkg_t **temp;
1026 for (depends = pkg_get_ptr(pkg, PKG_DEPENDS); depends && depends->type; depends++) {
1027 if (depends->type != PREDEPEND
1028 && depends->type != DEPEND && depends->type != RECOMMEND)
1030 for (j = 0; j < depends->possibility_count; j++) {
1031 ab_depend = depends->possibilities[j]->pkg;
1032 if (!ab_depend->depended_upon_by) {
1033 ab_depend->depended_upon_by =
1034 xcalloc(1, sizeof(abstract_pkg_t *));
1037 temp = ab_depend->depended_upon_by;
1045 ab_depend->depended_upon_by =
1046 xrealloc(ab_depend->depended_upon_by,
1048 1) * sizeof(abstract_pkg_t *));
1050 /* the array may have been moved by realloc */
1051 temp = ab_depend->depended_upon_by + othercount;
1057 static depend_t *depend_init(void)
1059 depend_t *d = xcalloc(1, sizeof(depend_t));
1060 d->constraint = NONE;
1067 static int parseDepends(compound_depend_t * compound_depend, char *depend_str)
1070 char *depend, *name, *vstr, *rest, *tok = NULL;
1071 depend_t **possibilities = NULL, **tmp;
1073 compound_depend->type = DEPEND;
1075 for (i = 0, depend = strtok_r(depend_str, "|", &tok); depend; i++, depend = strtok_r(NULL, "|", &tok)) {
1076 name = strtok(depend, " ");
1077 rest = strtok(NULL, "\n");
1079 tmp = realloc(possibilities, sizeof(tmp) * (i + 1));
1084 possibilities = tmp;
1085 possibilities[i] = depend_init();
1086 possibilities[i]->pkg = ensure_abstract_pkg_by_name(name);
1088 if (rest && *rest == '(') {
1089 vstr = strtok(rest + 1, ")");
1091 if (!strncmp(vstr, "<<", 2)) {
1092 possibilities[i]->constraint = EARLIER;
1094 } else if (!strncmp(vstr, "<=", 2)) {
1095 possibilities[i]->constraint = EARLIER_EQUAL;
1097 } else if (!strncmp(vstr, ">=", 2)) {
1098 possibilities[i]->constraint = LATER_EQUAL;
1100 } else if (!strncmp(vstr, ">>", 2)) {
1101 possibilities[i]->constraint = LATER;
1103 } else if (!strncmp(vstr, "=", 1)) {
1104 possibilities[i]->constraint = EQUAL;
1107 /* should these be here to support deprecated designations; dpkg does */
1108 else if (!strncmp(vstr, "<", 1)) {
1109 possibilities[i]->constraint = EARLIER_EQUAL;
1111 } else if (!strncmp(vstr, ">", 1)) {
1112 possibilities[i]->constraint = LATER_EQUAL;
1116 possibilities[i]->version = trim_xstrdup(vstr);
1117 rest = strtok(NULL, " ");
1120 rest = strtok(rest, " ");
1123 if (rest && *rest == '*')
1124 compound_depend->type = GREEDY_DEPEND;
1127 compound_depend->possibility_count = i;
1128 compound_depend->possibilities = possibilities;
1133 compound_depend_t *pkg_get_depends(pkg_t *pkg, enum depend_type type)
1135 compound_depend_t *dep;
1137 for (dep = pkg_get_ptr(pkg, PKG_DEPENDS); dep && dep->type; dep++)
1138 if (type == UNSPEC || dep->type == type)