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
|| pkg
->state_status
== SS_UNPACKED
) && version_constraints_satisfied(depend
, pkg
))
44 static int pkg_constraint_satisfied(pkg_t
*pkg
, void *cdata
)
46 depend_t
*depend
= (depend_t
*)cdata
;
47 if (version_constraints_satisfied(depend
, pkg
))
53 /* returns ndependencies or negative error value */
55 pkg_hash_fetch_unsatisfied_dependencies(pkg_t
* pkg
, pkg_vec_t
*unsatisfied
,
58 pkg_t
* satisfier_entry_pkg
;
62 abstract_pkg_t
* ab_pkg
;
65 * this is a setup to check for redundant/cyclic dependency checks,
66 * which are marked at the abstract_pkg level
68 if (!(ab_pkg
= pkg
->parent
)) {
69 opkg_msg(ERROR
, "Internal error, with pkg %s.\n", pkg
->name
);
73 if (ab_pkg
->dependencies_checked
) { /* avoid duplicate or cyclic checks */
77 ab_pkg
->dependencies_checked
= 1; /* mark it for subsequent visits */
81 count
= pkg
->pre_depends_count
+ pkg
->depends_count
+ pkg
->recommends_count
+ pkg
->suggests_count
;
89 /* foreach dependency */
90 for (i
= 0; i
< count
; i
++) {
91 compound_depend_t
* compound_depend
= &pkg
->depends
[i
];
92 depend_t
** possible_satisfiers
= compound_depend
->possibilities
;;
94 satisfier_entry_pkg
= NULL
;
96 if (compound_depend
->type
== GREEDY_DEPEND
) {
97 /* foreach possible satisfier */
98 for (j
= 0; j
< compound_depend
->possibility_count
; j
++) {
99 /* foreach provided_by, which includes the abstract_pkg itself */
100 abstract_pkg_t
*abpkg
= possible_satisfiers
[j
]->pkg
;
101 abstract_pkg_vec_t
*ab_provider_vec
= abpkg
->provided_by
;
102 int nposs
= ab_provider_vec
->len
;
103 abstract_pkg_t
**ab_providers
= ab_provider_vec
->pkgs
;
105 for (l
= 0; l
< nposs
; l
++) {
106 pkg_vec_t
*test_vec
= ab_providers
[l
]->pkgs
;
107 /* if no depends on this one, try the first package that Provides this one */
108 if (!test_vec
){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
112 /* cruise this possiblity's pkg_vec looking for an installed version */
113 for (k
= 0; k
< test_vec
->len
; k
++) {
114 pkg_t
*pkg_scout
= test_vec
->pkgs
[k
];
115 /* not installed, and not already known about? */
116 if ((pkg_scout
->state_want
!= SW_INSTALL
)
117 && !pkg_scout
->parent
->dependencies_checked
118 && !is_pkg_in_pkg_vec(unsatisfied
, pkg_scout
)) {
119 char ** newstuff
= NULL
;
121 pkg_vec_t
*tmp_vec
= pkg_vec_alloc ();
122 /* check for not-already-installed dependencies */
123 rc
= pkg_hash_fetch_unsatisfied_dependencies(pkg_scout
,
126 if (newstuff
== NULL
) {
129 for (m
= 0; m
< rc
; m
++) {
130 pkg_t
*p
= tmp_vec
->pkgs
[m
];
131 if (p
->state_want
== SW_INSTALL
)
134 "Not installing %s due"
135 " to requirement for %s.\n",
141 pkg_vec_free (tmp_vec
);
143 /* mark this one for installation */
145 "Adding satisfier for greedy"
148 pkg_vec_insert(unsatisfied
, pkg_scout
);
152 "Not installing %s due to "
165 /* foreach possible satisfier, look for installed package */
166 for (j
= 0; j
< compound_depend
->possibility_count
; j
++) {
167 /* foreach provided_by, which includes the abstract_pkg itself */
168 depend_t
*dependence_to_satisfy
= possible_satisfiers
[j
];
169 abstract_pkg_t
*satisfying_apkg
= possible_satisfiers
[j
]->pkg
;
170 pkg_t
*satisfying_pkg
=
171 pkg_hash_fetch_best_installation_candidate(satisfying_apkg
,
172 pkg_installed_and_constraint_satisfied
,
173 dependence_to_satisfy
, 1);
174 /* Being that I can't test constraing in pkg_hash, I will test it here */
175 if (satisfying_pkg
!= NULL
) {
176 if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg
,dependence_to_satisfy
)) {
177 satisfying_pkg
= NULL
;
180 opkg_msg(DEBUG
, "satisfying_pkg=%p\n", satisfying_pkg
);
181 if (satisfying_pkg
!= NULL
) {
187 /* if nothing installed matches, then look for uninstalled satisfier */
189 /* foreach possible satisfier, look for installed package */
190 for (j
= 0; j
< compound_depend
->possibility_count
; j
++) {
191 /* foreach provided_by, which includes the abstract_pkg itself */
192 depend_t
*dependence_to_satisfy
= possible_satisfiers
[j
];
193 abstract_pkg_t
*satisfying_apkg
= possible_satisfiers
[j
]->pkg
;
194 pkg_t
*satisfying_pkg
=
195 pkg_hash_fetch_best_installation_candidate(satisfying_apkg
,
196 pkg_constraint_satisfied
,
197 dependence_to_satisfy
, 1);
198 /* Being that I can't test constraing in pkg_hash, I will test it here too */
199 if (satisfying_pkg
!= NULL
) {
200 if (!pkg_constraint_satisfied ( satisfying_pkg
,dependence_to_satisfy
)) {
201 satisfying_pkg
= NULL
;
205 /* user request overrides package recommendation */
206 if (satisfying_pkg
!= NULL
207 && (compound_depend
->type
== RECOMMEND
|| compound_depend
->type
== SUGGEST
)
208 && (satisfying_pkg
->state_want
== SW_DEINSTALL
|| satisfying_pkg
->state_want
== SW_PURGE
)) {
209 opkg_msg(NOTICE
, "%s: ignoring recommendation for "
210 "%s at user request\n",
211 pkg
->name
, satisfying_pkg
->name
);
215 opkg_msg(DEBUG
, "satisfying_pkg=%p\n", satisfying_pkg
);
216 if (satisfying_pkg
!= NULL
) {
217 satisfier_entry_pkg
= satisfying_pkg
;
223 /* we didn't find one, add something to the unsatisfied vector */
225 if (!satisfier_entry_pkg
) {
226 /* failure to meet recommendations is not an error */
227 if (compound_depend
->type
!= RECOMMEND
&& compound_depend
->type
!= SUGGEST
)
228 the_lost
= add_unresolved_dep(pkg
, the_lost
, i
);
231 "%s: unsatisfied recommendation for %s\n",
233 compound_depend
->possibilities
[0]->pkg
->name
);
236 if (compound_depend
->type
== SUGGEST
) {
237 /* just mention it politely */
238 opkg_msg(NOTICE
, "package %s suggests installing %s\n",
239 pkg
->name
, satisfier_entry_pkg
->name
);
241 char ** newstuff
= NULL
;
243 if (satisfier_entry_pkg
!= pkg
&&
244 !is_pkg_in_pkg_vec(unsatisfied
, satisfier_entry_pkg
)) {
245 pkg_vec_insert(unsatisfied
, satisfier_entry_pkg
);
246 pkg_hash_fetch_unsatisfied_dependencies(satisfier_entry_pkg
,
249 the_lost
= merge_unresolved(the_lost
, newstuff
);
257 *unresolved
= the_lost
;
259 return unsatisfied
->len
;
262 /*checking for conflicts !in replaces
263 If a packages conflicts with another but is also replacing it, I should not consider it a
265 returns 0 if conflicts <> replaces or 1 if conflicts == replaces
268 is_pkg_a_replaces(pkg_t
*pkg_scout
,pkg_t
*pkg
)
271 int replaces_count
= pkg
->replaces_count
;
272 abstract_pkg_t
**replaces
;
274 if (pkg
->replaces_count
==0) // No replaces, it's surely a conflict
277 replaces
= pkg
->replaces
;
279 for (i
= 0; i
< replaces_count
; i
++) {
280 if (strcmp(pkg_scout
->name
,pkg
->replaces
[i
]->name
)==0) { // Found
281 opkg_msg(DEBUG2
, "Seems I've found a replace %s %s\n",
282 pkg_scout
->name
, pkg
->replaces
[i
]->name
);
291 pkg_vec_t
* pkg_hash_fetch_conflicts(pkg_t
* pkg
)
293 pkg_vec_t
* installed_conflicts
, * test_vec
;
294 compound_depend_t
* conflicts
;
295 depend_t
** possible_satisfiers
;
296 depend_t
* possible_satisfier
;
299 abstract_pkg_t
* ab_pkg
;
304 * this is a setup to check for redundant/cyclic dependency checks,
305 * which are marked at the abstract_pkg level
307 if(!(ab_pkg
= pkg
->parent
)){
308 opkg_msg(ERROR
, "Internal error: %s not in hash table\n", pkg
->name
);
309 return (pkg_vec_t
*)NULL
;
312 conflicts
= pkg
->conflicts
;
314 return (pkg_vec_t
*)NULL
;
316 installed_conflicts
= pkg_vec_alloc();
318 count
= pkg
->conflicts_count
;
322 /* foreach conflict */
323 for(i
= 0; i
< pkg
->conflicts_count
; i
++){
325 possible_satisfiers
= conflicts
->possibilities
;
327 /* foreach possible satisfier */
328 for(j
= 0; j
< conflicts
->possibility_count
; j
++){
329 possible_satisfier
= possible_satisfiers
[j
];
330 if (!possible_satisfier
)
331 opkg_msg(ERROR
, "Internal error: possible_satisfier=NULL\n");
332 if (!possible_satisfier
->pkg
)
333 opkg_msg(ERROR
, "Internal error: possible_satisfier->pkg=NULL\n");
334 test_vec
= possible_satisfier
->pkg
->pkgs
;
336 /* pkg_vec found, it is an actual package conflict
337 * cruise this possiblity's pkg_vec looking for an installed version */
338 pkg_scouts
= test_vec
->pkgs
;
339 for(k
= 0; k
< test_vec
->len
; k
++){
340 pkg_scout
= pkg_scouts
[k
];
342 opkg_msg(ERROR
, "Internal error: pkg_scout=NULL\n");
345 if ((pkg_scout
->state_status
== SS_INSTALLED
|| pkg_scout
->state_want
== SW_INSTALL
) &&
346 version_constraints_satisfied(possible_satisfier
, pkg_scout
) && !is_pkg_a_replaces(pkg_scout
,pkg
)){
347 if (!is_pkg_in_pkg_vec(installed_conflicts
, pkg_scout
)){
348 pkg_vec_insert(installed_conflicts
, pkg_scout
);
357 if (installed_conflicts
->len
)
358 return installed_conflicts
;
359 pkg_vec_free(installed_conflicts
);
360 return (pkg_vec_t
*)NULL
;
363 int version_constraints_satisfied(depend_t
* depends
, pkg_t
* pkg
)
368 if(depends
->constraint
== NONE
)
373 parse_version(temp
, depends
->version
);
375 comparison
= pkg_compare_versions(pkg
, temp
);
377 free (temp
->version
);
380 if((depends
->constraint
== EARLIER
) &&
383 else if((depends
->constraint
== LATER
) &&
386 else if(comparison
== 0)
388 else if((depends
->constraint
== LATER_EQUAL
) &&
391 else if((depends
->constraint
== EARLIER_EQUAL
) &&
398 int pkg_dependence_satisfiable(depend_t
*depend
)
400 abstract_pkg_t
*apkg
= depend
->pkg
;
401 abstract_pkg_vec_t
*provider_apkgs
= apkg
->provided_by
;
402 int n_providers
= provider_apkgs
->len
;
403 abstract_pkg_t
**apkgs
= provider_apkgs
->pkgs
;
409 for (i
= 0; i
< n_providers
; i
++) {
410 abstract_pkg_t
*papkg
= apkgs
[i
];
411 pkg_vec
= papkg
->pkgs
;
413 n_pkgs
= pkg_vec
->len
;
414 for (j
= 0; j
< n_pkgs
; j
++) {
415 pkg_t
*pkg
= pkg_vec
->pkgs
[j
];
416 if (version_constraints_satisfied(depend
, pkg
)) {
425 int pkg_dependence_satisfied(depend_t
*depend
)
427 abstract_pkg_t
*apkg
= depend
->pkg
;
428 abstract_pkg_vec_t
*provider_apkgs
= apkg
->provided_by
;
429 int n_providers
= provider_apkgs
->len
;
430 abstract_pkg_t
**apkgs
= provider_apkgs
->pkgs
;
435 for (i
= 0; i
< n_providers
; i
++) {
436 abstract_pkg_t
*papkg
= apkgs
[i
];
437 pkg_vec_t
*pkg_vec
= papkg
->pkgs
;
439 n_pkgs
= pkg_vec
->len
;
440 for (j
= 0; j
< n_pkgs
; j
++) {
441 pkg_t
*pkg
= pkg_vec
->pkgs
[j
];
442 if (version_constraints_satisfied(depend
, pkg
)) {
443 if (pkg
->state_status
== SS_INSTALLED
|| pkg
->state_status
== SS_UNPACKED
)
452 static int is_pkg_in_pkg_vec(pkg_vec_t
* vec
, pkg_t
* pkg
)
455 pkg_t
** pkgs
= vec
->pkgs
;
457 for(i
= 0; i
< vec
->len
; i
++)
458 if((strcmp(pkg
->name
, (*(pkgs
+ i
))->name
) == 0)
459 && (pkg_compare_versions(pkg
, *(pkgs
+ i
)) == 0)
460 && (strcmp(pkg
->architecture
, (*(pkgs
+ i
))->architecture
) == 0))
466 * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
469 int pkg_replaces(pkg_t
*pkg
, pkg_t
*replacee
)
471 abstract_pkg_t
**replaces
= pkg
->replaces
;
472 int replaces_count
= pkg
->replaces_count
;
473 int replacee_provides_count
= replacee
->provides_count
;
475 for (i
= 0; i
< replaces_count
; i
++) {
476 abstract_pkg_t
*abstract_replacee
= replaces
[i
];
477 for (j
= 0; j
< replacee_provides_count
; j
++) {
478 if (replacee
->provides
[j
] == abstract_replacee
)
487 * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
490 int pkg_conflicts_abstract(pkg_t
*pkg
, abstract_pkg_t
*conflictee
)
492 compound_depend_t
*conflicts
= pkg
->conflicts
;
493 int conflicts_count
= pkg
->conflicts_count
;
495 for (i
= 0; i
< conflicts_count
; i
++) {
496 int possibility_count
= conflicts
[i
].possibility_count
;
497 struct depend
**possibilities
= conflicts
[i
].possibilities
;
498 for (j
= 0; j
< possibility_count
; j
++) {
499 if (possibilities
[j
]->pkg
== conflictee
) {
508 * pkg_conflicts returns 1 if pkg->conflicts contains one of
509 * conflictee's provides and 0 otherwise.
511 int pkg_conflicts(pkg_t
*pkg
, pkg_t
*conflictee
)
513 compound_depend_t
*conflicts
= pkg
->conflicts
;
514 int conflicts_count
= pkg
->conflicts_count
;
515 abstract_pkg_t
**conflictee_provides
= conflictee
->provides
;
516 int conflictee_provides_count
= conflictee
->provides_count
;
518 int possibility_count
;
519 struct depend
**possibilities
;
520 abstract_pkg_t
*possibility
;
522 for (i
= 0; i
< conflicts_count
; i
++) {
523 possibility_count
= conflicts
[i
].possibility_count
;
524 possibilities
= conflicts
[i
].possibilities
;
525 for (j
= 0; j
< possibility_count
; j
++) {
526 possibility
= possibilities
[j
]->pkg
;
527 for (k
= 0; k
< conflictee_provides_count
; k
++) {
528 if (possibility
== conflictee_provides
[k
]) {
537 static char ** merge_unresolved(char ** oldstuff
, char ** newstuff
)
539 int oldlen
= 0, newlen
= 0;
546 while(oldstuff
&& oldstuff
[oldlen
]) oldlen
++;
547 while(newstuff
&& newstuff
[newlen
]) newlen
++;
549 result
= xrealloc(oldstuff
, sizeof(char *) * (oldlen
+ newlen
+ 1));
551 for(i
= oldlen
, j
= 0; i
< (oldlen
+ newlen
); i
++, j
++)
552 *(result
+ i
) = *(newstuff
+ j
);
554 *(result
+ i
) = NULL
;
560 * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
561 * this is null terminated, no count is carried around
563 char ** add_unresolved_dep(pkg_t
* pkg
, char ** the_lost
, int ref_ndx
)
569 while(the_lost
&& the_lost
[count
]) count
++;
571 count
++; /* need one to hold the null */
572 resized
= xrealloc(the_lost
, sizeof(char *) * (count
+ 1));
573 resized
[count
- 1] = pkg_depend_str(pkg
, ref_ndx
);
574 resized
[count
] = NULL
;
579 void buildProvides(abstract_pkg_t
* ab_pkg
, pkg_t
* pkg
)
583 /* every pkg provides itself */
584 pkg
->provides_count
++;
585 abstract_pkg_vec_insert(ab_pkg
->provided_by
, ab_pkg
);
586 pkg
->provides
= xcalloc(pkg
->provides_count
, sizeof(abstract_pkg_t
*));
587 pkg
->provides
[0] = ab_pkg
;
589 for (i
=1; i
<pkg
->provides_count
; i
++) {
590 abstract_pkg_t
*provided_abpkg
= ensure_abstract_pkg_by_name(
591 pkg
->provides_str
[i
-1]);
592 free(pkg
->provides_str
[i
-1]);
594 pkg
->provides
[i
] = provided_abpkg
;
596 abstract_pkg_vec_insert(provided_abpkg
->provided_by
, ab_pkg
);
598 if (pkg
->provides_str
)
599 free(pkg
->provides_str
);
602 void buildConflicts(pkg_t
* pkg
)
605 compound_depend_t
* conflicts
;
607 if (!pkg
->conflicts_count
)
610 conflicts
= pkg
->conflicts
= xcalloc(pkg
->conflicts_count
, sizeof(compound_depend_t
));
611 for (i
= 0; i
< pkg
->conflicts_count
; i
++) {
612 conflicts
->type
= CONFLICTS
;
613 parseDepends(conflicts
, pkg
->conflicts_str
[i
]);
614 free(pkg
->conflicts_str
[i
]);
617 if (pkg
->conflicts_str
)
618 free(pkg
->conflicts_str
);
621 void buildReplaces(abstract_pkg_t
* ab_pkg
, pkg_t
* pkg
)
625 if (!pkg
->replaces_count
)
628 pkg
->replaces
= xcalloc(pkg
->replaces_count
, sizeof(abstract_pkg_t
*));
630 for(i
= 0; i
< pkg
->replaces_count
; i
++){
631 abstract_pkg_t
*old_abpkg
= ensure_abstract_pkg_by_name(pkg
->replaces_str
[i
]);
633 pkg
->replaces
[i
] = old_abpkg
;
634 free(pkg
->replaces_str
[i
]);
636 if (!old_abpkg
->replaced_by
)
637 old_abpkg
->replaced_by
= abstract_pkg_vec_alloc();
638 /* if a package pkg both replaces and conflicts old_abpkg,
639 * then add it to the replaced_by vector so that old_abpkg
640 * will be upgraded to ab_pkg automatically */
641 if (pkg_conflicts_abstract(pkg
, old_abpkg
))
642 abstract_pkg_vec_insert(old_abpkg
->replaced_by
, ab_pkg
);
645 if (pkg
->replaces_str
)
646 free(pkg
->replaces_str
);
649 void buildDepends(pkg_t
* pkg
)
653 compound_depend_t
* depends
;
655 if(!(count
= pkg
->pre_depends_count
+ pkg
->depends_count
+ pkg
->recommends_count
+ pkg
->suggests_count
))
658 depends
= pkg
->depends
= xcalloc(count
, sizeof(compound_depend_t
));
660 for(i
= 0; i
< pkg
->pre_depends_count
; i
++){
661 parseDepends(depends
, pkg
->pre_depends_str
[i
]);
662 free(pkg
->pre_depends_str
[i
]);
663 depends
->type
= PREDEPEND
;
666 if (pkg
->pre_depends_str
)
667 free(pkg
->pre_depends_str
);
669 for(i
= 0; i
< pkg
->depends_count
; i
++){
670 parseDepends(depends
, pkg
->depends_str
[i
]);
671 free(pkg
->depends_str
[i
]);
674 if (pkg
->depends_str
)
675 free(pkg
->depends_str
);
677 for(i
= 0; i
< pkg
->recommends_count
; i
++){
678 parseDepends(depends
, pkg
->recommends_str
[i
]);
679 free(pkg
->recommends_str
[i
]);
680 depends
->type
= RECOMMEND
;
683 if(pkg
->recommends_str
)
684 free(pkg
->recommends_str
);
686 for(i
= 0; i
< pkg
->suggests_count
; i
++){
687 parseDepends(depends
, pkg
->suggests_str
[i
]);
688 free(pkg
->suggests_str
[i
]);
689 depends
->type
= SUGGEST
;
692 if(pkg
->suggests_str
)
693 free(pkg
->suggests_str
);
697 constraint_to_str(enum version_constraint c
)
718 * Returns a printable string for pkg's dependency at the specified idx. The
719 * resultant string must be passed to free() by the caller.
722 pkg_depend_str(pkg_t
*pkg
, int idx
)
727 compound_depend_t
*cdep
;
731 cdep
= &pkg
->depends
[idx
];
733 /* calculate string length */
734 for (i
=0; i
<cdep
->possibility_count
; i
++) {
735 dep
= cdep
->possibilities
[i
];
738 len
+= 3; /* space, pipe, space */
740 len
+= strlen(dep
->pkg
->name
);
743 len
+= 2; /* space, left parenthesis */
744 len
+= 3; /* constraint string (<=, >=, etc), space */
745 len
+= strlen(dep
->version
);
746 len
+= 1; /* right parenthesis */
750 str
= xmalloc(len
+ 1); /* +1 for the NULL terminator */
753 for (i
=0; i
<cdep
->possibility_count
; i
++) {
754 dep
= cdep
->possibilities
[i
];
757 strncat(str
, " | ", len
);
759 strncat(str
, dep
->pkg
->name
, len
);
762 strncat(str
, " (", len
);
763 strncat(str
, constraint_to_str(dep
->constraint
), len
);
764 strncat(str
, dep
->version
, len
);
765 strncat(str
, ")", len
);
772 void buildDependedUponBy(pkg_t
* pkg
, abstract_pkg_t
* ab_pkg
)
774 compound_depend_t
* depends
;
775 int count
, othercount
;
777 abstract_pkg_t
* ab_depend
;
778 abstract_pkg_t
** temp
;
780 count
= pkg
->pre_depends_count
+
782 pkg
->recommends_count
+
785 for (i
= 0; i
< count
; i
++) {
786 depends
= &pkg
->depends
[i
];
787 if (depends
->type
!= PREDEPEND
788 && depends
->type
!= DEPEND
789 && depends
->type
!= RECOMMEND
)
791 for (j
= 0; j
< depends
->possibility_count
; j
++) {
792 ab_depend
= depends
->possibilities
[j
]->pkg
;
793 if (!ab_depend
->depended_upon_by
) {
794 ab_depend
->depended_upon_by
=
795 xcalloc(1, sizeof(abstract_pkg_t
*));
798 temp
= ab_depend
->depended_upon_by
;
806 ab_depend
->depended_upon_by
=
807 xrealloc(ab_depend
->depended_upon_by
,
808 (othercount
+ 1) * sizeof(abstract_pkg_t
*));
810 /* the array may have been moved by realloc */
811 temp
= ab_depend
->depended_upon_by
+ othercount
;
817 static depend_t
* depend_init(void)
819 depend_t
* d
= xcalloc(1, sizeof(depend_t
));
820 d
->constraint
= NONE
;
827 static int parseDepends(compound_depend_t
*compound_depend
,
830 char * pkg_name
, buffer
[2048];
831 unsigned int num_of_ors
= 0;
834 depend_t
** possibilities
;
836 /* first count the number of ored possibilities for satisfying dependency */
842 compound_depend
->type
= DEPEND
;
844 compound_depend
->possibility_count
= num_of_ors
+ 1;
845 possibilities
= xcalloc((num_of_ors
+ 1), sizeof(depend_t
*) );
846 compound_depend
->possibilities
= possibilities
;
849 for(i
= 0; i
< num_of_ors
+ 1; i
++){
850 possibilities
[i
] = depend_init();
851 /* gobble up just the name first */
860 pkg_name
= trim_xstrdup(buffer
);
862 /* now look at possible version info */
864 /* skip to next chars */
866 while(*src
&& isspace(*src
)) src
++;
868 /* extract constraint and version */
871 if(!strncmp(src
, "<<", 2)){
872 possibilities
[i
]->constraint
= EARLIER
;
875 else if(!strncmp(src
, "<=", 2)){
876 possibilities
[i
]->constraint
= EARLIER_EQUAL
;
879 else if(!strncmp(src
, ">=", 2)){
880 possibilities
[i
]->constraint
= LATER_EQUAL
;
883 else if(!strncmp(src
, ">>", 2)){
884 possibilities
[i
]->constraint
= LATER
;
887 else if(!strncmp(src
, "=", 1)){
888 possibilities
[i
]->constraint
= EQUAL
;
891 /* should these be here to support deprecated designations; dpkg does */
892 else if(!strncmp(src
, "<", 1)){
893 possibilities
[i
]->constraint
= EARLIER_EQUAL
;
896 else if(!strncmp(src
, ">", 1)){
897 possibilities
[i
]->constraint
= LATER_EQUAL
;
901 /* now we have any constraint, pass space to version string */
902 while(isspace(*src
)) src
++;
904 /* this would be the version string */
906 while(*src
&& *src
!= ')')
910 possibilities
[i
]->version
= trim_xstrdup(buffer
);
912 /* hook up the dependency to its abstract pkg */
913 possibilities
[i
]->pkg
= ensure_abstract_pkg_by_name(pkg_name
);
917 /* now get past the ) and any possible | chars */
925 compound_depend
->type
= GREEDY_DEPEND
;