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.
23 #include "opkg_utils.h"
25 #include "opkg_message.h"
26 #include "pkg_parse.h"
27 #include "hash_table.h"
28 #include "libbb/libbb.h"
30 static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
31 static depend_t * depend_init(void);
32 static void depend_deinit(depend_t *d);
33 static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
34 static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
35 static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
37 static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
39 depend_t *depend = (depend_t *)cdata;
40 if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && 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 ndependences or negative error value */
56 int pkg_hash_fetch_unsatisfied_dependencies(opkg_conf_t *conf, pkg_t * pkg,
57 pkg_vec_t *unsatisfied, char *** unresolved)
59 pkg_t * satisfier_entry_pkg;
63 abstract_pkg_t * ab_pkg;
66 * this is a setup to check for redundant/cyclic dependency checks,
67 * which are marked at the abstract_pkg level
69 if (!(ab_pkg = pkg->parent)) {
70 fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
74 if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
78 ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
82 count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
90 /* foreach dependency */
91 for (i = 0; i < count; i++) {
92 compound_depend_t * compound_depend = &pkg->depends[i];
93 depend_t ** possible_satisfiers = compound_depend->possibilities;;
95 satisfier_entry_pkg = NULL;
97 if (compound_depend->type == GREEDY_DEPEND) {
98 /* foreach possible satisfier */
99 for (j = 0; j < compound_depend->possibility_count; j++) {
100 /* foreach provided_by, which includes the abstract_pkg itself */
101 abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
102 abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
103 int nposs = ab_provider_vec->len;
104 abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
106 for (l = 0; l < nposs; l++) {
107 pkg_vec_t *test_vec = ab_providers[l]->pkgs;
108 /* if no depends on this one, try the first package that Provides this one */
109 if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
113 /* cruise this possiblity's pkg_vec looking for an installed version */
114 for (k = 0; k < test_vec->len; k++) {
115 pkg_t *pkg_scout = test_vec->pkgs[k];
116 /* not installed, and not already known about? */
117 if ((pkg_scout->state_want != SW_INSTALL)
118 && !pkg_scout->parent->dependencies_checked
119 && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
120 char ** newstuff = NULL;
122 pkg_vec_t *tmp_vec = pkg_vec_alloc ();
123 /* check for not-already-installed dependencies */
124 rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
128 if (newstuff == NULL) {
131 for (i = 0; i < rc; i++) {
132 pkg_t *p = tmp_vec->pkgs[i];
133 if (p->state_want == SW_INSTALL)
135 opkg_message(conf, OPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
139 pkg_vec_free (tmp_vec);
141 /* mark this one for installation */
142 opkg_message(conf, OPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
143 pkg_vec_insert(unsatisfied, pkg_scout);
146 opkg_message(conf, OPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
157 /* foreach possible satisfier, look for installed package */
158 for (j = 0; j < compound_depend->possibility_count; j++) {
159 /* foreach provided_by, which includes the abstract_pkg itself */
160 depend_t *dependence_to_satisfy = possible_satisfiers[j];
161 abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
162 pkg_t *satisfying_pkg =
163 pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
164 pkg_installed_and_constraint_satisfied,
165 dependence_to_satisfy, 1, NULL);
166 /* Being that I can't test constraing in pkg_hash, I will test it here */
167 if (satisfying_pkg != NULL) {
168 if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
169 satisfying_pkg = NULL;
172 opkg_message(conf, OPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
173 if (satisfying_pkg != NULL) {
179 /* if nothing installed matches, then look for uninstalled satisfier */
181 /* foreach possible satisfier, look for installed package */
182 for (j = 0; j < compound_depend->possibility_count; j++) {
183 /* foreach provided_by, which includes the abstract_pkg itself */
184 depend_t *dependence_to_satisfy = possible_satisfiers[j];
185 abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
186 pkg_t *satisfying_pkg =
187 pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
188 pkg_constraint_satisfied,
189 dependence_to_satisfy, 1, NULL);
190 /* Being that I can't test constraing in pkg_hash, I will test it here too */
191 if (satisfying_pkg != NULL) {
192 if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
193 satisfying_pkg = NULL;
197 /* user request overrides package recommendation */
198 if (satisfying_pkg != NULL
199 && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
200 && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
201 opkg_message (conf, OPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
202 pkg->name, satisfying_pkg->name);
206 opkg_message(conf, OPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
207 if (satisfying_pkg != NULL) {
208 satisfier_entry_pkg = satisfying_pkg;
214 /* we didn't find one, add something to the unsatisfied vector */
216 if (!satisfier_entry_pkg) {
217 /* failure to meet recommendations is not an error */
218 if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
219 the_lost = add_unresolved_dep(pkg, the_lost, i);
221 opkg_message (conf, OPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
222 pkg->name, compound_depend->possibilities[0]->pkg->name);
225 if (compound_depend->type == SUGGEST) {
226 /* just mention it politely */
227 opkg_message (conf, OPKG_NOTICE, "package %s suggests installing %s\n",
228 pkg->name, satisfier_entry_pkg->name);
230 char ** newstuff = NULL;
232 if (satisfier_entry_pkg != pkg &&
233 !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
234 pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
235 pkg_hash_fetch_unsatisfied_dependencies(conf,
239 the_lost = merge_unresolved(the_lost, newstuff);
245 *unresolved = the_lost;
247 return unsatisfied->len;
250 /*checking for conflicts !in replaces
251 If a packages conflicts with another but is also replacing it, I should not consider it a
253 returns 0 if conflicts <> replaces or 1 if conflicts == replaces
255 int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
258 int replaces_count = pkg->replaces_count;
259 abstract_pkg_t **replaces;
261 if (pkg->replaces_count==0) // No replaces, it's surely a conflict
264 replaces = pkg->replaces;
266 for (i = 0; i < replaces_count; i++) {
267 if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found
268 opkg_message(NULL, OPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name);
277 /* Abhaya: added support for conflicts */
278 pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg)
280 pkg_vec_t * installed_conflicts, * test_vec;
281 compound_depend_t * conflicts;
282 depend_t ** possible_satisfiers;
283 depend_t * possible_satisfier;
286 abstract_pkg_t * ab_pkg;
291 * this is a setup to check for redundant/cyclic dependency checks,
292 * which are marked at the abstract_pkg level
294 if(!(ab_pkg = pkg->parent)){
295 fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
296 return (pkg_vec_t *)NULL;
299 conflicts = pkg->conflicts;
301 return (pkg_vec_t *)NULL;
303 installed_conflicts = pkg_vec_alloc();
305 count = pkg->conflicts_count;
309 /* foreach conflict */
310 for(i = 0; i < pkg->conflicts_count; i++){
312 possible_satisfiers = conflicts->possibilities;
314 /* foreach possible satisfier */
315 for(j = 0; j < conflicts->possibility_count; j++){
316 possible_satisfier = possible_satisfiers[j];
317 if (!possible_satisfier)
318 fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
319 if (!possible_satisfier->pkg)
320 fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
321 test_vec = possible_satisfier->pkg->pkgs;
323 /* pkg_vec found, it is an actual package conflict
324 * cruise this possiblity's pkg_vec looking for an installed version */
325 pkg_scouts = test_vec->pkgs;
326 for(k = 0; k < test_vec->len; k++){
327 pkg_scout = pkg_scouts[k];
329 fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
332 if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
333 version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
334 if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
335 pkg_vec_insert(installed_conflicts, pkg_scout);
344 if (installed_conflicts->len)
345 return installed_conflicts;
346 pkg_vec_free(installed_conflicts);
347 return (pkg_vec_t *)NULL;
350 int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
355 if(depends->constraint == NONE)
360 parseVersion(temp, depends->version);
362 comparison = pkg_compare_versions(pkg, temp);
364 free (temp->version);
367 if((depends->constraint == EARLIER) &&
370 else if((depends->constraint == LATER) &&
373 else if(comparison == 0)
375 else if((depends->constraint == LATER_EQUAL) &&
378 else if((depends->constraint == EARLIER_EQUAL) &&
385 int pkg_dependence_satisfiable(opkg_conf_t *conf, depend_t *depend)
387 abstract_pkg_t *apkg = depend->pkg;
388 abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
389 int n_providers = provider_apkgs->len;
390 abstract_pkg_t **apkgs = provider_apkgs->pkgs;
396 for (i = 0; i < n_providers; i++) {
397 abstract_pkg_t *papkg = apkgs[i];
398 pkg_vec = papkg->pkgs;
400 n_pkgs = pkg_vec->len;
401 for (j = 0; j < n_pkgs; j++) {
402 pkg_t *pkg = pkg_vec->pkgs[j];
403 if (version_constraints_satisfied(depend, pkg)) {
412 int pkg_dependence_satisfied(opkg_conf_t *conf, depend_t *depend)
414 abstract_pkg_t *apkg = depend->pkg;
415 abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
416 int n_providers = provider_apkgs->len;
417 abstract_pkg_t **apkgs = provider_apkgs->pkgs;
422 for (i = 0; i < n_providers; i++) {
423 abstract_pkg_t *papkg = apkgs[i];
424 pkg_vec_t *pkg_vec = papkg->pkgs;
426 n_pkgs = pkg_vec->len;
427 for (j = 0; j < n_pkgs; j++) {
428 pkg_t *pkg = pkg_vec->pkgs[j];
429 if (version_constraints_satisfied(depend, pkg)) {
430 if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
439 static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
442 pkg_t ** pkgs = vec->pkgs;
444 for(i = 0; i < vec->len; i++)
445 if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
446 && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
447 && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
455 * pkg_has_common_provides returns 1 if pkg and replacee both provide
456 * the same abstract package and 0 otherwise.
458 int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
460 abstract_pkg_t **provides = pkg->provides;
461 int provides_count = pkg->provides_count;
462 abstract_pkg_t **replacee_provides = replacee->provides;
463 int replacee_provides_count = replacee->provides_count;
465 for (i = 0; i < provides_count; i++) {
466 abstract_pkg_t *apkg = provides[i];
467 for (j = 0; j < replacee_provides_count; j++) {
468 abstract_pkg_t *replacee_apkg = replacee_provides[i];
469 if (apkg == replacee_apkg)
478 * pkg_provides_abstract returns 1 if pkg->provides contains providee
481 int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
483 abstract_pkg_t **provides = pkg->provides;
484 int provides_count = pkg->provides_count;
486 for (i = 0; i < provides_count; i++) {
487 if (provides[i] == providee)
494 * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
497 int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
499 abstract_pkg_t **replaces = pkg->replaces;
500 int replaces_count = pkg->replaces_count;
501 /* abstract_pkg_t **replacee_provides = pkg->provides;
502 int replacee_provides_count = pkg->provides_count; */
504 for (i = 0; i < replaces_count; i++) {
505 abstract_pkg_t *abstract_replacee = replaces[i];
506 for (j = 0; j < replaces_count; j++) {
507 /* opkg_message(NULL, OPKG_DEBUG2, "Searching pkg-name %s repprovname %s absrepname %s \n",
508 pkg->name,replacee->provides[j]->name, abstract_replacee->name); */
509 if (replacee->provides[j] == abstract_replacee)
518 * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
521 int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
523 compound_depend_t *conflicts = pkg->conflicts;
524 int conflicts_count = pkg->conflicts_count;
526 for (i = 0; i < conflicts_count; i++) {
527 int possibility_count = conflicts[i].possibility_count;
528 struct depend **possibilities = conflicts[i].possibilities;
529 for (j = 0; j < possibility_count; j++) {
530 if (possibilities[j]->pkg == conflictee) {
539 * pkg_conflicts returns 1 if pkg->conflicts contains one of
540 * conflictee's provides and 0 otherwise.
542 int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
544 compound_depend_t *conflicts = pkg->conflicts;
545 int conflicts_count = pkg->conflicts_count;
546 abstract_pkg_t **conflictee_provides = conflictee->provides;
547 int conflictee_provides_count = conflictee->provides_count;
549 int possibility_count;
550 struct depend **possibilities;
551 abstract_pkg_t *possibility ;
553 for (i = 0; i < conflicts_count; i++) {
554 possibility_count = conflicts[i].possibility_count;
555 possibilities = conflicts[i].possibilities;
556 for (j = 0; j < possibility_count; j++) {
557 possibility = possibilities[j]->pkg;
558 for (k = 0; k < conflictee_provides_count; k++) {
559 if (possibility == conflictee_provides[k]) {
568 static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
570 int oldlen = 0, newlen = 0;
577 while(oldstuff && oldstuff[oldlen]) oldlen++;
578 while(newstuff && newstuff[newlen]) newlen++;
580 result = xrealloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
582 for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
583 *(result + i) = *(newstuff + j);
585 *(result + i) = NULL;
591 * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
592 * this is null terminated, no count is carried around
594 char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
598 char *depend_str = pkg_depend_str(pkg, ref_ndx);
601 while(the_lost && the_lost[count]) count++;
603 count++; /* need one to hold the null */
604 resized = xrealloc(the_lost, sizeof(char *) * (count + 1));
605 resized[count - 1] = xstrdup(depend_str);
606 resized[count] = NULL;
611 void printDepends(pkg_t * pkg)
614 compound_depend_t * depend;
617 count = pkg->pre_depends_count + pkg->depends_count;
619 depend = pkg->depends;
621 fprintf(stderr, "Depends pointer is NULL\n");
624 for(i = 0; i < count; i++){
625 fprintf(stderr, "%s has %d possibilities:\n",
626 (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
627 depend->possibility_count);
628 for(j = 0; j < depend->possibility_count; j++)
629 fprintf(stderr, "\t%s version %s (%d)\n",
630 depend->possibilities[j]->pkg->name,
631 depend->possibilities[j]->version,
632 depend->possibilities[j]->constraint);
637 int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
641 /* every pkg provides itself */
642 abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
644 if (!pkg->provides_count)
649 pkg->provides = xcalloc((pkg->provides_count + 1), sizeof(abstract_pkg_t *));
650 pkg->provides[0] = ab_pkg;
652 // if (strcmp(ab_pkg->name, pkg->name))
653 // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
655 for(i = 0; i < pkg->provides_count; i++){
656 abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
658 pkg->provides[i+1] = provided_abpkg;
661 abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
666 /* Abhaya: added conflicts support */
667 int buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
670 compound_depend_t * conflicts;
672 if (!pkg->conflicts_count)
675 conflicts = pkg->conflicts = xcalloc(pkg->conflicts_count, sizeof(compound_depend_t));
676 for (i = 0; i < pkg->conflicts_count; i++) {
677 conflicts->type = CONFLICTS;
678 parseDepends(conflicts, hash,
679 pkg->conflicts_str[i]);
685 int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
689 if (!pkg->replaces_count)
692 pkg->replaces = xcalloc(pkg->replaces_count, sizeof(abstract_pkg_t *));
694 for(i = 0; i < pkg->replaces_count; i++){
695 abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
697 pkg->replaces[i] = old_abpkg;
700 if (!old_abpkg->replaced_by)
701 old_abpkg->replaced_by = abstract_pkg_vec_alloc();
702 /* if a package pkg both replaces and conflicts old_abpkg,
703 * then add it to the replaced_by vector so that old_abpkg
704 * will be upgraded to ab_pkg automatically */
705 if (pkg_conflicts_abstract(pkg, old_abpkg))
706 abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
711 int buildDepends(hash_table_t * hash, pkg_t * pkg)
715 compound_depend_t * depends;
717 if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
720 if (0 && pkg->pre_depends_count)
721 fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
722 pkg->name, pkg->pre_depends_count, pkg->depends_count);
723 depends = pkg->depends = xcalloc(count, sizeof(compound_depend_t));
725 for(i = 0; i < pkg->pre_depends_count; i++){
726 parseDepends(depends, hash, pkg->pre_depends_str[i]);
727 if (0 && pkg->pre_depends_count)
728 fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
729 pkg->pre_depends_str[i], depends, depends->possibility_count);
730 depends->type = PREDEPEND;
734 for(i = 0; i < pkg->recommends_count; i++){
735 parseDepends(depends, hash, pkg->recommends_str[i]);
736 if (0 && pkg->recommends_count)
737 fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
738 pkg->recommends_str[i], depends, depends->possibility_count);
739 depends->type = RECOMMEND;
743 for(i = 0; i < pkg->suggests_count; i++){
744 parseDepends(depends, hash, pkg->suggests_str[i]);
745 if (0 && pkg->suggests_count)
746 fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
747 pkg->suggests_str[i], depends, depends->possibility_count);
748 depends->type = SUGGEST;
752 for(i = 0; i < pkg->depends_count; i++){
753 parseDepends(depends, hash, pkg->depends_str[i]);
754 if (0 && pkg->depends_count)
755 fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
756 pkg->depends_str[i], depends, depends->possibility_count);
763 * pkg_depend_string: returns the depends string specified by index.
764 * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
765 * [0,npredepends) -> returns pre_depends_str[index]
766 * [npredepends,npredepends+nrecommends) -> returns recommends_str[index]
767 * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index]
768 * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index]
770 char *pkg_depend_str(pkg_t *pkg, int index)
772 if (index < pkg->pre_depends_count) {
773 return pkg->pre_depends_str[index];
775 index -= pkg->pre_depends_count;
777 if (index < pkg->recommends_count) {
778 return pkg->recommends_str[index];
780 index -= pkg->recommends_count;
782 if (index < pkg->suggests_count) {
783 return pkg->suggests_str[index];
785 index -= pkg->suggests_count;
787 if (index < pkg->depends_count) {
788 return pkg->depends_str[index];
790 fprintf(stderr, "pkg_depend_str: index %d out of range for pkg=%s\n", index, pkg->name);
794 void freeDepends(pkg_t *pkg)
798 if (pkg == NULL || pkg->depends == NULL) {
802 fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
803 for (i=0; i < pkg->depends->possibility_count; i++) {
804 depend_deinit(pkg->depends->possibilities[i]);
806 free(pkg->depends->possibilities);
811 void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
813 compound_depend_t * depends;
814 int count, othercount;
816 abstract_pkg_t * ab_depend;
817 abstract_pkg_t ** temp;
819 count = pkg->pre_depends_count + pkg->depends_count;
820 depends = pkg->depends;
822 if (0 && pkg->pre_depends_count)
823 fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
824 pkg->name, pkg->pre_depends_count, pkg->depends_count);
825 for (i = 0; i < count; i++) {
826 if (0 && pkg->pre_depends_count)
827 fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
828 for (j = 0; j < depends->possibility_count; j++){
829 ab_depend = depends->possibilities[j]->pkg;
830 if(!ab_depend->depended_upon_by)
831 ab_depend->depended_upon_by = xcalloc(1, sizeof(abstract_pkg_t *));
833 temp = ab_depend->depended_upon_by;
841 ab_depend->depended_upon_by = xrealloc(ab_depend->depended_upon_by,
842 (othercount + 1) * sizeof(abstract_pkg_t *));
843 /* the array may have moved */
844 temp = ab_depend->depended_upon_by + othercount;
851 static depend_t * depend_init(void)
853 depend_t * d = xcalloc(1, sizeof(depend_t));
854 d->constraint = NONE;
861 static void depend_deinit(depend_t *d)
866 static int parseDepends(compound_depend_t *compound_depend,
867 hash_table_t * hash, char * depend_str)
869 char * pkg_name, buffer[2048];
873 depend_t ** possibilities;
875 /* first count the number of ored possibilities for satisfying dependency */
881 compound_depend->type = DEPEND;
883 compound_depend->possibility_count = num_of_ors + 1;
884 possibilities = xcalloc((num_of_ors + 1), sizeof(depend_t *) );
885 compound_depend->possibilities = possibilities;
888 for(i = 0; i < num_of_ors + 1; i++){
889 possibilities[i] = depend_init();
890 /* gobble up just the name first */
899 pkg_name = trim_alloc(buffer);
900 if (pkg_name == NULL )
903 /* now look at possible version info */
905 /* skip to next chars */
907 while(*src && isspace(*src)) src++;
909 /* extract constraint and version */
912 if(!strncmp(src, "<<", 2)){
913 possibilities[i]->constraint = EARLIER;
916 else if(!strncmp(src, "<=", 2)){
917 possibilities[i]->constraint = EARLIER_EQUAL;
920 else if(!strncmp(src, ">=", 2)){
921 possibilities[i]->constraint = LATER_EQUAL;
924 else if(!strncmp(src, ">>", 2)){
925 possibilities[i]->constraint = LATER;
928 else if(!strncmp(src, "=", 1)){
929 possibilities[i]->constraint = EQUAL;
932 /* should these be here to support deprecated designations; dpkg does */
933 else if(!strncmp(src, "<", 1)){
934 possibilities[i]->constraint = EARLIER_EQUAL;
937 else if(!strncmp(src, ">", 1)){
938 possibilities[i]->constraint = LATER_EQUAL;
942 /* now we have any constraint, pass space to version string */
943 while(isspace(*src)) src++;
945 /* this would be the version string */
947 while(*src && *src != ')')
951 possibilities[i]->version = trim_alloc(buffer);
952 /* fprintf(stderr, "let's print the depends version string:");
953 fprintf(stderr, "version %s\n", possibilities[i]->version);*/
954 if (possibilities[i]->version == NULL )
959 /* hook up the dependency to its abstract pkg */
960 possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
964 /* now get past the ) and any possible | chars */
972 compound_depend->type = GREEDY_DEPEND;