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);
670 transaction_installedresult(Transaction *trans, Queue *installedq)
672 Pool *pool = trans->pool;
673 Repo *installed = pool->installed;
678 queue_empty(installedq);
679 /* first the new installs, than the kept packages */
680 for (i = 0; i < trans->steps.count; i++)
682 p = trans->steps.elements[i];
683 s = pool->solvables + p;
684 if (installed && s->repo == installed)
686 queue_push(installedq, p);
688 cutoff = installedq->count;
691 FOR_REPO_SOLVABLES(installed, p, s)
692 if (!MAPTST(&trans->transactsmap, p))
693 queue_push(installedq, p);
698 struct _TransactionElement {
699 Id p; /* solvable id */
700 Id edges; /* pointer into edges data */
704 struct _TransactionOrderdata {
705 struct _TransactionElement *tes;
711 #define TYPE_BROKEN (1<<0)
712 #define TYPE_CON (1<<1)
714 #define TYPE_REQ_P (1<<2)
715 #define TYPE_PREREQ_P (1<<3)
717 #define TYPE_REQ (1<<4)
718 #define TYPE_PREREQ (1<<5)
720 #define TYPE_CYCLETAIL (1<<16)
721 #define TYPE_CYCLEHEAD (1<<17)
723 #define EDGEDATA_BLOCK 127
726 transaction_init(Transaction *trans, Pool *pool)
728 memset(trans, 0, sizeof(*trans));
733 transaction_init_clone(Transaction *trans, Transaction *srctrans)
735 memset(trans, 0, sizeof(*trans));
736 trans->pool = srctrans->pool;
737 queue_init_clone(&trans->steps, &srctrans->steps);
738 queue_init_clone(&trans->transaction_info, &srctrans->transaction_info);
739 if (srctrans->transaction_installed)
741 Repo *installed = srctrans->pool->installed;
742 trans->transaction_installed = sat_calloc(installed->end - installed->start, sizeof(Id));
743 memcpy(trans->transaction_installed, srctrans->transaction_installed, (installed->end - installed->start) * sizeof(Id));
745 map_init_clone(&trans->transactsmap, &srctrans->transactsmap);
746 map_init_clone(&trans->noobsmap, &srctrans->noobsmap);
747 if (srctrans->orderdata)
749 struct _TransactionOrderdata *od = srctrans->orderdata;
750 trans->orderdata = sat_calloc(1, sizeof(*trans->orderdata));
751 trans->orderdata->tes = sat_malloc2(od->ntes, sizeof(*od->tes));
752 memcpy(trans->orderdata->tes, od->tes, od->ntes * sizeof(*od->tes));
753 trans->orderdata->ntes = od->ntes;
754 trans->orderdata->invedgedata = sat_malloc2(od->ninvedgedata, sizeof(Id));
755 memcpy(trans->orderdata->invedgedata, od->invedgedata, od->ninvedgedata * sizeof(Id));
756 trans->orderdata->ninvedgedata = od->ninvedgedata;
761 transaction_free(Transaction *trans)
763 queue_free(&trans->steps);
764 queue_free(&trans->transaction_info);
765 trans->transaction_installed = sat_free(trans->transaction_installed);
766 map_free(&trans->transactsmap);
767 map_free(&trans->noobsmap);
768 transaction_free_orderdata(trans);
772 transaction_free_orderdata(Transaction *trans)
774 if (trans->orderdata)
776 struct _TransactionOrderdata *od = trans->orderdata;
777 od->tes = sat_free(od->tes);
778 od->invedgedata = sat_free(od->invedgedata);
779 trans->orderdata = sat_free(trans->orderdata);
785 struct _TransactionElement *tes;
797 addteedge(struct orderdata *od, int from, int to, int type)
800 struct _TransactionElement *te;
805 /* printf("edge %d(%s) -> %d(%s) type %x\n", from, solvid2str(pool, od->tes[from].p), to, solvid2str(pool, od->tes[to].p), type); */
808 for (i = te->edges; od->edgedata[i]; i += 2)
809 if (od->edgedata[i] == to)
811 /* test of brokenness */
812 if (type == TYPE_BROKEN)
813 return od->edgedata[i] && (od->edgedata[i + 1] & TYPE_BROKEN) != 0 ? 1 : 0;
816 od->edgedata[i + 1] |= type;
819 if (i + 1 == od->nedgedata)
821 /* printf("tail add %d\n", i - te->edges); */
824 od->edgedata = sat_extend(od->edgedata, od->nedgedata, 3, sizeof(Id), EDGEDATA_BLOCK);
828 /* printf("extend %d\n", i - te->edges); */
829 od->edgedata = sat_extend(od->edgedata, od->nedgedata, 3 + (i - te->edges), sizeof(Id), EDGEDATA_BLOCK);
831 memcpy(od->edgedata + od->nedgedata, od->edgedata + te->edges, sizeof(Id) * (i - te->edges));
832 i = od->nedgedata + (i - te->edges);
833 te->edges = od->nedgedata;
835 od->edgedata[i] = to;
836 od->edgedata[i + 1] = type;
837 od->edgedata[i + 2] = 0; /* end marker */
838 od->nedgedata = i + 3;
843 addedge(struct orderdata *od, Id from, Id to, int type)
845 Transaction *trans = od->trans;
846 Pool *pool = trans->pool;
848 struct _TransactionElement *te;
851 // printf("addedge %d %d type %d\n", from, to, type);
852 s = pool->solvables + from;
853 if (s->repo == pool->installed && trans->transaction_installed[from - pool->installed->start])
855 /* obsolete, map to install */
856 if (trans->transaction_installed[from - pool->installed->start] > 0)
857 from = trans->transaction_installed[from - pool->installed->start];
864 queue_init_buffer(&ti, tibuf, sizeof(tibuf)/sizeof(*tibuf));
865 transaction_all_obs_pkgs(trans, from, &ti);
866 for (i = 0; i < ti.count; i++)
867 ret |= addedge(od, ti.elements[i], to, type);
872 s = pool->solvables + to;
873 if (s->repo == pool->installed && trans->transaction_installed[to - pool->installed->start])
875 /* obsolete, map to install */
876 if (trans->transaction_installed[to - pool->installed->start] > 0)
877 to = trans->transaction_installed[to - pool->installed->start];
884 queue_init_buffer(&ti, tibuf, sizeof(tibuf)/sizeof(*tibuf));
885 transaction_all_obs_pkgs(trans, to, &ti);
886 for (i = 0; i < ti.count; i++)
887 ret |= addedge(od, from, ti.elements[i], type);
893 /* map from/to to te numbers */
894 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
901 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
907 return addteedge(od, i, to, type);
912 havechoice(struct orderdata *od, Id p, Id q1, Id q2)
914 Transaction *trans = od->trans;
915 Pool *pool = trans->pool;
916 Id ti1buf[5], ti2buf[5];
920 /* both q1 and q2 are uninstalls. check if their TEs intersect */
921 /* common case: just one TE for both packages */
923 printf("havechoice %d %d %d\n", p, q1, q2);
925 if (trans->transaction_installed[q1 - pool->installed->start] == 0)
927 if (trans->transaction_installed[q2 - pool->installed->start] == 0)
929 if (trans->transaction_installed[q1 - pool->installed->start] == trans->transaction_installed[q2 - pool->installed->start])
931 if (trans->transaction_installed[q1 - pool->installed->start] > 0 && trans->transaction_installed[q2 - pool->installed->start] > 0)
933 queue_init_buffer(&ti1, ti1buf, sizeof(ti1buf)/sizeof(*ti1buf));
934 transaction_all_obs_pkgs(trans, q1, &ti1);
935 queue_init_buffer(&ti2, ti2buf, sizeof(ti2buf)/sizeof(*ti2buf));
936 transaction_all_obs_pkgs(trans, q2, &ti2);
937 for (i = 0; i < ti1.count; i++)
938 for (j = 0; j < ti2.count; j++)
939 if (ti1.elements[i] == ti2.elements[j])
941 /* found a common edge */
953 havescripts(Pool *pool, Id solvid)
955 Solvable *s = pool->solvables + solvid;
961 reqp = s->repo->idarraydata + s->requires;
962 while ((req = *reqp++) != 0)
964 if (req == SOLVABLE_PREREQMARKER)
971 dep = id2str(pool, req);
972 if (*dep == '/' && strcmp(dep, "/sbin/ldconfig") != 0)
980 addsolvableedges(struct orderdata *od, Solvable *s)
982 Transaction *trans = od->trans;
983 Pool *pool = trans->pool;
984 Id req, *reqp, con, *conp;
986 int i, j, pre, numins;
987 Repo *installed = pool->installed;
993 printf("addsolvableedges %s\n", solvable2str(pool, s));
995 p = s - pool->solvables;
999 reqp = s->repo->idarraydata + s->requires;
1001 while ((req = *reqp++) != 0)
1003 if (req == SOLVABLE_PREREQMARKER)
1009 if (pre != TYPE_PREREQ && installed && s->repo == installed)
1011 /* ignore normal requires if we're getting obsoleted */
1012 if (trans->transaction_installed[p - pool->installed->start])
1017 numins = 0; /* number of packages to be installed providing it */
1018 provbyinst = 0; /* provided by kept package */
1019 FOR_PROVIDES(p2, pp2, req)
1021 s2 = pool->solvables + p2;
1024 reqq.count = 0; /* self provides */
1027 if (s2->repo == installed && !MAPTST(&trans->transactsmap, p2))
1031 printf("IGNORE inst provides %s by %s\n", dep2str(pool, req), solvable2str(pool, s2));
1032 reqq.count = 0; /* provided by package that stays installed */
1038 if (s2->repo != installed && !MAPTST(&trans->transactsmap, p2))
1039 continue; /* package stays uninstalled */
1041 if (s->repo == installed)
1043 /* s gets uninstalled */
1044 queue_pushunique(&reqq, p2);
1045 if (s2->repo != installed)
1050 if (s2->repo == installed)
1051 continue; /* s2 gets uninstalled */
1052 queue_pushunique(&reqq, p2);
1057 /* prune to harmless ->inst edges */
1058 for (i = j = 0; i < reqq.count; i++)
1059 if (pool->solvables[reqq.elements[i]].repo != installed)
1060 reqq.elements[j++] = reqq.elements[i];
1064 if (numins && reqq.count)
1066 if (s->repo == installed)
1068 for (i = 0; i < reqq.count; i++)
1070 if (pool->solvables[reqq.elements[i]].repo == installed)
1072 for (j = 0; j < reqq.count; j++)
1074 if (pool->solvables[reqq.elements[j]].repo != installed)
1076 if (trans->transaction_installed[reqq.elements[i] - pool->installed->start] == reqq.elements[j])
1077 continue; /* no self edge */
1079 printf("add interrreq uninst->inst edge (%s -> %s -> %s)\n", solvid2str(pool, reqq.elements[i]), dep2str(pool, req), solvid2str(pool, reqq.elements[j]));
1081 addedge(od, reqq.elements[i], reqq.elements[j], pre == TYPE_PREREQ ? TYPE_PREREQ_P : TYPE_REQ_P);
1087 /* no mixed types, remove all deps on uninstalls */
1088 for (i = j = 0; i < reqq.count; i++)
1089 if (pool->solvables[reqq.elements[i]].repo != installed)
1090 reqq.elements[j++] = reqq.elements[i];
1095 for (i = 0; i < reqq.count; i++)
1098 p2 = reqq.elements[i];
1099 if (pool->solvables[p2].repo != installed)
1101 /* all elements of reqq are installs, thus have different TEs */
1102 choice = reqq.count - 1;
1103 if (pool->solvables[p].repo != installed)
1106 printf("add inst->inst edge choice %d (%s -> %s -> %s)\n", choice, solvid2str(pool, p), dep2str(pool, req), solvid2str(pool, p2));
1108 addedge(od, p, p2, pre);
1113 printf("add uninst->inst edge choice %d (%s -> %s -> %s)\n", choice, solvid2str(pool, p), dep2str(pool, req), solvid2str(pool, p2));
1115 addedge(od, p, p2, pre == TYPE_PREREQ ? TYPE_PREREQ_P : TYPE_REQ_P);
1120 if (s->repo != installed)
1121 continue; /* no inst->uninst edges, please! */
1123 /* uninst -> uninst edge. Those make trouble. Only add if we must */
1124 if (trans->transaction_installed[p - installed->start] && !havescripts(pool, p))
1126 /* p is obsoleted by another package and has no scripts */
1127 /* we assume that the obsoletor is good enough to replace p */
1132 for (j = 0; j < reqq.count; j++)
1136 if (havechoice(od, p, reqq.elements[i], reqq.elements[j]))
1141 printf("add uninst->uninst edge choice %d (%s -> %s -> %s)\n", choice, solvid2str(pool, p), dep2str(pool, req), solvid2str(pool, p2));
1143 addedge(od, p2, p, pre == TYPE_PREREQ ? TYPE_PREREQ_P : TYPE_REQ_P);
1150 conp = s->repo->idarraydata + s->conflicts;
1151 while ((con = *conp++) != 0)
1153 FOR_PROVIDES(p2, pp2, con)
1157 s2 = pool->solvables + p2;
1160 if (s->repo == installed)
1162 if (s2->repo != installed && MAPTST(&trans->transactsmap, p2))
1164 /* deinstall p before installing p2 */
1165 addedge(od, p2, p, TYPE_CON);
1170 if (s2->repo == installed && MAPTST(&trans->transactsmap, p2))
1172 /* deinstall p2 before installing p */
1173 addedge(od, p, p2, TYPE_CON);
1184 /* break an edge in a cycle */
1186 breakcycle(struct orderdata *od, Id *cycle)
1188 Pool *pool = od->trans->pool;
1189 Id ddegmin, ddegmax, ddeg;
1191 struct _TransactionElement *te;
1194 ddegmin = ddegmax = 0;
1195 for (k = 0; cycle[k + 1]; k += 2)
1197 ddeg = od->edgedata[cycle[k + 1] + 1];
1200 if (!k || ddeg < ddegmin)
1206 if (ddeg == ddegmin)
1208 if (havescripts(pool, od->tes[cycle[l]].p) && !havescripts(pool, od->tes[cycle[k]].p))
1210 /* prefer k, as l comes from a package with contains scriptlets */
1215 /* same edge value, check for prereq */
1219 /* record brkoen cycle starting with the tail */
1220 queue_push(&od->cycles, od->cyclesdata.count); /* offset into data */
1221 queue_push(&od->cycles, k / 2); /* cycle elements */
1222 queue_push(&od->cycles, od->edgedata[cycle[l + 1] + 1]); /* broken edge */
1229 queue_push(&od->cyclesdata, cycle[k]);
1233 queue_push(&od->cyclesdata, 0); /* mark end */
1235 /* break that edge */
1236 od->edgedata[cycle[l + 1] + 1] |= TYPE_BROKEN;
1239 if (ddegmin < TYPE_REQ)
1243 /* cycle recorded, print it */
1244 if (ddegmin >= TYPE_REQ && (ddegmax & TYPE_PREREQ) != 0)
1245 POOL_DEBUG(SAT_DEBUG_STATS, "CRITICAL ");
1246 POOL_DEBUG(SAT_DEBUG_STATS, "cycle: --> ");
1247 for (k = 0; cycle[k + 1]; k += 2)
1249 te = od->tes + cycle[k];
1250 if ((od->edgedata[cycle[k + 1] + 1] & TYPE_BROKEN) != 0)
1251 POOL_DEBUG(SAT_DEBUG_STATS, "%s ##%x##> ", solvid2str(pool, te->p), od->edgedata[cycle[k + 1] + 1]);
1253 POOL_DEBUG(SAT_DEBUG_STATS, "%s --%x--> ", solvid2str(pool, te->p), od->edgedata[cycle[k + 1] + 1]);
1255 POOL_DEBUG(SAT_DEBUG_STATS, "\n");
1259 dump_tes(struct orderdata *od)
1261 Pool *pool = od->trans->pool;
1264 struct _TransactionElement *te, *te2;
1267 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1269 Solvable *s = pool->solvables + te->p;
1270 POOL_DEBUG(SAT_DEBUG_RESULT, "TE %4d: %c%s\n", i, s->repo == pool->installed ? '-' : '+', solvable2str(pool, s));
1271 if (s->repo != pool->installed)
1274 transaction_all_obs_pkgs(od->trans, te->p, &obsq);
1275 for (j = 0; j < obsq.count; j++)
1276 POOL_DEBUG(SAT_DEBUG_RESULT, " -%s\n", solvid2str(pool, obsq.elements[j]));
1278 for (j = te->edges; od->edgedata[j]; j += 2)
1280 te2 = od->tes + od->edgedata[j];
1281 if ((od->edgedata[j + 1] & TYPE_BROKEN) == 0)
1282 POOL_DEBUG(SAT_DEBUG_RESULT, " --%x--> TE %4d: %s\n", od->edgedata[j + 1], od->edgedata[j], solvid2str(pool, te2->p));
1284 POOL_DEBUG(SAT_DEBUG_RESULT, " ##%x##> TE %4d: %s\n", od->edgedata[j + 1], od->edgedata[j], solvid2str(pool, te2->p));
1291 reachable(struct orderdata *od, Id i)
1293 struct _TransactionElement *te = od->tes + i;
1299 for (j = te->edges; (k = od->edgedata[j]) != 0; j += 2)
1301 if ((od->edgedata[j + 1] & TYPE_BROKEN) != 0)
1303 if (!od->tes[k].mark)
1305 if (od->tes[k].mark == 2)
1316 addcycleedges(struct orderdata *od, Id *cycle, Queue *todo)
1319 Transaction *trans = od->trans;
1320 Pool *pool = trans->pool;
1322 struct _TransactionElement *te;
1329 printf("addcycleedges\n");
1330 for (i = 0; (j = cycle[i]) != 0; i++)
1331 printf("cycle %s\n", solvid2str(pool, od->tes[j].p));
1334 /* first add all the tail cycle edges */
1336 /* see what we can reach from the cycle */
1338 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1340 for (i = 0; (j = cycle[i]) != 0; i++)
1342 od->tes[j].mark = -1;
1343 queue_push(todo, j);
1347 i = queue_pop(todo);
1351 te->mark = te->mark < 0 ? 2 : 1;
1352 for (j = te->edges; (k = od->edgedata[j]) != 0; j += 2)
1354 if ((od->edgedata[j + 1] & TYPE_BROKEN) != 0)
1356 if (od->tes[k].mark > 0)
1357 continue; /* no need to visit again */
1358 queue_push(todo, k);
1361 /* now all cycle TEs are marked with 2, all TEs reachable
1362 * from the cycle are marked with 1 */
1364 od->tes[tail].mark = 1; /* no need to add edges */
1366 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1369 continue; /* reachable from cycle */
1370 for (j = te->edges; (k = od->edgedata[j]) != 0; j += 2)
1372 if ((od->edgedata[j + 1] & TYPE_BROKEN) != 0)
1374 if (od->tes[k].mark != 2)
1376 /* We found an edge to the cycle. Add an extra edge to the tail */
1377 /* the TE was not reachable, so we're not creating a new cycle! */
1379 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));
1381 j -= te->edges; /* in case we move */
1382 addteedge(od, i, tail, TYPE_CYCLETAIL);
1384 break; /* one edge is enough */
1389 /* now add all head cycle edges */
1392 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1395 for (i = 0; (j = cycle[i]) != 0; i++)
1398 od->tes[j].mark = 2;
1400 /* first the head to save some time */
1401 te = od->tes + head;
1402 for (j = te->edges; (k = od->edgedata[j]) != 0; j += 2)
1404 if ((od->edgedata[j + 1] & TYPE_BROKEN) != 0)
1406 if (!od->tes[k].mark)
1408 if (od->tes[k].mark == -1)
1409 od->tes[k].mark = -2; /* no need for another edge */
1411 for (i = 0; cycle[i] != 0; i++)
1413 if (cycle[i] == head)
1415 te = od->tes + cycle[i];
1416 for (j = te->edges; (k = od->edgedata[j]) != 0; j += 2)
1418 if ((od->edgedata[j + 1] & TYPE_BROKEN) != 0)
1420 /* see if we can reach a cycle TE from k */
1421 if (!od->tes[k].mark)
1423 if (od->tes[k].mark == -1)
1426 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));
1428 addteedge(od, head, k, TYPE_CYCLEHEAD);
1429 od->tes[k].mark = -2; /* no need to add that one again */
1437 transaction_order(Transaction *trans, int flags)
1439 Pool *pool = trans->pool;
1440 Queue *tr = &trans->steps;
1441 Repo *installed = pool->installed;
1444 int i, j, k, numte, numedge;
1445 struct orderdata od;
1446 struct _TransactionElement *te;
1447 Queue todo, obsq, samerepoq, uninstq;
1448 int cycstart, cycel;
1456 start = now = sat_timems(0);
1457 POOL_DEBUG(SAT_DEBUG_STATS, "ordering transaction\n");
1458 /* free old data if present */
1459 if (trans->orderdata)
1461 struct _TransactionOrderdata *od = trans->orderdata;
1462 od->tes = sat_free(od->tes);
1463 od->invedgedata = sat_free(od->invedgedata);
1464 trans->orderdata = sat_free(trans->orderdata);
1467 /* create a transaction element for every active component */
1469 for (i = 0; i < tr->count; i++)
1471 p = tr->elements[i];
1472 s = pool->solvables + p;
1473 if (installed && s->repo == installed && trans->transaction_installed[p - installed->start])
1477 POOL_DEBUG(SAT_DEBUG_STATS, "transaction elements: %d\n", numte);
1479 return; /* nothing to do... */
1481 numte++; /* leave first one zero */
1482 memset(&od, 0, sizeof(od));
1485 od.tes = sat_calloc(numte, sizeof(*od.tes));
1486 od.edgedata = sat_extend(0, 0, 1, sizeof(Id), EDGEDATA_BLOCK);
1489 queue_init(&od.cycles);
1491 /* initialize TEs */
1492 for (i = 0, te = od.tes + 1; i < tr->count; i++)
1494 p = tr->elements[i];
1495 s = pool->solvables + p;
1496 if (installed && s->repo == installed && trans->transaction_installed[p - installed->start])
1502 /* create dependency graph */
1503 for (i = 0; i < tr->count; i++)
1504 addsolvableedges(&od, pool->solvables + tr->elements[i]);
1508 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1509 for (j = te->edges; od.edgedata[j]; j += 2)
1511 POOL_DEBUG(SAT_DEBUG_STATS, "edges: %d, edge space: %d\n", numedge, od.nedgedata / 2);
1512 POOL_DEBUG(SAT_DEBUG_STATS, "edge creation took %d ms\n", sat_timems(now));
1518 now = sat_timems(0);
1519 /* kill all cycles */
1521 for (i = numte - 1; i > 0; i--)
1522 queue_push(&todo, i);
1526 i = queue_pop(&todo);
1527 /* printf("- look at TE %d\n", i); */
1531 od.tes[i].mark = 2; /* done with that one */
1536 continue; /* already finished before */
1539 int edgestovisit = 0;
1540 /* new node, visit edges */
1541 for (j = te->edges; (k = od.edgedata[j]) != 0; j += 2)
1543 if ((od.edgedata[j + 1] & TYPE_BROKEN) != 0)
1545 if (od.tes[k].mark == 2)
1546 continue; /* no need to visit again */
1547 if (!edgestovisit++)
1548 queue_push(&todo, -i); /* end of edges marker */
1549 queue_push(&todo, k);
1552 te->mark = 2; /* no edges, done with that one */
1554 te->mark = 1; /* under investigation */
1557 /* oh no, we found a cycle */
1558 /* find start of cycle node (<0) */
1559 for (j = todo.count - 1; j >= 0; j--)
1560 if (todo.elements[j] == -i)
1564 /* build te/edge chain */
1566 for (j = k; j < todo.count; j++)
1567 if (todo.elements[j] < 0)
1568 todo.elements[k++] = -todo.elements[j];
1569 cycel = k - cycstart;
1571 /* make room for edges, two extra element for cycle loop + terminating 0 */
1572 while (todo.count < cycstart + 2 * cycel + 2)
1573 queue_push(&todo, 0);
1574 cycle = todo.elements + cycstart;
1575 cycle[cycel] = i; /* close the loop */
1576 cycle[2 * cycel + 1] = 0; /* terminator */
1577 for (k = cycel; k > 0; k--)
1579 cycle[k * 2] = cycle[k];
1580 te = od.tes + cycle[k - 1];
1581 assert(te->mark == 1);
1582 te->mark = 0; /* reset investigation marker */
1583 /* printf("searching for edge from %d to %d\n", cycle[k - 1], cycle[k]); */
1584 for (j = te->edges; od.edgedata[j]; j += 2)
1585 if (od.edgedata[j] == cycle[k])
1587 assert(od.edgedata[j]);
1588 cycle[k * 2 - 1] = j;
1590 /* now cycle looks like this: */
1591 /* te1 edge te2 edge te3 ... teN edge te1 0 */
1592 breakcycle(&od, cycle);
1593 /* restart with start of cycle */
1594 todo.count = cycstart + 1;
1596 POOL_DEBUG(SAT_DEBUG_STATS, "cycles broken: %d\n", od.ncycles);
1597 POOL_DEBUG(SAT_DEBUG_STATS, "cycle breaking took %d ms\n", sat_timems(now));
1599 now = sat_timems(0);
1600 /* now go through all broken cycles and create cycle edges to help
1602 for (i = od.cycles.count - 3; i >= 0; i -= 3)
1604 if (od.cycles.elements[i + 2] >= TYPE_REQ)
1605 addcycleedges(&od, od.cyclesdata.elements + od.cycles.elements[i], &todo);
1607 for (i = od.cycles.count - 3; i >= 0; i -= 3)
1609 if (od.cycles.elements[i + 2] < TYPE_REQ)
1610 addcycleedges(&od, od.cyclesdata.elements + od.cycles.elements[i], &todo);
1612 POOL_DEBUG(SAT_DEBUG_STATS, "cycle edge creation took %d ms\n", sat_timems(now));
1615 /* all edges are finally set up and there are no cycles, now the easy part.
1616 * Create an ordered transaction */
1617 now = sat_timems(0);
1618 /* first invert all edges */
1619 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1620 te->mark = 1; /* term 0 */
1621 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1623 for (j = te->edges; od.edgedata[j]; j += 2)
1625 if ((od.edgedata[j + 1] & TYPE_BROKEN) != 0)
1627 od.tes[od.edgedata[j]].mark++;
1631 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1636 POOL_DEBUG(SAT_DEBUG_STATS, "invedge space: %d\n", j + 1);
1637 od.invedgedata = sat_calloc(j + 1, sizeof(Id));
1638 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1640 for (j = te->edges; od.edgedata[j]; j += 2)
1642 if ((od.edgedata[j + 1] & TYPE_BROKEN) != 0)
1644 od.invedgedata[--od.tes[od.edgedata[j]].mark] = i;
1647 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1648 te->edges = te->mark; /* edges now points into invedgedata */
1649 od.edgedata = sat_free(od.edgedata);
1650 od.nedgedata = j + 1;
1652 /* now the final ordering */
1653 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1655 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1656 for (j = te->edges; od.invedgedata[j]; j++)
1657 od.tes[od.invedgedata[j]].mark++;
1659 queue_init(&samerepoq);
1660 queue_init(&uninstq);
1662 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1665 if (installed && pool->solvables[te->p].repo == installed)
1666 queue_push(&uninstq, i);
1668 queue_push(&todo, i);
1670 assert(todo.count > 0 || uninstq.count > 0);
1671 oldcount = tr->count;
1678 temedianr = sat_calloc(numte, sizeof(Id));
1679 for (i = 1; i < numte; i++)
1681 Solvable *s = pool->solvables + od.tes[i].p;
1682 if (installed && s->repo == installed)
1685 j = solvable_lookup_num(s, SOLVABLE_MEDIANR, 1);
1690 /* select an TE i */
1692 i = queue_shift(&uninstq);
1693 else if (samerepoq.count)
1694 i = queue_shift(&samerepoq);
1695 else if (todo.count)
1697 /* find next repo/media */
1698 for (j = 0; j < todo.count; j++)
1700 if (!j || temedianr[todo.elements[j]] < lastmedia)
1703 lastmedia = temedianr[todo.elements[j]];
1706 lastrepo = pool->solvables[od.tes[todo.elements[i]].p].repo;
1708 /* move all matching TEs to samerepoq */
1709 for (i = j = 0; j < todo.count; j++)
1711 int k = todo.elements[j];
1712 if (temedianr[k] == lastmedia && pool->solvables[od.tes[k].p].repo == lastrepo)
1713 queue_push(&samerepoq, k);
1715 todo.elements[i++] = k;
1719 assert(samerepoq.count);
1720 i = queue_shift(&samerepoq);
1726 queue_push(tr, te->p);
1728 printf("do %s [%d]\n", solvid2str(pool, te->p), temedianr[i]);
1730 s = pool->solvables + te->p;
1731 for (j = te->edges; od.invedgedata[j]; j++)
1733 struct _TransactionElement *te2 = od.tes + od.invedgedata[j];
1734 assert(te2->mark > 0);
1735 if (--te2->mark == 0)
1737 Solvable *s = pool->solvables + te2->p;
1739 printf("free %s [%d]\n", solvid2str(pool, te2->p), temedianr[od.invedgedata[j]]);
1741 if (installed && s->repo == installed)
1742 queue_push(&uninstq, od.invedgedata[j]);
1743 else if (s->repo == lastrepo && temedianr[od.invedgedata[j]] == lastmedia)
1744 queue_push(&samerepoq, od.invedgedata[j]);
1746 queue_push(&todo, od.invedgedata[j]);
1750 sat_free(temedianr);
1752 queue_free(&samerepoq);
1753 queue_free(&uninstq);
1755 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1756 assert(te->mark == 0);
1758 /* add back obsoleted packages */
1759 transaction_add_obsoleted(trans);
1760 assert(tr->count == oldcount);
1762 POOL_DEBUG(SAT_DEBUG_STATS, "creating new transaction took %d ms\n", sat_timems(now));
1763 POOL_DEBUG(SAT_DEBUG_STATS, "transaction ordering took %d ms\n", sat_timems(start));
1765 if ((flags & SOLVER_TRANSACTION_KEEP_ORDERDATA) != 0)
1767 trans->orderdata = sat_calloc(1, sizeof(*trans->orderdata));
1768 trans->orderdata->tes = od.tes;
1769 trans->orderdata->ntes = numte;
1770 trans->orderdata->invedgedata = od.invedgedata;
1771 trans->orderdata->ninvedgedata = od.nedgedata;
1776 sat_free(od.invedgedata);
1782 transaction_order_add_choices(Transaction *trans, Id chosen, Queue *choices)
1785 struct _TransactionOrderdata *od = trans->orderdata;
1786 struct _TransactionElement *te;
1789 return choices->count;
1792 /* initialization step */
1793 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1795 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1797 for (j = te->edges; od->invedgedata[j]; j++)
1798 od->tes[od->invedgedata[j]].mark++;
1800 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1802 queue_push(choices, te->p);
1803 return choices->count;
1805 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1806 if (te->p == chosen)
1809 return choices->count;
1812 /* hey! out-of-order installation! */
1815 for (j = te->edges; od->invedgedata[j]; j++)
1817 te = od->tes + od->invedgedata[j];
1818 assert(te->mark > 0 || te->mark == -1);
1819 if (te->mark > 0 && --te->mark == 0)
1820 queue_push(choices, te->p);
1822 return choices->count;
1826 transaction_add_obsoleted(Transaction *trans)
1828 Pool *pool = trans->pool;
1829 Repo *installed = pool->installed;
1832 int i, j, k, max, oldcount;
1836 if (!installed || !trans->steps.count)
1838 /* calculate upper bound */
1840 FOR_REPO_SOLVABLES(installed, p, s)
1841 if (MAPTST(&trans->transactsmap, p))
1846 steps = &trans->steps;
1847 oldcount = steps->count;
1848 queue_insertn(steps, 0, max);
1851 map_init(&done, installed->end - installed->start);
1853 for (j = 0, i = max; i < steps->count; i++)
1855 p = trans->steps.elements[i];
1856 if (pool->solvables[p].repo == installed)
1858 if (!trans->transaction_installed[p - pool->installed->start])
1859 trans->steps.elements[j++] = p;
1862 trans->steps.elements[j++] = p;
1864 transaction_all_obs_pkgs(trans, p, &obsq);
1865 for (k = 0; k < obsq.count; k++)
1867 p = obsq.elements[k];
1868 assert(p >= installed->start && p < installed->end);
1869 if (MAPTST(&done, p - installed->start))
1871 MAPSET(&done, p - installed->start);
1872 trans->steps.elements[j++] = p;
1876 /* free unneeded space */
1877 queue_truncate(steps, j);
1883 transaction_check_pkg(Transaction *trans, Id tepkg, Id pkg, Map *ins, Map *seen, int onlyprereq, Id noconfpkg, int depth)
1885 Pool *pool = trans->pool;
1890 if (MAPTST(seen, pkg))
1893 s = pool->solvables + pkg;
1895 printf("- %*s%c%s\n", depth * 2, "", s->repo == pool->installed ? '-' : '+', solvable2str(pool, s));
1901 reqp = s->repo->idarraydata + s->requires;
1902 while ((req = *reqp++) != 0)
1904 if (req == SOLVABLE_PREREQMARKER)
1909 if (onlyprereq && !inpre)
1911 if (!strncmp(id2str(pool, req), "rpmlib(", 7))
1914 /* first check kept packages, then freshly installed, then not yet uninstalled */
1915 FOR_PROVIDES(p, pp, req)
1917 if (!MAPTST(ins, p))
1919 if (MAPTST(&trans->transactsmap, p))
1922 transaction_check_pkg(trans, tepkg, p, ins, seen, 0, noconfpkg, depth + 1);
1926 FOR_PROVIDES(p, pp, req)
1928 if (!MAPTST(ins, p))
1930 if (pool->solvables[p].repo == pool->installed)
1933 transaction_check_pkg(trans, tepkg, p, ins, seen, 0, noconfpkg, depth + 1);
1938 FOR_PROVIDES(p, pp, req)
1940 if (!MAPTST(ins, p))
1943 transaction_check_pkg(trans, tepkg, p, ins, seen, 0, noconfpkg, depth + 1);
1948 POOL_DEBUG(SAT_DEBUG_RESULT, " %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));
1955 transaction_check_order(Transaction *trans)
1957 Pool *pool = trans->pool;
1963 POOL_DEBUG(SAT_WARN, "\nchecking transaction order...\n");
1964 map_init(&ins, pool->nsolvables);
1965 map_init(&seen, pool->nsolvables);
1966 if (pool->installed)
1967 FOR_REPO_SOLVABLES(pool->installed, p, s)
1970 for (i = 0; i < trans->steps.count; i++)
1972 p = trans->steps.elements[i];
1973 s = pool->solvables + p;
1974 if (s->repo != pool->installed)
1976 if (s->repo != pool->installed)
1978 if (havescripts(pool, p))
1981 transaction_check_pkg(trans, p, p, &ins, &seen, 1, lastins, 0);
1983 if (s->repo == pool->installed)
1988 POOL_DEBUG(SAT_WARN, "transaction order check done.\n");