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 char ** add_unresolved_dep(pkg_t
* pkg
, char ** the_lost
, int ref_ndx
);
33 static char ** merge_unresolved(char ** oldstuff
, char ** newstuff
);
34 static int is_pkg_in_pkg_vec(pkg_vec_t
* vec
, pkg_t
* pkg
);
36 static int pkg_installed_and_constraint_satisfied(pkg_t
*pkg
, void *cdata
)
38 depend_t
*depend
= (depend_t
*)cdata
;
39 if ((pkg
->state_status
== SS_INSTALLED
|| pkg
->state_status
== SS_UNPACKED
) && version_constraints_satisfied(depend
, pkg
))
45 static int pkg_constraint_satisfied(pkg_t
*pkg
, void *cdata
)
47 depend_t
*depend
= (depend_t
*)cdata
;
48 if (version_constraints_satisfied(depend
, pkg
))
54 /* returns ndependences or negative error value */
55 int pkg_hash_fetch_unsatisfied_dependencies(opkg_conf_t
*conf
, pkg_t
* pkg
,
56 pkg_vec_t
*unsatisfied
, char *** unresolved
)
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 fprintf(stderr
, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__
, __LINE__
, 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(conf
,
127 if (newstuff
== NULL
) {
130 for (m
= 0; m
< rc
; m
++) {
131 pkg_t
*p
= tmp_vec
->pkgs
[m
];
132 if (p
->state_want
== SW_INSTALL
)
134 opkg_message(conf
, OPKG_DEBUG
, "not installing %s due to requirement for %s\n", pkg_scout
->name
, p
->name
);
138 pkg_vec_free (tmp_vec
);
140 /* mark this one for installation */
141 opkg_message(conf
, OPKG_NOTICE
, "Adding satisfier for greedy dependence: %s\n", pkg_scout
->name
);
142 pkg_vec_insert(unsatisfied
, pkg_scout
);
145 opkg_message(conf
, OPKG_DEBUG
, "not installing %s due to broken depends \n", pkg_scout
->name
);
156 /* foreach possible satisfier, look for installed package */
157 for (j
= 0; j
< compound_depend
->possibility_count
; j
++) {
158 /* foreach provided_by, which includes the abstract_pkg itself */
159 depend_t
*dependence_to_satisfy
= possible_satisfiers
[j
];
160 abstract_pkg_t
*satisfying_apkg
= possible_satisfiers
[j
]->pkg
;
161 pkg_t
*satisfying_pkg
=
162 pkg_hash_fetch_best_installation_candidate(conf
, satisfying_apkg
,
163 pkg_installed_and_constraint_satisfied
,
164 dependence_to_satisfy
, 1);
165 /* Being that I can't test constraing in pkg_hash, I will test it here */
166 if (satisfying_pkg
!= NULL
) {
167 if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg
,dependence_to_satisfy
)) {
168 satisfying_pkg
= NULL
;
171 opkg_message(conf
, OPKG_DEBUG
, "%s:%d: satisfying_pkg=%p \n", __FILE__
, __LINE__
, satisfying_pkg
);
172 if (satisfying_pkg
!= NULL
) {
178 /* if nothing installed matches, then look for uninstalled satisfier */
180 /* foreach possible satisfier, look for installed package */
181 for (j
= 0; j
< compound_depend
->possibility_count
; j
++) {
182 /* foreach provided_by, which includes the abstract_pkg itself */
183 depend_t
*dependence_to_satisfy
= possible_satisfiers
[j
];
184 abstract_pkg_t
*satisfying_apkg
= possible_satisfiers
[j
]->pkg
;
185 pkg_t
*satisfying_pkg
=
186 pkg_hash_fetch_best_installation_candidate(conf
, satisfying_apkg
,
187 pkg_constraint_satisfied
,
188 dependence_to_satisfy
, 1);
189 /* Being that I can't test constraing in pkg_hash, I will test it here too */
190 if (satisfying_pkg
!= NULL
) {
191 if (!pkg_constraint_satisfied ( satisfying_pkg
,dependence_to_satisfy
)) {
192 satisfying_pkg
= NULL
;
196 /* user request overrides package recommendation */
197 if (satisfying_pkg
!= NULL
198 && (compound_depend
->type
== RECOMMEND
|| compound_depend
->type
== SUGGEST
)
199 && (satisfying_pkg
->state_want
== SW_DEINSTALL
|| satisfying_pkg
->state_want
== SW_PURGE
)) {
200 opkg_message (conf
, OPKG_NOTICE
, "%s: ignoring recommendation for %s at user request\n",
201 pkg
->name
, satisfying_pkg
->name
);
205 opkg_message(conf
, OPKG_DEBUG
, "%s:%d: satisfying_pkg=%p\n", __FILE__
, __LINE__
, satisfying_pkg
);
206 if (satisfying_pkg
!= NULL
) {
207 satisfier_entry_pkg
= satisfying_pkg
;
213 /* we didn't find one, add something to the unsatisfied vector */
215 if (!satisfier_entry_pkg
) {
216 /* failure to meet recommendations is not an error */
217 if (compound_depend
->type
!= RECOMMEND
&& compound_depend
->type
!= SUGGEST
)
218 the_lost
= add_unresolved_dep(pkg
, the_lost
, i
);
220 opkg_message (conf
, OPKG_NOTICE
, "%s: unsatisfied recommendation for %s\n",
221 pkg
->name
, compound_depend
->possibilities
[0]->pkg
->name
);
224 if (compound_depend
->type
== SUGGEST
) {
225 /* just mention it politely */
226 opkg_message (conf
, OPKG_NOTICE
, "package %s suggests installing %s\n",
227 pkg
->name
, satisfier_entry_pkg
->name
);
229 char ** newstuff
= NULL
;
231 if (satisfier_entry_pkg
!= pkg
&&
232 !is_pkg_in_pkg_vec(unsatisfied
, satisfier_entry_pkg
)) {
233 pkg_vec_insert(unsatisfied
, satisfier_entry_pkg
);
234 pkg_hash_fetch_unsatisfied_dependencies(conf
,
238 the_lost
= merge_unresolved(the_lost
, newstuff
);
246 *unresolved
= the_lost
;
248 return unsatisfied
->len
;
251 /*checking for conflicts !in replaces
252 If a packages conflicts with another but is also replacing it, I should not consider it a
254 returns 0 if conflicts <> replaces or 1 if conflicts == replaces
256 int is_pkg_a_replaces(pkg_t
*pkg_scout
,pkg_t
*pkg
)
259 int replaces_count
= pkg
->replaces_count
;
260 abstract_pkg_t
**replaces
;
262 if (pkg
->replaces_count
==0) // No replaces, it's surely a conflict
265 replaces
= pkg
->replaces
;
267 for (i
= 0; i
< replaces_count
; i
++) {
268 if (strcmp(pkg_scout
->name
,pkg
->replaces
[i
]->name
)==0) { // Found
269 opkg_message(NULL
, OPKG_DEBUG2
, "Seems I've found a replace %s %s \n",pkg_scout
->name
,pkg
->replaces
[i
]->name
);
278 /* Abhaya: added support for conflicts */
279 pkg_vec_t
* pkg_hash_fetch_conflicts(hash_table_t
* hash
, pkg_t
* pkg
)
281 pkg_vec_t
* installed_conflicts
, * test_vec
;
282 compound_depend_t
* conflicts
;
283 depend_t
** possible_satisfiers
;
284 depend_t
* possible_satisfier
;
287 abstract_pkg_t
* ab_pkg
;
292 * this is a setup to check for redundant/cyclic dependency checks,
293 * which are marked at the abstract_pkg level
295 if(!(ab_pkg
= pkg
->parent
)){
296 fprintf(stderr
, "dependency check error. pkg %s isn't in hash table\n", pkg
->name
);
297 return (pkg_vec_t
*)NULL
;
300 conflicts
= pkg
->conflicts
;
302 return (pkg_vec_t
*)NULL
;
304 installed_conflicts
= pkg_vec_alloc();
306 count
= pkg
->conflicts_count
;
310 /* foreach conflict */
311 for(i
= 0; i
< pkg
->conflicts_count
; i
++){
313 possible_satisfiers
= conflicts
->possibilities
;
315 /* foreach possible satisfier */
316 for(j
= 0; j
< conflicts
->possibility_count
; j
++){
317 possible_satisfier
= possible_satisfiers
[j
];
318 if (!possible_satisfier
)
319 fprintf(stderr
, "%s:%d: possible_satisfier is null\n", __FUNCTION__
, __LINE__
);
320 if (!possible_satisfier
->pkg
)
321 fprintf(stderr
, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__
, __LINE__
);
322 test_vec
= possible_satisfier
->pkg
->pkgs
;
324 /* pkg_vec found, it is an actual package conflict
325 * cruise this possiblity's pkg_vec looking for an installed version */
326 pkg_scouts
= test_vec
->pkgs
;
327 for(k
= 0; k
< test_vec
->len
; k
++){
328 pkg_scout
= pkg_scouts
[k
];
330 fprintf(stderr
, "%s: null pkg scout\n", __FUNCTION__
);
333 if ((pkg_scout
->state_status
== SS_INSTALLED
|| pkg_scout
->state_want
== SW_INSTALL
) &&
334 version_constraints_satisfied(possible_satisfier
, pkg_scout
) && !is_pkg_a_replaces(pkg_scout
,pkg
)){
335 if (!is_pkg_in_pkg_vec(installed_conflicts
, pkg_scout
)){
336 pkg_vec_insert(installed_conflicts
, pkg_scout
);
345 if (installed_conflicts
->len
)
346 return installed_conflicts
;
347 pkg_vec_free(installed_conflicts
);
348 return (pkg_vec_t
*)NULL
;
351 int version_constraints_satisfied(depend_t
* depends
, pkg_t
* pkg
)
356 if(depends
->constraint
== NONE
)
361 parse_version(temp
, depends
->version
);
363 comparison
= pkg_compare_versions(pkg
, temp
);
365 free (temp
->version
);
368 if((depends
->constraint
== EARLIER
) &&
371 else if((depends
->constraint
== LATER
) &&
374 else if(comparison
== 0)
376 else if((depends
->constraint
== LATER_EQUAL
) &&
379 else if((depends
->constraint
== EARLIER_EQUAL
) &&
386 int pkg_dependence_satisfiable(opkg_conf_t
*conf
, depend_t
*depend
)
388 abstract_pkg_t
*apkg
= depend
->pkg
;
389 abstract_pkg_vec_t
*provider_apkgs
= apkg
->provided_by
;
390 int n_providers
= provider_apkgs
->len
;
391 abstract_pkg_t
**apkgs
= provider_apkgs
->pkgs
;
397 for (i
= 0; i
< n_providers
; i
++) {
398 abstract_pkg_t
*papkg
= apkgs
[i
];
399 pkg_vec
= papkg
->pkgs
;
401 n_pkgs
= pkg_vec
->len
;
402 for (j
= 0; j
< n_pkgs
; j
++) {
403 pkg_t
*pkg
= pkg_vec
->pkgs
[j
];
404 if (version_constraints_satisfied(depend
, pkg
)) {
413 int pkg_dependence_satisfied(opkg_conf_t
*conf
, depend_t
*depend
)
415 abstract_pkg_t
*apkg
= depend
->pkg
;
416 abstract_pkg_vec_t
*provider_apkgs
= apkg
->provided_by
;
417 int n_providers
= provider_apkgs
->len
;
418 abstract_pkg_t
**apkgs
= provider_apkgs
->pkgs
;
423 for (i
= 0; i
< n_providers
; i
++) {
424 abstract_pkg_t
*papkg
= apkgs
[i
];
425 pkg_vec_t
*pkg_vec
= papkg
->pkgs
;
427 n_pkgs
= pkg_vec
->len
;
428 for (j
= 0; j
< n_pkgs
; j
++) {
429 pkg_t
*pkg
= pkg_vec
->pkgs
[j
];
430 if (version_constraints_satisfied(depend
, pkg
)) {
431 if (pkg
->state_status
== SS_INSTALLED
|| pkg
->state_status
== SS_UNPACKED
)
440 static int is_pkg_in_pkg_vec(pkg_vec_t
* vec
, pkg_t
* pkg
)
443 pkg_t
** pkgs
= vec
->pkgs
;
445 for(i
= 0; i
< vec
->len
; i
++)
446 if((strcmp(pkg
->name
, (*(pkgs
+ i
))->name
) == 0)
447 && (pkg_compare_versions(pkg
, *(pkgs
+ i
)) == 0)
448 && (strcmp(pkg
->architecture
, (*(pkgs
+ i
))->architecture
) == 0))
454 * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
457 int pkg_replaces(pkg_t
*pkg
, pkg_t
*replacee
)
459 abstract_pkg_t
**replaces
= pkg
->replaces
;
460 int replaces_count
= pkg
->replaces_count
;
461 int replacee_provides_count
= replacee
->provides_count
;
463 for (i
= 0; i
< replaces_count
; i
++) {
464 abstract_pkg_t
*abstract_replacee
= replaces
[i
];
465 for (j
= 0; j
< replacee_provides_count
; j
++) {
466 if (replacee
->provides
[j
] == abstract_replacee
)
475 * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
478 int pkg_conflicts_abstract(pkg_t
*pkg
, abstract_pkg_t
*conflictee
)
480 compound_depend_t
*conflicts
= pkg
->conflicts
;
481 int conflicts_count
= pkg
->conflicts_count
;
483 for (i
= 0; i
< conflicts_count
; i
++) {
484 int possibility_count
= conflicts
[i
].possibility_count
;
485 struct depend
**possibilities
= conflicts
[i
].possibilities
;
486 for (j
= 0; j
< possibility_count
; j
++) {
487 if (possibilities
[j
]->pkg
== conflictee
) {
496 * pkg_conflicts returns 1 if pkg->conflicts contains one of
497 * conflictee's provides and 0 otherwise.
499 int pkg_conflicts(pkg_t
*pkg
, pkg_t
*conflictee
)
501 compound_depend_t
*conflicts
= pkg
->conflicts
;
502 int conflicts_count
= pkg
->conflicts_count
;
503 abstract_pkg_t
**conflictee_provides
= conflictee
->provides
;
504 int conflictee_provides_count
= conflictee
->provides_count
;
506 int possibility_count
;
507 struct depend
**possibilities
;
508 abstract_pkg_t
*possibility
;
510 for (i
= 0; i
< conflicts_count
; i
++) {
511 possibility_count
= conflicts
[i
].possibility_count
;
512 possibilities
= conflicts
[i
].possibilities
;
513 for (j
= 0; j
< possibility_count
; j
++) {
514 possibility
= possibilities
[j
]->pkg
;
515 for (k
= 0; k
< conflictee_provides_count
; k
++) {
516 if (possibility
== conflictee_provides
[k
]) {
525 static char ** merge_unresolved(char ** oldstuff
, char ** newstuff
)
527 int oldlen
= 0, newlen
= 0;
534 while(oldstuff
&& oldstuff
[oldlen
]) oldlen
++;
535 while(newstuff
&& newstuff
[newlen
]) newlen
++;
537 result
= xrealloc(oldstuff
, sizeof(char *) * (oldlen
+ newlen
+ 1));
539 for(i
= oldlen
, j
= 0; i
< (oldlen
+ newlen
); i
++, j
++)
540 *(result
+ i
) = *(newstuff
+ j
);
542 *(result
+ i
) = NULL
;
548 * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
549 * this is null terminated, no count is carried around
551 char ** add_unresolved_dep(pkg_t
* pkg
, char ** the_lost
, int ref_ndx
)
557 while(the_lost
&& the_lost
[count
]) count
++;
559 count
++; /* need one to hold the null */
560 resized
= xrealloc(the_lost
, sizeof(char *) * (count
+ 1));
561 resized
[count
- 1] = pkg_depend_str(pkg
, ref_ndx
);
562 resized
[count
] = NULL
;
567 void buildProvides(hash_table_t
* hash
, abstract_pkg_t
* ab_pkg
, pkg_t
* pkg
)
571 /* every pkg provides itself */
572 pkg
->provides_count
++;
573 abstract_pkg_vec_insert(ab_pkg
->provided_by
, ab_pkg
);
574 pkg
->provides
= xcalloc(pkg
->provides_count
, sizeof(abstract_pkg_t
*));
575 pkg
->provides
[0] = ab_pkg
;
577 for (i
=1; i
<pkg
->provides_count
; i
++) {
578 abstract_pkg_t
*provided_abpkg
= ensure_abstract_pkg_by_name(hash
,
579 pkg
->provides_str
[i
-1]);
580 free(pkg
->provides_str
[i
-1]);
582 pkg
->provides
[i
] = provided_abpkg
;
584 abstract_pkg_vec_insert(provided_abpkg
->provided_by
, ab_pkg
);
586 if (pkg
->provides_str
)
587 free(pkg
->provides_str
);
590 /* Abhaya: added conflicts support */
591 void buildConflicts(hash_table_t
* hash
, abstract_pkg_t
* ab_pkg
, pkg_t
* pkg
)
594 compound_depend_t
* conflicts
;
596 if (!pkg
->conflicts_count
)
599 conflicts
= pkg
->conflicts
= xcalloc(pkg
->conflicts_count
, sizeof(compound_depend_t
));
600 for (i
= 0; i
< pkg
->conflicts_count
; i
++) {
601 conflicts
->type
= CONFLICTS
;
602 parseDepends(conflicts
, hash
,
603 pkg
->conflicts_str
[i
]);
604 free(pkg
->conflicts_str
[i
]);
607 if (pkg
->conflicts_str
)
608 free(pkg
->conflicts_str
);
611 void buildReplaces(hash_table_t
* hash
, abstract_pkg_t
* ab_pkg
, pkg_t
* pkg
)
615 if (!pkg
->replaces_count
)
618 pkg
->replaces
= xcalloc(pkg
->replaces_count
, sizeof(abstract_pkg_t
*));
620 for(i
= 0; i
< pkg
->replaces_count
; i
++){
621 abstract_pkg_t
*old_abpkg
= ensure_abstract_pkg_by_name(hash
, pkg
->replaces_str
[i
]);
623 pkg
->replaces
[i
] = old_abpkg
;
624 free(pkg
->replaces_str
[i
]);
626 if (!old_abpkg
->replaced_by
)
627 old_abpkg
->replaced_by
= abstract_pkg_vec_alloc();
628 /* if a package pkg both replaces and conflicts old_abpkg,
629 * then add it to the replaced_by vector so that old_abpkg
630 * will be upgraded to ab_pkg automatically */
631 if (pkg_conflicts_abstract(pkg
, old_abpkg
))
632 abstract_pkg_vec_insert(old_abpkg
->replaced_by
, ab_pkg
);
635 if (pkg
->replaces_str
)
636 free(pkg
->replaces_str
);
639 void buildDepends(hash_table_t
* hash
, pkg_t
* pkg
)
643 compound_depend_t
* depends
;
645 if(!(count
= pkg
->pre_depends_count
+ pkg
->depends_count
+ pkg
->recommends_count
+ pkg
->suggests_count
))
648 depends
= pkg
->depends
= xcalloc(count
, sizeof(compound_depend_t
));
650 for(i
= 0; i
< pkg
->pre_depends_count
; i
++){
651 parseDepends(depends
, hash
, pkg
->pre_depends_str
[i
]);
652 free(pkg
->pre_depends_str
[i
]);
653 depends
->type
= PREDEPEND
;
656 if (pkg
->pre_depends_str
)
657 free(pkg
->pre_depends_str
);
659 for(i
= 0; i
< pkg
->depends_count
; i
++){
660 parseDepends(depends
, hash
, pkg
->depends_str
[i
]);
661 free(pkg
->depends_str
[i
]);
664 if (pkg
->depends_str
)
665 free(pkg
->depends_str
);
667 for(i
= 0; i
< pkg
->recommends_count
; i
++){
668 parseDepends(depends
, hash
, pkg
->recommends_str
[i
]);
669 free(pkg
->recommends_str
[i
]);
670 depends
->type
= RECOMMEND
;
673 if(pkg
->recommends_str
)
674 free(pkg
->recommends_str
);
676 for(i
= 0; i
< pkg
->suggests_count
; i
++){
677 parseDepends(depends
, hash
, pkg
->suggests_str
[i
]);
678 free(pkg
->suggests_str
[i
]);
679 depends
->type
= SUGGEST
;
682 if(pkg
->suggests_str
)
683 free(pkg
->suggests_str
);
687 constraint_to_str(enum version_constraint c
)
708 * Returns a printable string for pkg's dependency at the specified index. The
709 * resultant string must be passed to free() by the caller.
712 pkg_depend_str(pkg_t
*pkg
, int index
)
716 compound_depend_t
*cdep
;
720 cdep
= &pkg
->depends
[index
];
722 /* calculate string length */
723 for (i
=0; i
<cdep
->possibility_count
; i
++) {
724 dep
= cdep
->possibilities
[i
];
727 len
+= 3; /* space, pipe, space */
729 len
+= strlen(dep
->pkg
->name
);
732 len
+= 2; /* space, left parenthesis */
733 len
+= 3; /* constraint string (<=, >=, etc), space */
734 len
+= strlen(dep
->version
);
735 len
+= 1; /* right parenthesis */
739 str
= xmalloc(len
+ 1); /* +1 for the NULL terminator */
742 for (i
=0; i
<cdep
->possibility_count
; i
++) {
743 dep
= cdep
->possibilities
[i
];
746 strncat(str
, " | ", len
);
748 strncat(str
, dep
->pkg
->name
, len
);
751 strncat(str
, " (", len
);
752 strncat(str
, constraint_to_str(dep
->constraint
), len
);
753 strncat(str
, dep
->version
, len
);
754 strncat(str
, ")", len
);
762 * WARNING: This function assumes pre_depends and depends are at the
763 * start of the pkg->depends array.
765 void buildDependedUponBy(pkg_t
* pkg
, abstract_pkg_t
* ab_pkg
)
767 compound_depend_t
* depends
;
768 int count
, othercount
;
770 abstract_pkg_t
* ab_depend
;
771 abstract_pkg_t
** temp
;
773 count
= pkg
->pre_depends_count
+ pkg
->depends_count
;
774 depends
= pkg
->depends
;
776 for (i
= 0; i
< count
; i
++) {
777 for (j
= 0; j
< depends
->possibility_count
; j
++){
778 ab_depend
= depends
->possibilities
[j
]->pkg
;
779 if(!ab_depend
->depended_upon_by
)
780 ab_depend
->depended_upon_by
= xcalloc(1, sizeof(abstract_pkg_t
*));
782 temp
= ab_depend
->depended_upon_by
;
790 ab_depend
->depended_upon_by
= xrealloc(ab_depend
->depended_upon_by
,
791 (othercount
+ 1) * sizeof(abstract_pkg_t
*));
792 /* the array may have moved */
793 temp
= ab_depend
->depended_upon_by
+ othercount
;
800 static depend_t
* depend_init(void)
802 depend_t
* d
= xcalloc(1, sizeof(depend_t
));
803 d
->constraint
= NONE
;
810 static int parseDepends(compound_depend_t
*compound_depend
,
811 hash_table_t
* hash
, char * depend_str
)
813 char * pkg_name
, buffer
[2048];
817 depend_t
** possibilities
;
819 /* first count the number of ored possibilities for satisfying dependency */
825 compound_depend
->type
= DEPEND
;
827 compound_depend
->possibility_count
= num_of_ors
+ 1;
828 possibilities
= xcalloc((num_of_ors
+ 1), sizeof(depend_t
*) );
829 compound_depend
->possibilities
= possibilities
;
832 for(i
= 0; i
< num_of_ors
+ 1; i
++){
833 possibilities
[i
] = depend_init();
834 /* gobble up just the name first */
843 pkg_name
= trim_xstrdup(buffer
);
844 if (pkg_name
== NULL
)
847 /* now look at possible version info */
849 /* skip to next chars */
851 while(*src
&& isspace(*src
)) src
++;
853 /* extract constraint and version */
856 if(!strncmp(src
, "<<", 2)){
857 possibilities
[i
]->constraint
= EARLIER
;
860 else if(!strncmp(src
, "<=", 2)){
861 possibilities
[i
]->constraint
= EARLIER_EQUAL
;
864 else if(!strncmp(src
, ">=", 2)){
865 possibilities
[i
]->constraint
= LATER_EQUAL
;
868 else if(!strncmp(src
, ">>", 2)){
869 possibilities
[i
]->constraint
= LATER
;
872 else if(!strncmp(src
, "=", 1)){
873 possibilities
[i
]->constraint
= EQUAL
;
876 /* should these be here to support deprecated designations; dpkg does */
877 else if(!strncmp(src
, "<", 1)){
878 possibilities
[i
]->constraint
= EARLIER_EQUAL
;
881 else if(!strncmp(src
, ">", 1)){
882 possibilities
[i
]->constraint
= LATER_EQUAL
;
886 /* now we have any constraint, pass space to version string */
887 while(isspace(*src
)) src
++;
889 /* this would be the version string */
891 while(*src
&& *src
!= ')')
895 possibilities
[i
]->version
= trim_xstrdup(buffer
);
896 /* fprintf(stderr, "let's print the depends version string:");
897 fprintf(stderr, "version %s\n", possibilities[i]->version);*/
898 if (possibilities
[i
]->version
== NULL
)
903 /* hook up the dependency to its abstract pkg */
904 possibilities
[i
]->pkg
= ensure_abstract_pkg_by_name(hash
, pkg_name
);
908 /* now get past the ) and any possible | chars */
916 compound_depend
->type
= GREEDY_DEPEND
;