2 * Copyright (c) 2007-2009, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
11 * Transaction handling
20 #include "transaction.h"
28 obsq_sortcmp(const void *ap, const void *bp, void *dp)
32 Solvable *s, *oas, *obs;
43 s = pool->solvables + a;
44 oas = pool->solvables + oa;
45 obs = pool->solvables + ob;
46 if (oas->name != obs->name)
48 if (oas->name == s->name)
50 if (obs->name == s->name)
52 return strcmp(id2str(pool, oas->name), id2str(pool, obs->name));
54 r = evrcmp(pool, oas->evr, obs->evr, EVRCMP_COMPARE);
56 return -r; /* highest version first */
61 transaction_all_obs_pkgs(Transaction *trans, Id p, Queue *pkgs)
63 Pool *pool = trans->pool;
64 Solvable *s = pool->solvables + p;
65 Queue *ti = &trans->transaction_info;
70 if (p <= 0 || !s->repo)
72 if (s->repo == pool->installed)
74 q = trans->transaction_installed[p - pool->installed->start];
82 /* find which packages obsolete us */
83 for (i = 0; i < ti->count; i += 2)
84 if (ti->elements[i + 1] == p)
87 queue_push(pkgs, ti->elements[i]);
91 sat_sort(pkgs->elements, pkgs->count / 2, 2 * sizeof(Id), obsq_sortcmp, pool);
92 for (i = 0; i < pkgs->count; i += 2)
93 pkgs->elements[i / 2] = pkgs->elements[i + 1];
98 /* find the packages we obsolete */
99 for (i = 0; i < ti->count; i += 2)
101 if (ti->elements[i] == p)
102 queue_push(pkgs, ti->elements[i + 1]);
103 else if (pkgs->count)
110 transaction_obs_pkg(Transaction *trans, Id p)
112 Pool *pool = trans->pool;
113 Solvable *s = pool->solvables + p;
117 if (p <= 0 || !s->repo)
119 if (s->repo == pool->installed)
121 p = trans->transaction_installed[p - pool->installed->start];
122 return p < 0 ? -p : p;
124 queue_init_buffer(&ti, tibuf, sizeof(tibuf)/sizeof(*tibuf));
125 transaction_all_obs_pkgs(trans, p, &ti);
126 p = ti.count ? ti.elements[0] : 0;
133 * calculate base type of transaction element
137 transaction_base_type(Transaction *trans, Id p)
139 Pool *pool = trans->pool;
144 if (!MAPTST(&trans->transactsmap, p))
145 return SOLVER_TRANSACTION_IGNORE;
146 p2 = transaction_obs_pkg(trans, p);
147 if (pool->installed && pool->solvables[p].repo == pool->installed)
151 return SOLVER_TRANSACTION_ERASE;
152 s = pool->solvables + p;
153 s2 = pool->solvables + p2;
154 if (s->name == s2->name)
156 if (s->evr == s2->evr && solvable_identical(s, s2))
157 return SOLVER_TRANSACTION_REINSTALLED;
158 r = evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
160 return SOLVER_TRANSACTION_UPGRADED;
162 return SOLVER_TRANSACTION_DOWNGRADED;
163 return SOLVER_TRANSACTION_CHANGED;
165 return SOLVER_TRANSACTION_OBSOLETED;
169 int noobs = trans->noobsmap.size && MAPTST(&trans->noobsmap, p);
171 return p2 ? SOLVER_TRANSACTION_MULTIREINSTALL : SOLVER_TRANSACTION_MULTIINSTALL;
173 return SOLVER_TRANSACTION_INSTALL;
174 s = pool->solvables + p;
175 s2 = pool->solvables + p2;
176 if (s->name == s2->name)
178 if (s->evr == s2->evr && solvable_identical(s, s2))
179 return SOLVER_TRANSACTION_REINSTALL;
180 r = evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
182 return SOLVER_TRANSACTION_UPGRADE;
184 return SOLVER_TRANSACTION_DOWNGRADE;
186 return SOLVER_TRANSACTION_CHANGE;
188 return SOLVER_TRANSACTION_OBSOLETES;
193 * return type of transaction element
195 * filtering is needed if either not all packages are shown
196 * or replaces are not shown, as otherwise parts of the
197 * transaction might not be shown to the user */
200 transaction_type(Transaction *trans, Id p, int mode)
202 Pool *pool = trans->pool;
203 Solvable *s = pool->solvables + p;
209 return SOLVER_TRANSACTION_IGNORE;
211 type = transaction_base_type(trans, p);
213 if (type == SOLVER_TRANSACTION_IGNORE)
214 return SOLVER_TRANSACTION_IGNORE; /* not part of the transaction */
216 if ((mode & SOLVER_TRANSACTION_RPM_ONLY) != 0)
218 /* application wants to know what to feed to rpm */
219 if (type == SOLVER_TRANSACTION_ERASE || type == SOLVER_TRANSACTION_INSTALL || type == SOLVER_TRANSACTION_MULTIINSTALL)
221 if (s->repo == pool->installed)
222 return SOLVER_TRANSACTION_IGNORE; /* ignore as we're being obsoleted */
223 if (type == SOLVER_TRANSACTION_MULTIREINSTALL)
224 return SOLVER_TRANSACTION_MULTIINSTALL;
225 return SOLVER_TRANSACTION_INSTALL;
228 if ((mode & SOLVER_TRANSACTION_SHOW_MULTIINSTALL) == 0)
230 /* application wants to make no difference between install
231 * and multiinstall */
232 if (type == SOLVER_TRANSACTION_MULTIINSTALL)
233 type = SOLVER_TRANSACTION_INSTALL;
234 if (type == SOLVER_TRANSACTION_MULTIREINSTALL)
235 type = SOLVER_TRANSACTION_REINSTALL;
238 if ((mode & SOLVER_TRANSACTION_CHANGE_IS_REINSTALL))
240 /* application wants to make no difference between change
242 if (type == SOLVER_TRANSACTION_CHANGED)
243 type = SOLVER_TRANSACTION_REINSTALLED;
244 else if (type == SOLVER_TRANSACTION_CHANGE)
245 type = SOLVER_TRANSACTION_REINSTALL;
248 if (type == SOLVER_TRANSACTION_ERASE || type == SOLVER_TRANSACTION_INSTALL || type == SOLVER_TRANSACTION_MULTIINSTALL)
251 if (s->repo == pool->installed && (mode & SOLVER_TRANSACTION_SHOW_ACTIVE) == 0)
253 /* erase element and we're showing the passive side */
254 if ((mode & SOLVER_TRANSACTION_SHOW_OBSOLETES) == 0 && type == SOLVER_TRANSACTION_OBSOLETED)
255 type = SOLVER_TRANSACTION_ERASE;
258 if (s->repo != pool->installed && (mode & SOLVER_TRANSACTION_SHOW_ACTIVE) != 0)
260 /* install element and we're showing the active side */
261 if ((mode & SOLVER_TRANSACTION_SHOW_OBSOLETES) == 0 && type == SOLVER_TRANSACTION_OBSOLETES)
262 type = SOLVER_TRANSACTION_INSTALL;
266 /* the element doesn't match the show mode */
268 /* if we're showing all references, we can ignore this package */
269 if ((mode & (SOLVER_TRANSACTION_SHOW_ALL|SOLVER_TRANSACTION_SHOW_OBSOLETES)) == (SOLVER_TRANSACTION_SHOW_ALL|SOLVER_TRANSACTION_SHOW_OBSOLETES))
270 return SOLVER_TRANSACTION_IGNORE;
272 /* we're not showing all refs. check if some other package
273 * references us. If yes, it's safe to ignore this package,
274 * otherwise we need to map the type */
276 /* most of the time there's only one reference, so check it first */
277 q = transaction_obs_pkg(trans, p);
279 if ((mode & SOLVER_TRANSACTION_SHOW_OBSOLETES) == 0)
281 Solvable *sq = pool->solvables + q;
282 if (sq->name != s->name)
284 /* it's a replace but we're not showing replaces. map type. */
285 if (s->repo == pool->installed)
286 return SOLVER_TRANSACTION_ERASE;
287 else if (type == SOLVER_TRANSACTION_MULTIREINSTALL)
288 return SOLVER_TRANSACTION_MULTIINSTALL;
290 return SOLVER_TRANSACTION_INSTALL;
294 /* if there's a match, p will be shown when q
296 if (transaction_obs_pkg(trans, q) == p)
297 return SOLVER_TRANSACTION_IGNORE;
299 /* too bad, a miss. check em all */
302 transaction_all_obs_pkgs(trans, p, &oq);
303 for (i = 0; i < oq.count; i++)
306 if ((mode & SOLVER_TRANSACTION_SHOW_OBSOLETES) == 0)
308 Solvable *sq = pool->solvables + q;
309 if (sq->name != s->name)
312 /* check if we are referenced? */
313 if ((mode & SOLVER_TRANSACTION_SHOW_ALL) != 0)
315 transaction_all_obs_pkgs(trans, q, &rq);
316 for (j = 0; j < rq.count; j++)
317 if (rq.elements[j] == p)
325 else if (transaction_obs_pkg(trans, q) == p)
336 /* we're not referenced. map type */
337 if (s->repo == pool->installed)
338 return SOLVER_TRANSACTION_ERASE;
339 else if (type == SOLVER_TRANSACTION_MULTIREINSTALL)
340 return SOLVER_TRANSACTION_MULTIINSTALL;
342 return SOLVER_TRANSACTION_INSTALL;
344 /* there was a ref, so p is shown with some other package */
345 return SOLVER_TRANSACTION_IGNORE;
351 classify_cmp(const void *ap, const void *bp, void *dp)
353 Transaction *trans = dp;
354 Pool *pool = trans->pool;
364 return a[2] && b[2] ? strcmp(id2str(pool, a[2]), id2str(pool, b[2])) : r;
367 return a[3] && b[3] ? strcmp(id2str(pool, a[3]), id2str(pool, b[3])) : r;
372 classify_cmp_pkgs(const void *ap, const void *bp, void *dp)
374 Transaction *trans = dp;
375 Pool *pool = trans->pool;
380 sa = pool->solvables + a;
381 sb = pool->solvables + b;
382 if (sa->name != sb->name)
383 return strcmp(id2str(pool, sa->name), id2str(pool, sb->name));
384 if (sa->evr != sb->evr)
386 int r = evrcmp(pool, sa->evr, sb->evr, EVRCMP_COMPARE);
394 transaction_classify(Transaction *trans, int mode, Queue *classes)
396 Pool *pool = trans->pool;
397 int ntypes[SOLVER_TRANSACTION_MAXTYPE];
399 Id v, vq, type, p, q;
402 queue_empty(classes);
403 memset(ntypes, 0, sizeof(ntypes));
404 /* go through transaction and classify each step */
405 for (i = 0; i < trans->steps.count; i++)
407 p = trans->steps.elements[i];
408 s = pool->solvables + p;
409 type = transaction_type(trans, p, mode);
411 if (!pool->installed || s->repo != pool->installed)
413 /* look at arch/vendor changes */
414 q = transaction_obs_pkg(trans, p);
417 sq = pool->solvables + q;
423 if ((mode & SOLVER_TRANSACTION_MERGE_ARCHCHANGES) != 0)
425 for (j = 0; j < classes->count; j += 4)
426 if (classes->elements[j] == SOLVER_TRANSACTION_ARCHCHANGE && classes->elements[j + 2] == v && classes->elements[j + 3] == vq)
428 if (j == classes->count)
430 queue_push(classes, SOLVER_TRANSACTION_ARCHCHANGE);
431 queue_push(classes, 1);
432 queue_push(classes, v);
433 queue_push(classes, vq);
436 classes->elements[j + 1]++;
439 v = s->vendor ? s->vendor : 1;
440 vq = sq->vendor ? sq->vendor : 1;
443 if ((mode & SOLVER_TRANSACTION_MERGE_VENDORCHANGES) != 0)
445 for (j = 0; j < classes->count; j += 4)
446 if (classes->elements[j] == SOLVER_TRANSACTION_VENDORCHANGE && classes->elements[j + 2] == v && classes->elements[j + 3] == vq)
448 if (j == classes->count)
450 queue_push(classes, SOLVER_TRANSACTION_VENDORCHANGE);
451 queue_push(classes, 1);
452 queue_push(classes, v);
453 queue_push(classes, vq);
456 classes->elements[j + 1]++;
459 /* now sort all vendor/arch changes */
460 if (classes->count > 4)
461 sat_sort(classes->elements, classes->count / 4, 4 * sizeof(Id), classify_cmp, trans);
462 /* finally add all classes. put erases last */
463 i = SOLVER_TRANSACTION_ERASE;
466 queue_unshift(classes, 0);
467 queue_unshift(classes, 0);
468 queue_unshift(classes, ntypes[i]);
469 queue_unshift(classes, i);
471 for (i = SOLVER_TRANSACTION_MAXTYPE; i > 0; i--)
475 if (i == SOLVER_TRANSACTION_ERASE)
477 queue_unshift(classes, 0);
478 queue_unshift(classes, 0);
479 queue_unshift(classes, ntypes[i]);
480 queue_unshift(classes, i);
485 transaction_classify_pkgs(Transaction *trans, int mode, Id class, Id from, Id to, Queue *pkgs)
487 Pool *pool = trans->pool;
493 for (i = 0; i < trans->steps.count; i++)
495 p = trans->steps.elements[i];
496 s = pool->solvables + p;
497 if (class <= SOLVER_TRANSACTION_MAXTYPE)
499 type = transaction_type(trans, p, mode);
504 if (!pool->installed || s->repo != pool->installed)
506 q = transaction_obs_pkg(trans, p);
509 sq = pool->solvables + q;
510 if (class == SOLVER_TRANSACTION_ARCHCHANGE)
512 if ((!from && !to) || (s->arch == from && sq->arch == to))
516 if (class == SOLVER_TRANSACTION_VENDORCHANGE)
518 Id v = s->vendor ? s->vendor : 1;
519 Id vq = sq->vendor ? sq->vendor : 1;
520 if ((!from && !to) || (v == from && vq == to))
526 sat_sort(pkgs->elements, pkgs->count, sizeof(Id), classify_cmp_pkgs, trans);
530 create_transaction_info(Transaction *trans, Queue *decisionq)
532 Pool *pool = trans->pool;
533 Queue *ti = &trans->transaction_info;
534 Repo *installed = pool->installed;
540 trans->transaction_installed = sat_free(trans->transaction_installed);
542 return; /* no info needed */
543 for (i = 0; i < decisionq->count; i++)
545 p = decisionq->elements[i];
546 if (p <= 0 || p == SYSTEMSOLVABLE)
548 s = pool->solvables + p;
549 if (!s->repo || s->repo == installed)
551 noobs = trans->noobsmap.size && MAPTST(&trans->noobsmap, p);
552 FOR_PROVIDES(p2, pp2, s->name)
554 if (!MAPTST(&trans->transactsmap, p2))
556 s2 = pool->solvables + p2;
557 if (s2->repo != installed)
559 if (noobs && (s->name != s2->name || s->evr != s2->evr || s->arch != s2->arch))
561 if (!pool->implicitobsoleteusesprovides && s->name != s2->name)
566 if (s->obsoletes && !noobs)
568 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
569 while ((obs = *obsp++) != 0)
571 FOR_PROVIDES(p2, pp2, obs)
573 s2 = pool->solvables + p2;
574 if (s2->repo != installed)
576 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p2, obs))
584 sat_sort(ti->elements, ti->count / 2, 2 * sizeof(Id), obsq_sortcmp, pool);
586 for (i = j = 0; i < ti->count; i += 2)
588 if (j && ti->elements[i] == ti->elements[j - 2] && ti->elements[i + 1] == ti->elements[j - 1])
590 ti->elements[j++] = ti->elements[i];
591 ti->elements[j++] = ti->elements[i + 1];
595 /* create transaction_installed helper */
596 trans->transaction_installed = sat_calloc(installed->end - installed->start, sizeof(Id));
597 for (i = 0; i < ti->count; i += 2)
599 j = ti->elements[i + 1] - installed->start;
600 if (!trans->transaction_installed[j])
601 trans->transaction_installed[j] = ti->elements[i];
604 /* more than one package obsoletes us. compare */
606 if (trans->transaction_installed[j] > 0)
607 trans->transaction_installed[j] = -trans->transaction_installed[j];
608 q[0] = q[2] = ti->elements[i + 1];
609 q[1] = ti->elements[i];
610 q[3] = -trans->transaction_installed[j];
611 if (obsq_sortcmp(q, q + 2, pool) < 0)
612 trans->transaction_installed[j] = -ti->elements[i];
619 transaction_calculate(Transaction *trans, Queue *decisionq, Map *noobsmap)
621 Pool *pool = trans->pool;
622 Repo *installed = pool->installed;
627 if (noobsmap && !noobsmap->size)
628 noobsmap = 0; /* ignore empty map */
629 queue_empty(&trans->steps);
630 map_init(&trans->transactsmap, pool->nsolvables);
632 for (i = 0; i < decisionq->count; i++)
634 p = decisionq->elements[i];
635 s = pool->solvables + (p > 0 ? p : -p);
638 if (installed && s->repo == installed && p < 0)
639 MAPSET(&trans->transactsmap, -p);
640 if ((!installed || s->repo != installed) && p > 0)
642 MAPSET(&trans->transactsmap, p);
643 if (noobsmap && MAPTST(noobsmap, p))
647 MAPCLR(&trans->transactsmap, SYSTEMSOLVABLE);
649 map_init_clone(&trans->noobsmap, noobsmap);
651 create_transaction_info(trans, decisionq);
655 FOR_REPO_SOLVABLES(installed, p, s)
657 if (MAPTST(&trans->transactsmap, p))
658 queue_push(&trans->steps, p);
661 for (i = 0; i < decisionq->count; i++)
663 p = decisionq->elements[i];
664 if (p > 0 && MAPTST(&trans->transactsmap, p))
665 queue_push(&trans->steps, p);
671 struct _TransactionElement {
672 Id p; /* solvable id */
673 Id edges; /* pointer into edges data */
677 struct _TransactionOrderdata {
678 struct _TransactionElement *tes;
683 #define TYPE_BROKEN (1<<0)
684 #define TYPE_CON (1<<1)
686 #define TYPE_REQ_P (1<<2)
687 #define TYPE_PREREQ_P (1<<3)
689 #define TYPE_REQ (1<<4)
690 #define TYPE_PREREQ (1<<5)
692 #define TYPE_CYCLETAIL (1<<16)
693 #define TYPE_CYCLEHEAD (1<<17)
695 #define EDGEDATA_BLOCK 127
698 transaction_init(Transaction *trans, Pool *pool)
700 memset(trans, 0, sizeof(*trans));
705 transaction_free(Transaction *trans)
707 queue_free(&trans->steps);
708 queue_free(&trans->transaction_info);
709 trans->transaction_installed = sat_free(trans->transaction_installed);
710 map_free(&trans->transactsmap);
711 map_free(&trans->noobsmap);
712 if (trans->orderdata)
714 struct _TransactionOrderdata *od = trans->orderdata;
715 od->tes = sat_free(od->tes);
716 od->invedgedata = sat_free(od->invedgedata);
717 trans->orderdata = sat_free(trans->orderdata);
723 struct _TransactionElement *tes;
735 addteedge(struct orderdata *od, int from, int to, int type)
738 struct _TransactionElement *te;
743 /* printf("edge %d(%s) -> %d(%s) type %x\n", from, solvid2str(pool, od->tes[from].p), to, solvid2str(pool, od->tes[to].p), type); */
746 for (i = te->edges; od->edgedata[i]; i += 2)
747 if (od->edgedata[i] == to)
749 /* test of brokenness */
750 if (type == TYPE_BROKEN)
751 return od->edgedata[i] && (od->edgedata[i + 1] & TYPE_BROKEN) != 0 ? 1 : 0;
754 od->edgedata[i + 1] |= type;
757 if (i + 1 == od->nedgedata)
759 /* printf("tail add %d\n", i - te->edges); */
762 od->edgedata = sat_extend(od->edgedata, od->nedgedata, 3, sizeof(Id), EDGEDATA_BLOCK);
766 /* printf("extend %d\n", i - te->edges); */
767 od->edgedata = sat_extend(od->edgedata, od->nedgedata, 3 + (i - te->edges), sizeof(Id), EDGEDATA_BLOCK);
769 memcpy(od->edgedata + od->nedgedata, od->edgedata + te->edges, sizeof(Id) * (i - te->edges));
770 i = od->nedgedata + (i - te->edges);
771 te->edges = od->nedgedata;
773 od->edgedata[i] = to;
774 od->edgedata[i + 1] = type;
775 od->edgedata[i + 2] = 0; /* end marker */
776 od->nedgedata = i + 3;
781 addedge(struct orderdata *od, Id from, Id to, int type)
783 Transaction *trans = od->trans;
784 Pool *pool = trans->pool;
786 struct _TransactionElement *te;
789 // printf("addedge %d %d type %d\n", from, to, type);
790 s = pool->solvables + from;
791 if (s->repo == pool->installed && trans->transaction_installed[from - pool->installed->start])
793 /* obsolete, map to install */
794 if (trans->transaction_installed[from - pool->installed->start] > 0)
795 from = trans->transaction_installed[from - pool->installed->start];
802 queue_init_buffer(&ti, tibuf, sizeof(tibuf)/sizeof(*tibuf));
803 transaction_all_obs_pkgs(trans, from, &ti);
804 for (i = 0; i < ti.count; i++)
805 ret |= addedge(od, ti.elements[i], to, type);
810 s = pool->solvables + to;
811 if (s->repo == pool->installed && trans->transaction_installed[to - pool->installed->start])
813 /* obsolete, map to install */
814 if (trans->transaction_installed[to - pool->installed->start] > 0)
815 to = trans->transaction_installed[to - pool->installed->start];
822 queue_init_buffer(&ti, tibuf, sizeof(tibuf)/sizeof(*tibuf));
823 transaction_all_obs_pkgs(trans, to, &ti);
824 for (i = 0; i < ti.count; i++)
825 ret |= addedge(od, from, ti.elements[i], type);
831 /* map from/to to te numbers */
832 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
839 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
845 return addteedge(od, i, to, type);
850 havechoice(struct orderdata *od, Id p, Id q1, Id q2)
852 Transaction *trans = od->trans;
853 Pool *pool = trans->pool;
854 Id ti1buf[5], ti2buf[5];
858 /* both q1 and q2 are uninstalls. check if their TEs intersect */
859 /* common case: just one TE for both packages */
861 printf("havechoice %d %d %d\n", p, q1, q2);
863 if (trans->transaction_installed[q1 - pool->installed->start] == 0)
865 if (trans->transaction_installed[q2 - pool->installed->start] == 0)
867 if (trans->transaction_installed[q1 - pool->installed->start] == trans->transaction_installed[q2 - pool->installed->start])
869 if (trans->transaction_installed[q1 - pool->installed->start] > 0 && trans->transaction_installed[q2 - pool->installed->start] > 0)
871 queue_init_buffer(&ti1, ti1buf, sizeof(ti1buf)/sizeof(*ti1buf));
872 transaction_all_obs_pkgs(trans, q1, &ti1);
873 queue_init_buffer(&ti2, ti2buf, sizeof(ti2buf)/sizeof(*ti2buf));
874 transaction_all_obs_pkgs(trans, q2, &ti2);
875 for (i = 0; i < ti1.count; i++)
876 for (j = 0; j < ti2.count; j++)
877 if (ti1.elements[i] == ti2.elements[j])
879 /* found a common edge */
891 havescripts(Pool *pool, Id solvid)
893 Solvable *s = pool->solvables + solvid;
899 reqp = s->repo->idarraydata + s->requires;
900 while ((req = *reqp++) != 0)
902 if (req == SOLVABLE_PREREQMARKER)
909 dep = id2str(pool, req);
910 if (*dep == '/' && strcmp(dep, "/sbin/ldconfig") != 0)
918 addsolvableedges(struct orderdata *od, Solvable *s)
920 Transaction *trans = od->trans;
921 Pool *pool = trans->pool;
922 Id req, *reqp, con, *conp;
924 int i, j, pre, numins;
925 Repo *installed = pool->installed;
931 printf("addsolvableedges %s\n", solvable2str(pool, s));
933 p = s - pool->solvables;
937 reqp = s->repo->idarraydata + s->requires;
939 while ((req = *reqp++) != 0)
941 if (req == SOLVABLE_PREREQMARKER)
947 if (pre != TYPE_PREREQ && installed && s->repo == installed)
949 /* ignore normal requires if we're getting obsoleted */
950 if (trans->transaction_installed[p - pool->installed->start])
955 numins = 0; /* number of packages to be installed providing it */
956 provbyinst = 0; /* provided by kept package */
957 FOR_PROVIDES(p2, pp2, req)
959 s2 = pool->solvables + p2;
962 reqq.count = 0; /* self provides */
965 if (s2->repo == installed && !MAPTST(&trans->transactsmap, p2))
969 printf("IGNORE inst provides %s by %s\n", dep2str(pool, req), solvable2str(pool, s2));
970 reqq.count = 0; /* provided by package that stays installed */
976 if (s2->repo != installed && !MAPTST(&trans->transactsmap, p2))
977 continue; /* package stays uninstalled */
979 if (s->repo == installed)
981 /* s gets uninstalled */
982 queue_pushunique(&reqq, p2);
983 if (s2->repo != installed)
988 if (s2->repo == installed)
989 continue; /* s2 gets uninstalled */
990 queue_pushunique(&reqq, p2);
995 /* prune to harmless ->inst edges */
996 for (i = j = 0; i < reqq.count; i++)
997 if (pool->solvables[reqq.elements[i]].repo != installed)
998 reqq.elements[j++] = reqq.elements[i];
1002 if (numins && reqq.count)
1004 if (s->repo == installed)
1006 for (i = 0; i < reqq.count; i++)
1008 if (pool->solvables[reqq.elements[i]].repo == installed)
1010 for (j = 0; j < reqq.count; j++)
1012 if (pool->solvables[reqq.elements[j]].repo != installed)
1014 if (trans->transaction_installed[reqq.elements[i] - pool->installed->start] == reqq.elements[j])
1015 continue; /* no self edge */
1017 printf("add interrreq uninst->inst edge (%s -> %s -> %s)\n", solvid2str(pool, reqq.elements[i]), dep2str(pool, req), solvid2str(pool, reqq.elements[j]));
1019 addedge(od, reqq.elements[i], reqq.elements[j], pre == TYPE_PREREQ ? TYPE_PREREQ_P : TYPE_REQ_P);
1025 /* no mixed types, remove all deps on uninstalls */
1026 for (i = j = 0; i < reqq.count; i++)
1027 if (pool->solvables[reqq.elements[i]].repo != installed)
1028 reqq.elements[j++] = reqq.elements[i];
1033 for (i = 0; i < reqq.count; i++)
1036 p2 = reqq.elements[i];
1037 if (pool->solvables[p2].repo != installed)
1039 /* all elements of reqq are installs, thus have different TEs */
1040 choice = reqq.count - 1;
1041 if (pool->solvables[p].repo != installed)
1044 printf("add inst->inst edge choice %d (%s -> %s -> %s)\n", choice, solvid2str(pool, p), dep2str(pool, req), solvid2str(pool, p2));
1046 addedge(od, p, p2, pre);
1051 printf("add uninst->inst edge choice %d (%s -> %s -> %s)\n", choice, solvid2str(pool, p), dep2str(pool, req), solvid2str(pool, p2));
1053 addedge(od, p, p2, pre == TYPE_PREREQ ? TYPE_PREREQ_P : TYPE_REQ_P);
1058 if (s->repo != installed)
1059 continue; /* no inst->uninst edges, please! */
1061 /* uninst -> uninst edge. Those make trouble. Only add if we must */
1062 if (trans->transaction_installed[p - installed->start] && !havescripts(pool, p))
1064 /* p is obsoleted by another package and has no scripts */
1065 /* we assume that the obsoletor is good enough to replace p */
1070 for (j = 0; j < reqq.count; j++)
1074 if (havechoice(od, p, reqq.elements[i], reqq.elements[j]))
1079 printf("add uninst->uninst edge choice %d (%s -> %s -> %s)\n", choice, solvid2str(pool, p), dep2str(pool, req), solvid2str(pool, p2));
1081 addedge(od, p2, p, pre == TYPE_PREREQ ? TYPE_PREREQ_P : TYPE_REQ_P);
1088 conp = s->repo->idarraydata + s->conflicts;
1089 while ((con = *conp++) != 0)
1091 FOR_PROVIDES(p2, pp2, con)
1095 s2 = pool->solvables + p2;
1098 if (s->repo == installed)
1100 if (s2->repo != installed && MAPTST(&trans->transactsmap, p2))
1102 /* deinstall p before installing p2 */
1103 addedge(od, p2, p, TYPE_CON);
1108 if (s2->repo == installed && MAPTST(&trans->transactsmap, p2))
1110 /* deinstall p2 before installing p */
1111 addedge(od, p, p2, TYPE_CON);
1122 /* break an edge in a cycle */
1124 breakcycle(struct orderdata *od, Id *cycle)
1126 Pool *pool = od->trans->pool;
1127 Id ddegmin, ddegmax, ddeg;
1129 struct _TransactionElement *te;
1132 ddegmin = ddegmax = 0;
1133 for (k = 0; cycle[k + 1]; k += 2)
1135 ddeg = od->edgedata[cycle[k + 1] + 1];
1138 if (!k || ddeg < ddegmin)
1144 if (ddeg == ddegmin)
1146 if (havescripts(pool, od->tes[cycle[l]].p) && !havescripts(pool, od->tes[cycle[k]].p))
1148 /* prefer k, as l comes from a package with contains scriptlets */
1153 /* same edge value, check for prereq */
1157 /* record brkoen cycle starting with the tail */
1158 queue_push(&od->cycles, od->cyclesdata.count); /* offset into data */
1159 queue_push(&od->cycles, k / 2); /* cycle elements */
1160 queue_push(&od->cycles, od->edgedata[cycle[l + 1] + 1]); /* broken edge */
1167 queue_push(&od->cyclesdata, cycle[k]);
1171 queue_push(&od->cyclesdata, 0); /* mark end */
1173 /* break that edge */
1174 od->edgedata[cycle[l + 1] + 1] |= TYPE_BROKEN;
1177 if (ddegmin < TYPE_REQ)
1181 /* cycle recorded, print it */
1182 if (ddegmin >= TYPE_REQ && (ddegmax & TYPE_PREREQ) != 0)
1183 POOL_DEBUG(SAT_DEBUG_STATS, "CRITICAL ");
1184 POOL_DEBUG(SAT_DEBUG_STATS, "cycle: --> ");
1185 for (k = 0; cycle[k + 1]; k += 2)
1187 te = od->tes + cycle[k];
1188 if ((od->edgedata[cycle[k + 1] + 1] & TYPE_BROKEN) != 0)
1189 POOL_DEBUG(SAT_DEBUG_STATS, "%s ##%x##> ", solvid2str(pool, te->p), od->edgedata[cycle[k + 1] + 1]);
1191 POOL_DEBUG(SAT_DEBUG_STATS, "%s --%x--> ", solvid2str(pool, te->p), od->edgedata[cycle[k + 1] + 1]);
1193 POOL_DEBUG(SAT_DEBUG_STATS, "\n");
1197 dump_tes(struct orderdata *od)
1199 Pool *pool = od->trans->pool;
1202 struct _TransactionElement *te, *te2;
1205 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1207 Solvable *s = pool->solvables + te->p;
1208 POOL_DEBUG(SAT_WARN, "TE %4d: %c%s\n", i, s->repo == pool->installed ? '-' : '+', solvable2str(pool, s));
1209 if (s->repo != pool->installed)
1212 transaction_all_obs_pkgs(od->trans, te->p, &obsq);
1213 for (j = 0; j < obsq.count; j++)
1214 POOL_DEBUG(SAT_WARN, " -%s\n", solvid2str(pool, obsq.elements[j]));
1216 for (j = te->edges; od->edgedata[j]; j += 2)
1218 te2 = od->tes + od->edgedata[j];
1219 POOL_DEBUG(SAT_WARN, " --%x--> TE %4d: %s\n", od->edgedata[j + 1], od->edgedata[j], solvid2str(pool, te2->p));
1226 reachable(struct orderdata *od, Id i)
1228 struct _TransactionElement *te = od->tes + i;
1234 for (j = te->edges; (k = od->edgedata[j]) != 0; j += 2)
1236 if ((od->edgedata[j + 1] & TYPE_BROKEN) != 0)
1238 if (!od->tes[k].mark)
1240 if (od->tes[k].mark == 2)
1251 addcycleedges(struct orderdata *od, Id *cycle, Queue *todo)
1254 Transaction *trans = od->trans;
1255 Pool *pool = trans->pool;
1257 struct _TransactionElement *te;
1264 printf("addcycleedges\n");
1265 for (i = 0; (j = cycle[i]) != 0; i++)
1266 printf("cycle %s\n", solvid2str(pool, od->tes[j].p));
1269 /* first add all the tail cycle edges */
1271 /* see what we can reach from the cycle */
1273 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1275 for (i = 0; (j = cycle[i]) != 0; i++)
1277 od->tes[j].mark = -1;
1278 queue_push(todo, j);
1282 i = queue_pop(todo);
1286 te->mark = te->mark < 0 ? 2 : 1;
1287 for (j = te->edges; (k = od->edgedata[j]) != 0; j += 2)
1289 if ((od->edgedata[j + 1] & TYPE_BROKEN) != 0)
1291 if (od->tes[k].mark > 0)
1292 continue; /* no need to visit again */
1293 queue_push(todo, k);
1296 /* now all cycle TEs are marked with 2, all TEs reachable
1297 * from the cycle are marked with 1 */
1299 od->tes[tail].mark = 1; /* no need to add edges */
1301 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1304 continue; /* reachable from cycle */
1305 for (j = te->edges; (k = od->edgedata[j]) != 0; j += 2)
1307 if ((od->edgedata[j + 1] & TYPE_BROKEN) != 0)
1309 if (od->tes[k].mark != 2)
1311 /* We found an edge to the cycle. Add an extra edge to the tail */
1312 /* the TE was not reachable, so we're not creating a new cycle! */
1314 printf("adding TO TAIL cycle edge %d->%d %s->%s!\n", i, tail, solvid2str(pool, od->tes[i].p), solvid2str(pool, od->tes[tail].p));
1316 j -= te->edges; /* in case we move */
1317 addteedge(od, i, tail, TYPE_CYCLETAIL);
1319 break; /* one edge is enough */
1324 /* now add all head cycle edges */
1327 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1330 for (i = 0; (j = cycle[i]) != 0; i++)
1333 od->tes[j].mark = 2;
1335 /* first the head to save some time */
1336 te = od->tes + head;
1337 for (j = te->edges; (k = od->edgedata[j]) != 0; j += 2)
1339 if ((od->edgedata[j + 1] & TYPE_BROKEN) != 0)
1341 if (!od->tes[k].mark)
1343 if (od->tes[k].mark == -1)
1344 od->tes[k].mark = -2; /* no need for another edge */
1346 for (i = 0; cycle[i] != 0; i++)
1348 if (cycle[i] == head)
1350 te = od->tes + cycle[i];
1351 for (j = te->edges; (k = od->edgedata[j]) != 0; j += 2)
1353 if ((od->edgedata[j + 1] & TYPE_BROKEN) != 0)
1355 /* see if we can reach a cycle TE from k */
1356 if (!od->tes[k].mark)
1358 if (od->tes[k].mark == -1)
1361 printf("adding FROM HEAD cycle edge %d->%d %s->%s [%s]!\n", head, k, solvid2str(pool, od->tes[head].p), solvid2str(pool, od->tes[k].p), solvid2str(pool, od->tes[cycle[i]].p));
1363 addteedge(od, head, k, TYPE_CYCLEHEAD);
1364 od->tes[k].mark = -2; /* no need to add that one again */
1372 transaction_order(Transaction *trans, int flags)
1374 Pool *pool = trans->pool;
1375 Queue *tr = &trans->steps;
1376 Repo *installed = pool->installed;
1379 int i, j, k, numte, numedge;
1380 struct orderdata od;
1381 struct _TransactionElement *te;
1382 Queue todo, obsq, samerepoq, uninstq;
1383 int cycstart, cycel;
1391 start = now = sat_timems(0);
1392 POOL_DEBUG(SAT_DEBUG_STATS, "ordering transaction\n");
1393 /* free old data if present */
1394 if (trans->orderdata)
1396 struct _TransactionOrderdata *od = trans->orderdata;
1397 od->tes = sat_free(od->tes);
1398 od->invedgedata = sat_free(od->invedgedata);
1399 trans->orderdata = sat_free(trans->orderdata);
1402 /* create a transaction element for every active component */
1404 for (i = 0; i < tr->count; i++)
1406 p = tr->elements[i];
1407 s = pool->solvables + p;
1408 if (installed && s->repo == installed && trans->transaction_installed[p - installed->start])
1412 POOL_DEBUG(SAT_DEBUG_STATS, "transaction elements: %d\n", numte);
1414 return; /* nothing to do... */
1416 numte++; /* leave first one zero */
1417 memset(&od, 0, sizeof(od));
1420 od.tes = sat_calloc(numte, sizeof(*od.tes));
1421 od.edgedata = sat_extend(0, 0, 1, sizeof(Id), EDGEDATA_BLOCK);
1424 queue_init(&od.cycles);
1426 /* initialize TEs */
1427 for (i = 0, te = od.tes + 1; i < tr->count; i++)
1429 p = tr->elements[i];
1430 s = pool->solvables + p;
1431 if (installed && s->repo == installed && trans->transaction_installed[p - installed->start])
1437 /* create dependency graph */
1438 for (i = 0; i < tr->count; i++)
1439 addsolvableedges(&od, pool->solvables + tr->elements[i]);
1443 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1444 for (j = te->edges; od.edgedata[j]; j += 2)
1446 POOL_DEBUG(SAT_DEBUG_STATS, "edges: %d, edge space: %d\n", numedge, od.nedgedata / 2);
1447 POOL_DEBUG(SAT_DEBUG_STATS, "edge creation took %d ms\n", sat_timems(now));
1453 now = sat_timems(0);
1454 /* kill all cycles */
1456 for (i = numte - 1; i > 0; i--)
1457 queue_push(&todo, i);
1461 i = queue_pop(&todo);
1462 /* printf("- look at TE %d\n", i); */
1466 od.tes[i].mark = 2; /* done with that one */
1471 continue; /* already finished before */
1474 int edgestovisit = 0;
1475 /* new node, visit edges */
1476 for (j = te->edges; (k = od.edgedata[j]) != 0; j += 2)
1478 if ((od.edgedata[j + 1] & TYPE_BROKEN) != 0)
1480 if (od.tes[k].mark == 2)
1481 continue; /* no need to visit again */
1482 if (!edgestovisit++)
1483 queue_push(&todo, -i); /* end of edges marker */
1484 queue_push(&todo, k);
1487 te->mark = 2; /* no edges, done with that one */
1489 te->mark = 1; /* under investigation */
1492 /* oh no, we found a cycle */
1493 /* find start of cycle node (<0) */
1494 for (j = todo.count - 1; j >= 0; j--)
1495 if (todo.elements[j] == -i)
1499 /* build te/edge chain */
1501 for (j = k; j < todo.count; j++)
1502 if (todo.elements[j] < 0)
1503 todo.elements[k++] = -todo.elements[j];
1504 cycel = k - cycstart;
1506 /* make room for edges, two extra element for cycle loop + terminating 0 */
1507 while (todo.count < cycstart + 2 * cycel + 2)
1508 queue_push(&todo, 0);
1509 cycle = todo.elements + cycstart;
1510 cycle[cycel] = i; /* close the loop */
1511 cycle[2 * cycel + 1] = 0; /* terminator */
1512 for (k = cycel; k > 0; k--)
1514 cycle[k * 2] = cycle[k];
1515 te = od.tes + cycle[k - 1];
1516 assert(te->mark == 1);
1517 te->mark = 0; /* reset investigation marker */
1518 /* printf("searching for edge from %d to %d\n", cycle[k - 1], cycle[k]); */
1519 for (j = te->edges; od.edgedata[j]; j += 2)
1520 if (od.edgedata[j] == cycle[k])
1522 assert(od.edgedata[j]);
1523 cycle[k * 2 - 1] = j;
1525 /* now cycle looks like this: */
1526 /* te1 edge te2 edge te3 ... teN edge te1 0 */
1527 breakcycle(&od, cycle);
1528 /* restart with start of cycle */
1529 todo.count = cycstart + 1;
1531 POOL_DEBUG(SAT_DEBUG_STATS, "cycles broken: %d\n", od.ncycles);
1532 POOL_DEBUG(SAT_DEBUG_STATS, "cycle breaking took %d ms\n", sat_timems(now));
1534 now = sat_timems(0);
1535 /* now go through all broken cycles and create cycle edges to help
1537 for (i = od.cycles.count - 3; i >= 0; i -= 3)
1539 if (od.cycles.elements[i + 2] >= TYPE_REQ)
1540 addcycleedges(&od, od.cyclesdata.elements + od.cycles.elements[i], &todo);
1542 for (i = od.cycles.count - 3; i >= 0; i -= 3)
1544 if (od.cycles.elements[i + 2] < TYPE_REQ)
1545 addcycleedges(&od, od.cyclesdata.elements + od.cycles.elements[i], &todo);
1547 POOL_DEBUG(SAT_DEBUG_STATS, "cycle edge creation took %d ms\n", sat_timems(now));
1549 /* all edges are finally set up and there are no cycles, now the easy part.
1550 * Create an ordered transaction */
1551 now = sat_timems(0);
1552 /* first invert all edges */
1553 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1554 te->mark = 1; /* term 0 */
1555 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1557 for (j = te->edges; od.edgedata[j]; j += 2)
1559 if ((od.edgedata[j + 1] & TYPE_BROKEN) != 0)
1561 od.tes[od.edgedata[j]].mark++;
1565 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1570 POOL_DEBUG(SAT_DEBUG_STATS, "invedge space: %d\n", j + 1);
1571 od.invedgedata = sat_calloc(j + 1, sizeof(Id));
1572 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1574 for (j = te->edges; od.edgedata[j]; j += 2)
1576 if ((od.edgedata[j + 1] & TYPE_BROKEN) != 0)
1578 od.invedgedata[--od.tes[od.edgedata[j]].mark] = i;
1581 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1582 te->edges = te->mark; /* edges now points into invedgedata */
1583 od.edgedata = sat_free(od.edgedata);
1585 /* now the final ordering */
1586 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1588 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1589 for (j = te->edges; od.invedgedata[j]; j++)
1590 od.tes[od.invedgedata[j]].mark++;
1592 queue_init(&samerepoq);
1593 queue_init(&uninstq);
1595 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1598 if (installed && pool->solvables[te->p].repo == installed)
1599 queue_push(&uninstq, i);
1601 queue_push(&todo, i);
1603 assert(todo.count > 0 || uninstq.count > 0);
1604 oldcount = tr->count;
1611 temedianr = sat_calloc(numte, sizeof(Id));
1612 for (i = 1; i < numte; i++)
1614 Solvable *s = pool->solvables + od.tes[i].p;
1615 if (installed && s->repo == installed)
1618 j = solvable_lookup_num(s, SOLVABLE_MEDIANR, 1);
1623 /* select an TE i */
1625 i = queue_shift(&uninstq);
1626 else if (samerepoq.count)
1627 i = queue_shift(&samerepoq);
1628 else if (todo.count)
1630 /* find next repo/media */
1631 for (j = 0; j < todo.count; j++)
1633 if (!j || temedianr[todo.elements[j]] < lastmedia)
1636 lastmedia = temedianr[todo.elements[j]];
1639 lastrepo = pool->solvables[od.tes[todo.elements[i]].p].repo;
1641 /* move all matching TEs to samerepoq */
1642 for (i = j = 0; j < todo.count; j++)
1644 int k = todo.elements[j];
1645 if (temedianr[k] == lastmedia && pool->solvables[od.tes[k].p].repo == lastrepo)
1646 queue_push(&samerepoq, k);
1648 todo.elements[i++] = k;
1652 assert(samerepoq.count);
1653 i = queue_shift(&samerepoq);
1659 queue_push(tr, te->p);
1661 printf("do %s [%d]\n", solvid2str(pool, te->p), temedianr[i]);
1663 s = pool->solvables + te->p;
1664 for (j = te->edges; od.invedgedata[j]; j++)
1666 struct _TransactionElement *te2 = od.tes + od.invedgedata[j];
1667 assert(te2->mark > 0);
1668 if (--te2->mark == 0)
1670 Solvable *s = pool->solvables + te2->p;
1672 printf("free %s [%d]\n", solvid2str(pool, te2->p), temedianr[od.invedgedata[j]]);
1674 if (installed && s->repo == installed)
1675 queue_push(&uninstq, od.invedgedata[j]);
1676 else if (s->repo == lastrepo && temedianr[od.invedgedata[j]] == lastmedia)
1677 queue_push(&samerepoq, od.invedgedata[j]);
1679 queue_push(&todo, od.invedgedata[j]);
1683 sat_free(temedianr);
1685 queue_free(&samerepoq);
1686 queue_free(&uninstq);
1688 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1689 assert(te->mark == 0);
1691 /* add back obsoleted packages */
1692 transaction_add_obsoleted(trans);
1693 assert(tr->count == oldcount);
1695 POOL_DEBUG(SAT_DEBUG_STATS, "creating new transaction took %d ms\n", sat_timems(now));
1696 POOL_DEBUG(SAT_DEBUG_STATS, "transaction ordering took %d ms\n", sat_timems(start));
1698 if ((flags & SOLVER_TRANSACTION_KEEP_ORDERDATA) != 0)
1700 trans->orderdata = sat_calloc(1, sizeof(*trans->orderdata));
1701 trans->orderdata->tes = od.tes;
1702 trans->orderdata->ntes = numte;
1703 trans->orderdata->invedgedata = od.invedgedata;
1708 sat_free(od.invedgedata);
1714 transaction_order_add_choices(Transaction *trans, Id chosen, Queue *choices)
1717 struct _TransactionOrderdata *od = trans->orderdata;
1718 struct _TransactionElement *te;
1721 return choices->count;
1724 /* initialization step */
1725 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1727 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1729 for (j = te->edges; od->invedgedata[j]; j++)
1730 od->tes[od->invedgedata[j]].mark++;
1732 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1734 queue_push(choices, te->p);
1735 return choices->count;
1737 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1738 if (te->p == chosen)
1741 return choices->count;
1744 /* hey! out-of-order installation! */
1747 for (j = te->edges; od->invedgedata[j]; j++)
1749 te = od->tes + od->invedgedata[j];
1750 assert(te->mark > 0 || te->mark == -1);
1751 if (te->mark > 0 && --te->mark == 0)
1752 queue_push(choices, te->p);
1754 return choices->count;
1758 transaction_add_obsoleted(Transaction *trans)
1760 Pool *pool = trans->pool;
1761 Repo *installed = pool->installed;
1764 int i, j, k, max, oldcount;
1768 if (!installed || !trans->steps.count)
1770 /* calculate upper bound */
1772 FOR_REPO_SOLVABLES(installed, p, s)
1773 if (MAPTST(&trans->transactsmap, p))
1778 steps = &trans->steps;
1779 oldcount = steps->count;
1780 queue_insertn(steps, 0, max);
1783 map_init(&done, installed->end - installed->start);
1785 for (j = 0, i = max; i < steps->count; i++)
1787 p = trans->steps.elements[i];
1788 if (pool->solvables[p].repo == installed)
1790 if (!trans->transaction_installed[p - pool->installed->start])
1791 trans->steps.elements[j++] = p;
1794 trans->steps.elements[j++] = p;
1796 transaction_all_obs_pkgs(trans, p, &obsq);
1797 for (k = 0; k < obsq.count; k++)
1799 p = obsq.elements[k];
1800 assert(p >= installed->start && p < installed->end);
1801 if (MAPTST(&done, p - installed->start))
1803 MAPSET(&done, p - installed->start);
1804 trans->steps.elements[j++] = p;
1808 /* free unneeded space */
1809 queue_truncate(steps, j);
1815 transaction_check_pkg(Transaction *trans, Id tepkg, Id pkg, Map *ins, Map *seen, int onlyprereq, Id noconfpkg, int depth)
1817 Pool *pool = trans->pool;
1822 if (MAPTST(seen, pkg))
1825 s = pool->solvables + pkg;
1827 printf("- %*s%c%s\n", depth * 2, "", s->repo == pool->installed ? '-' : '+', solvable2str(pool, s));
1833 reqp = s->repo->idarraydata + s->requires;
1834 while ((req = *reqp++) != 0)
1836 if (req == SOLVABLE_PREREQMARKER)
1841 if (onlyprereq && !inpre)
1843 if (!strncmp(id2str(pool, req), "rpmlib(", 7))
1846 /* first check kept packages, then freshly installed, then not yet uninstalled */
1847 FOR_PROVIDES(p, pp, req)
1849 if (!MAPTST(ins, p))
1851 if (MAPTST(&trans->transactsmap, p))
1854 transaction_check_pkg(trans, tepkg, p, ins, seen, 0, noconfpkg, depth + 1);
1858 FOR_PROVIDES(p, pp, req)
1860 if (!MAPTST(ins, p))
1862 if (pool->solvables[p].repo == pool->installed)
1865 transaction_check_pkg(trans, tepkg, p, ins, seen, 0, noconfpkg, depth + 1);
1870 FOR_PROVIDES(p, pp, req)
1872 if (!MAPTST(ins, p))
1875 transaction_check_pkg(trans, tepkg, p, ins, seen, 0, noconfpkg, depth + 1);
1880 POOL_DEBUG(SAT_WARN, " %c%s: nothing provides %s needed by %c%s\n", pool->solvables[tepkg].repo == pool->installed ? '-' : '+', solvid2str(pool, tepkg), dep2str(pool, req), s->repo == pool->installed ? '-' : '+', solvable2str(pool, s));
1887 transaction_check_order(Transaction *trans)
1889 Pool *pool = trans->pool;
1895 POOL_DEBUG(SAT_WARN, "\nchecking transaction order...\n");
1896 map_init(&ins, pool->nsolvables);
1897 map_init(&seen, pool->nsolvables);
1898 if (pool->installed)
1899 FOR_REPO_SOLVABLES(pool->installed, p, s)
1902 for (i = 0; i < trans->steps.count; i++)
1904 p = trans->steps.elements[i];
1905 s = pool->solvables + p;
1906 if (s->repo != pool->installed)
1908 if (s->repo != pool->installed)
1910 if (havescripts(pool, p))
1913 transaction_check_pkg(trans, p, p, &ins, &seen, 1, lastins, 0);
1915 if (s->repo == pool->installed)
1920 POOL_DEBUG(SAT_WARN, "transaction order check done.\n");