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"
29 obsq_sortcmp(const void *ap, const void *bp, void *dp)
33 Solvable *s, *oas, *obs;
44 s = pool->solvables + a;
45 oas = pool->solvables + oa;
46 obs = pool->solvables + ob;
47 if (oas->name != obs->name)
49 if (oas->name == s->name)
51 if (obs->name == s->name)
53 return strcmp(id2str(pool, oas->name), id2str(pool, obs->name));
55 r = evrcmp(pool, oas->evr, obs->evr, EVRCMP_COMPARE);
57 return -r; /* highest version first */
62 transaction_all_obs_pkgs(Transaction *trans, Id p, Queue *pkgs)
64 Pool *pool = trans->pool;
65 Solvable *s = pool->solvables + p;
66 Queue *ti = &trans->transaction_info;
71 if (p <= 0 || !s->repo)
73 if (s->repo == pool->installed)
75 q = trans->transaction_installed[p - pool->installed->start];
83 /* find which packages obsolete us */
84 for (i = 0; i < ti->count; i += 2)
85 if (ti->elements[i + 1] == p)
88 queue_push(pkgs, ti->elements[i]);
92 sat_sort(pkgs->elements, pkgs->count / 2, 2 * sizeof(Id), obsq_sortcmp, pool);
93 for (i = 0; i < pkgs->count; i += 2)
94 pkgs->elements[i / 2] = pkgs->elements[i + 1];
99 /* find the packages we obsolete */
100 for (i = 0; i < ti->count; i += 2)
102 if (ti->elements[i] == p)
103 queue_push(pkgs, ti->elements[i + 1]);
104 else if (pkgs->count)
111 transaction_obs_pkg(Transaction *trans, Id p)
113 Pool *pool = trans->pool;
114 Solvable *s = pool->solvables + p;
118 if (p <= 0 || !s->repo)
120 if (s->repo == pool->installed)
122 p = trans->transaction_installed[p - pool->installed->start];
123 return p < 0 ? -p : p;
125 queue_init_buffer(&ti, tibuf, sizeof(tibuf)/sizeof(*tibuf));
126 transaction_all_obs_pkgs(trans, p, &ti);
127 p = ti.count ? ti.elements[0] : 0;
134 * calculate base type of transaction element
138 transaction_base_type(Transaction *trans, Id p)
140 Pool *pool = trans->pool;
145 if (!MAPTST(&trans->transactsmap, p))
146 return SOLVER_TRANSACTION_IGNORE;
147 p2 = transaction_obs_pkg(trans, p);
148 if (pool->installed && pool->solvables[p].repo == pool->installed)
152 return SOLVER_TRANSACTION_ERASE;
153 s = pool->solvables + p;
154 s2 = pool->solvables + p2;
155 if (s->name == s2->name)
157 if (s->evr == s2->evr && solvable_identical(s, s2))
158 return SOLVER_TRANSACTION_REINSTALLED;
159 r = evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
161 return SOLVER_TRANSACTION_UPGRADED;
163 return SOLVER_TRANSACTION_DOWNGRADED;
164 return SOLVER_TRANSACTION_CHANGED;
166 return SOLVER_TRANSACTION_OBSOLETED;
170 int noobs = trans->noobsmap.size && MAPTST(&trans->noobsmap, p);
172 return p2 ? SOLVER_TRANSACTION_MULTIREINSTALL : SOLVER_TRANSACTION_MULTIINSTALL;
174 return SOLVER_TRANSACTION_INSTALL;
175 s = pool->solvables + p;
176 s2 = pool->solvables + p2;
177 if (s->name == s2->name)
179 if (s->evr == s2->evr && solvable_identical(s, s2))
180 return SOLVER_TRANSACTION_REINSTALL;
181 r = evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
183 return SOLVER_TRANSACTION_UPGRADE;
185 return SOLVER_TRANSACTION_DOWNGRADE;
187 return SOLVER_TRANSACTION_CHANGE;
189 return SOLVER_TRANSACTION_OBSOLETES;
194 * return type of transaction element
196 * filtering is needed if either not all packages are shown
197 * or replaces are not shown, as otherwise parts of the
198 * transaction might not be shown to the user */
201 transaction_type(Transaction *trans, Id p, int mode)
203 Pool *pool = trans->pool;
204 Solvable *s = pool->solvables + p;
210 return SOLVER_TRANSACTION_IGNORE;
212 type = transaction_base_type(trans, p);
214 if (type == SOLVER_TRANSACTION_IGNORE)
215 return SOLVER_TRANSACTION_IGNORE; /* not part of the transaction */
217 if ((mode & SOLVER_TRANSACTION_RPM_ONLY) != 0)
219 /* application wants to know what to feed to rpm */
220 if (type == SOLVER_TRANSACTION_ERASE || type == SOLVER_TRANSACTION_INSTALL || type == SOLVER_TRANSACTION_MULTIINSTALL)
222 if (s->repo == pool->installed)
223 return SOLVER_TRANSACTION_IGNORE; /* ignore as we're being obsoleted */
224 if (type == SOLVER_TRANSACTION_MULTIREINSTALL)
225 return SOLVER_TRANSACTION_MULTIINSTALL;
226 return SOLVER_TRANSACTION_INSTALL;
229 if ((mode & SOLVER_TRANSACTION_SHOW_MULTIINSTALL) == 0)
231 /* application wants to make no difference between install
232 * and multiinstall */
233 if (type == SOLVER_TRANSACTION_MULTIINSTALL)
234 type = SOLVER_TRANSACTION_INSTALL;
235 if (type == SOLVER_TRANSACTION_MULTIREINSTALL)
236 type = SOLVER_TRANSACTION_REINSTALL;
239 if ((mode & SOLVER_TRANSACTION_CHANGE_IS_REINSTALL))
241 /* application wants to make no difference between change
243 if (type == SOLVER_TRANSACTION_CHANGED)
244 type = SOLVER_TRANSACTION_REINSTALLED;
245 else if (type == SOLVER_TRANSACTION_CHANGE)
246 type = SOLVER_TRANSACTION_REINSTALL;
249 if (type == SOLVER_TRANSACTION_ERASE || type == SOLVER_TRANSACTION_INSTALL || type == SOLVER_TRANSACTION_MULTIINSTALL)
252 if (s->repo == pool->installed && (mode & SOLVER_TRANSACTION_SHOW_ACTIVE) == 0)
254 /* erase element and we're showing the passive side */
255 if ((mode & SOLVER_TRANSACTION_SHOW_OBSOLETES) == 0 && type == SOLVER_TRANSACTION_OBSOLETED)
256 type = SOLVER_TRANSACTION_ERASE;
259 if (s->repo != pool->installed && (mode & SOLVER_TRANSACTION_SHOW_ACTIVE) != 0)
261 /* install element and we're showing the active side */
262 if ((mode & SOLVER_TRANSACTION_SHOW_OBSOLETES) == 0 && type == SOLVER_TRANSACTION_OBSOLETES)
263 type = SOLVER_TRANSACTION_INSTALL;
267 /* the element doesn't match the show mode */
269 /* if we're showing all references, we can ignore this package */
270 if ((mode & (SOLVER_TRANSACTION_SHOW_ALL|SOLVER_TRANSACTION_SHOW_OBSOLETES)) == (SOLVER_TRANSACTION_SHOW_ALL|SOLVER_TRANSACTION_SHOW_OBSOLETES))
271 return SOLVER_TRANSACTION_IGNORE;
273 /* we're not showing all refs. check if some other package
274 * references us. If yes, it's safe to ignore this package,
275 * otherwise we need to map the type */
277 /* most of the time there's only one reference, so check it first */
278 q = transaction_obs_pkg(trans, p);
280 if ((mode & SOLVER_TRANSACTION_SHOW_OBSOLETES) == 0)
282 Solvable *sq = pool->solvables + q;
283 if (sq->name != s->name)
285 /* it's a replace but we're not showing replaces. map type. */
286 if (s->repo == pool->installed)
287 return SOLVER_TRANSACTION_ERASE;
288 else if (type == SOLVER_TRANSACTION_MULTIREINSTALL)
289 return SOLVER_TRANSACTION_MULTIINSTALL;
291 return SOLVER_TRANSACTION_INSTALL;
295 /* if there's a match, p will be shown when q
297 if (transaction_obs_pkg(trans, q) == p)
298 return SOLVER_TRANSACTION_IGNORE;
300 /* too bad, a miss. check em all */
303 transaction_all_obs_pkgs(trans, p, &oq);
304 for (i = 0; i < oq.count; i++)
307 if ((mode & SOLVER_TRANSACTION_SHOW_OBSOLETES) == 0)
309 Solvable *sq = pool->solvables + q;
310 if (sq->name != s->name)
313 /* check if we are referenced? */
314 if ((mode & SOLVER_TRANSACTION_SHOW_ALL) != 0)
316 transaction_all_obs_pkgs(trans, q, &rq);
317 for (j = 0; j < rq.count; j++)
318 if (rq.elements[j] == p)
326 else if (transaction_obs_pkg(trans, q) == p)
337 /* we're not referenced. map type */
338 if (s->repo == pool->installed)
339 return SOLVER_TRANSACTION_ERASE;
340 else if (type == SOLVER_TRANSACTION_MULTIREINSTALL)
341 return SOLVER_TRANSACTION_MULTIINSTALL;
343 return SOLVER_TRANSACTION_INSTALL;
345 /* there was a ref, so p is shown with some other package */
346 return SOLVER_TRANSACTION_IGNORE;
352 classify_cmp(const void *ap, const void *bp, void *dp)
354 Transaction *trans = dp;
355 Pool *pool = trans->pool;
365 return a[2] && b[2] ? strcmp(id2str(pool, a[2]), id2str(pool, b[2])) : r;
368 return a[3] && b[3] ? strcmp(id2str(pool, a[3]), id2str(pool, b[3])) : r;
373 classify_cmp_pkgs(const void *ap, const void *bp, void *dp)
375 Transaction *trans = dp;
376 Pool *pool = trans->pool;
381 sa = pool->solvables + a;
382 sb = pool->solvables + b;
383 if (sa->name != sb->name)
384 return strcmp(id2str(pool, sa->name), id2str(pool, sb->name));
385 if (sa->evr != sb->evr)
387 int r = evrcmp(pool, sa->evr, sb->evr, EVRCMP_COMPARE);
395 transaction_classify(Transaction *trans, int mode, Queue *classes)
397 Pool *pool = trans->pool;
398 int ntypes[SOLVER_TRANSACTION_MAXTYPE + 1];
400 Id v, vq, type, p, q;
403 queue_empty(classes);
404 memset(ntypes, 0, sizeof(ntypes));
405 /* go through transaction and classify each step */
406 for (i = 0; i < trans->steps.count; i++)
408 p = trans->steps.elements[i];
409 s = pool->solvables + p;
410 type = transaction_type(trans, p, mode);
412 if (!pool->installed || s->repo != pool->installed)
414 /* look at arch/vendor changes */
415 q = transaction_obs_pkg(trans, p);
418 sq = pool->solvables + q;
424 if ((mode & SOLVER_TRANSACTION_MERGE_ARCHCHANGES) != 0)
426 for (j = 0; j < classes->count; j += 4)
427 if (classes->elements[j] == SOLVER_TRANSACTION_ARCHCHANGE && classes->elements[j + 2] == v && classes->elements[j + 3] == vq)
429 if (j == classes->count)
431 queue_push(classes, SOLVER_TRANSACTION_ARCHCHANGE);
432 queue_push(classes, 1);
433 queue_push(classes, v);
434 queue_push(classes, vq);
437 classes->elements[j + 1]++;
440 v = s->vendor ? s->vendor : 1;
441 vq = sq->vendor ? sq->vendor : 1;
444 if ((mode & SOLVER_TRANSACTION_MERGE_VENDORCHANGES) != 0)
446 for (j = 0; j < classes->count; j += 4)
447 if (classes->elements[j] == SOLVER_TRANSACTION_VENDORCHANGE && classes->elements[j + 2] == v && classes->elements[j + 3] == vq)
449 if (j == classes->count)
451 queue_push(classes, SOLVER_TRANSACTION_VENDORCHANGE);
452 queue_push(classes, 1);
453 queue_push(classes, v);
454 queue_push(classes, vq);
457 classes->elements[j + 1]++;
460 /* now sort all vendor/arch changes */
461 if (classes->count > 4)
462 sat_sort(classes->elements, classes->count / 4, 4 * sizeof(Id), classify_cmp, trans);
463 /* finally add all classes. put erases last */
464 i = SOLVER_TRANSACTION_ERASE;
467 queue_unshift(classes, 0);
468 queue_unshift(classes, 0);
469 queue_unshift(classes, ntypes[i]);
470 queue_unshift(classes, i);
472 for (i = SOLVER_TRANSACTION_MAXTYPE; i > 0; i--)
476 if (i == SOLVER_TRANSACTION_ERASE)
478 queue_unshift(classes, 0);
479 queue_unshift(classes, 0);
480 queue_unshift(classes, ntypes[i]);
481 queue_unshift(classes, i);
486 transaction_classify_pkgs(Transaction *trans, int mode, Id class, Id from, Id to, Queue *pkgs)
488 Pool *pool = trans->pool;
494 for (i = 0; i < trans->steps.count; i++)
496 p = trans->steps.elements[i];
497 s = pool->solvables + p;
498 if (class <= SOLVER_TRANSACTION_MAXTYPE)
500 type = transaction_type(trans, p, mode);
505 if (!pool->installed || s->repo != pool->installed)
507 q = transaction_obs_pkg(trans, p);
510 sq = pool->solvables + q;
511 if (class == SOLVER_TRANSACTION_ARCHCHANGE)
513 if ((!from && !to) || (s->arch == from && sq->arch == to))
517 if (class == SOLVER_TRANSACTION_VENDORCHANGE)
519 Id v = s->vendor ? s->vendor : 1;
520 Id vq = sq->vendor ? sq->vendor : 1;
521 if ((!from && !to) || (v == from && vq == to))
527 sat_sort(pkgs->elements, pkgs->count, sizeof(Id), classify_cmp_pkgs, trans);
531 create_transaction_info(Transaction *trans, Queue *decisionq)
533 Pool *pool = trans->pool;
534 Queue *ti = &trans->transaction_info;
535 Repo *installed = pool->installed;
541 trans->transaction_installed = sat_free(trans->transaction_installed);
543 return; /* no info needed */
544 for (i = 0; i < decisionq->count; i++)
546 p = decisionq->elements[i];
547 if (p <= 0 || p == SYSTEMSOLVABLE)
549 s = pool->solvables + p;
550 if (!s->repo || s->repo == installed)
552 noobs = trans->noobsmap.size && MAPTST(&trans->noobsmap, p);
553 FOR_PROVIDES(p2, pp2, s->name)
555 if (!MAPTST(&trans->transactsmap, p2))
557 s2 = pool->solvables + p2;
558 if (s2->repo != installed)
560 if (noobs && (s->name != s2->name || s->evr != s2->evr || s->arch != s2->arch))
562 if (!pool->implicitobsoleteusesprovides && s->name != s2->name)
564 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, s2))
569 if (s->obsoletes && !noobs)
571 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
572 while ((obs = *obsp++) != 0)
574 FOR_PROVIDES(p2, pp2, obs)
576 s2 = pool->solvables + p2;
577 if (s2->repo != installed)
579 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p2, obs))
581 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, s2))
589 sat_sort(ti->elements, ti->count / 2, 2 * sizeof(Id), obsq_sortcmp, pool);
591 for (i = j = 0; i < ti->count; i += 2)
593 if (j && ti->elements[i] == ti->elements[j - 2] && ti->elements[i + 1] == ti->elements[j - 1])
595 ti->elements[j++] = ti->elements[i];
596 ti->elements[j++] = ti->elements[i + 1];
600 /* create transaction_installed helper */
601 trans->transaction_installed = sat_calloc(installed->end - installed->start, sizeof(Id));
602 for (i = 0; i < ti->count; i += 2)
604 j = ti->elements[i + 1] - installed->start;
605 if (!trans->transaction_installed[j])
606 trans->transaction_installed[j] = ti->elements[i];
609 /* more than one package obsoletes us. compare */
611 if (trans->transaction_installed[j] > 0)
612 trans->transaction_installed[j] = -trans->transaction_installed[j];
613 q[0] = q[2] = ti->elements[i + 1];
614 q[1] = ti->elements[i];
615 q[3] = -trans->transaction_installed[j];
616 if (obsq_sortcmp(q, q + 2, pool) < 0)
617 trans->transaction_installed[j] = -ti->elements[i];
624 transaction_calculate(Transaction *trans, Queue *decisionq, Map *noobsmap)
626 Pool *pool = trans->pool;
627 Repo *installed = pool->installed;
632 if (noobsmap && !noobsmap->size)
633 noobsmap = 0; /* ignore empty map */
634 queue_empty(&trans->steps);
635 map_init(&trans->transactsmap, pool->nsolvables);
637 for (i = 0; i < decisionq->count; i++)
639 p = decisionq->elements[i];
640 s = pool->solvables + (p > 0 ? p : -p);
643 if (installed && s->repo == installed && p < 0)
644 MAPSET(&trans->transactsmap, -p);
645 if ((!installed || s->repo != installed) && p > 0)
647 const char *n = id2str(pool, s->name);
648 if (!strncmp(n, "patch:", 6))
650 if (!strncmp(n, "pattern:", 8))
652 MAPSET(&trans->transactsmap, p);
653 if (noobsmap && MAPTST(noobsmap, p))
657 MAPCLR(&trans->transactsmap, SYSTEMSOLVABLE);
659 map_init_clone(&trans->noobsmap, noobsmap);
661 create_transaction_info(trans, decisionq);
665 FOR_REPO_SOLVABLES(installed, p, s)
667 if (MAPTST(&trans->transactsmap, p))
668 queue_push(&trans->steps, p);
671 for (i = 0; i < decisionq->count; i++)
673 p = decisionq->elements[i];
674 if (p > 0 && MAPTST(&trans->transactsmap, p))
675 queue_push(&trans->steps, p);
680 transaction_installedresult(Transaction *trans, Queue *installedq)
682 Pool *pool = trans->pool;
683 Repo *installed = pool->installed;
688 queue_empty(installedq);
689 /* first the new installs, than the kept packages */
690 for (i = 0; i < trans->steps.count; i++)
692 p = trans->steps.elements[i];
693 s = pool->solvables + p;
694 if (installed && s->repo == installed)
696 queue_push(installedq, p);
698 cutoff = installedq->count;
701 FOR_REPO_SOLVABLES(installed, p, s)
702 if (!MAPTST(&trans->transactsmap, p))
703 queue_push(installedq, p);
708 struct _TransactionElement {
709 Id p; /* solvable id */
710 Id edges; /* pointer into edges data */
714 struct _TransactionOrderdata {
715 struct _TransactionElement *tes;
721 #define TYPE_BROKEN (1<<0)
722 #define TYPE_CON (1<<1)
724 #define TYPE_REQ_P (1<<2)
725 #define TYPE_PREREQ_P (1<<3)
727 #define TYPE_REQ (1<<4)
728 #define TYPE_PREREQ (1<<5)
730 #define TYPE_CYCLETAIL (1<<16)
731 #define TYPE_CYCLEHEAD (1<<17)
733 #define EDGEDATA_BLOCK 127
736 transaction_init(Transaction *trans, Pool *pool)
738 memset(trans, 0, sizeof(*trans));
743 transaction_init_clone(Transaction *trans, Transaction *srctrans)
745 memset(trans, 0, sizeof(*trans));
746 trans->pool = srctrans->pool;
747 queue_init_clone(&trans->steps, &srctrans->steps);
748 queue_init_clone(&trans->transaction_info, &srctrans->transaction_info);
749 if (srctrans->transaction_installed)
751 Repo *installed = srctrans->pool->installed;
752 trans->transaction_installed = sat_calloc(installed->end - installed->start, sizeof(Id));
753 memcpy(trans->transaction_installed, srctrans->transaction_installed, (installed->end - installed->start) * sizeof(Id));
755 map_init_clone(&trans->transactsmap, &srctrans->transactsmap);
756 map_init_clone(&trans->noobsmap, &srctrans->noobsmap);
757 if (srctrans->orderdata)
759 struct _TransactionOrderdata *od = srctrans->orderdata;
760 trans->orderdata = sat_calloc(1, sizeof(*trans->orderdata));
761 trans->orderdata->tes = sat_malloc2(od->ntes, sizeof(*od->tes));
762 memcpy(trans->orderdata->tes, od->tes, od->ntes * sizeof(*od->tes));
763 trans->orderdata->ntes = od->ntes;
764 trans->orderdata->invedgedata = sat_malloc2(od->ninvedgedata, sizeof(Id));
765 memcpy(trans->orderdata->invedgedata, od->invedgedata, od->ninvedgedata * sizeof(Id));
766 trans->orderdata->ninvedgedata = od->ninvedgedata;
771 transaction_free(Transaction *trans)
773 queue_free(&trans->steps);
774 queue_free(&trans->transaction_info);
775 trans->transaction_installed = sat_free(trans->transaction_installed);
776 map_free(&trans->transactsmap);
777 map_free(&trans->noobsmap);
778 transaction_free_orderdata(trans);
782 transaction_free_orderdata(Transaction *trans)
784 if (trans->orderdata)
786 struct _TransactionOrderdata *od = trans->orderdata;
787 od->tes = sat_free(od->tes);
788 od->invedgedata = sat_free(od->invedgedata);
789 trans->orderdata = sat_free(trans->orderdata);
795 struct _TransactionElement *tes;
807 addteedge(struct orderdata *od, int from, int to, int type)
810 struct _TransactionElement *te;
815 /* printf("edge %d(%s) -> %d(%s) type %x\n", from, solvid2str(pool, od->tes[from].p), to, solvid2str(pool, od->tes[to].p), type); */
818 for (i = te->edges; od->edgedata[i]; i += 2)
819 if (od->edgedata[i] == to)
821 /* test of brokenness */
822 if (type == TYPE_BROKEN)
823 return od->edgedata[i] && (od->edgedata[i + 1] & TYPE_BROKEN) != 0 ? 1 : 0;
826 od->edgedata[i + 1] |= type;
829 if (i + 1 == od->nedgedata)
831 /* printf("tail add %d\n", i - te->edges); */
834 od->edgedata = sat_extend(od->edgedata, od->nedgedata, 3, sizeof(Id), EDGEDATA_BLOCK);
838 /* printf("extend %d\n", i - te->edges); */
839 od->edgedata = sat_extend(od->edgedata, od->nedgedata, 3 + (i - te->edges), sizeof(Id), EDGEDATA_BLOCK);
841 memcpy(od->edgedata + od->nedgedata, od->edgedata + te->edges, sizeof(Id) * (i - te->edges));
842 i = od->nedgedata + (i - te->edges);
843 te->edges = od->nedgedata;
845 od->edgedata[i] = to;
846 od->edgedata[i + 1] = type;
847 od->edgedata[i + 2] = 0; /* end marker */
848 od->nedgedata = i + 3;
853 addedge(struct orderdata *od, Id from, Id to, int type)
855 Transaction *trans = od->trans;
856 Pool *pool = trans->pool;
858 struct _TransactionElement *te;
861 // printf("addedge %d %d type %d\n", from, to, type);
862 s = pool->solvables + from;
863 if (s->repo == pool->installed && trans->transaction_installed[from - pool->installed->start])
865 /* obsolete, map to install */
866 if (trans->transaction_installed[from - pool->installed->start] > 0)
867 from = trans->transaction_installed[from - pool->installed->start];
874 queue_init_buffer(&ti, tibuf, sizeof(tibuf)/sizeof(*tibuf));
875 transaction_all_obs_pkgs(trans, from, &ti);
876 for (i = 0; i < ti.count; i++)
877 ret |= addedge(od, ti.elements[i], to, type);
882 s = pool->solvables + to;
883 if (s->repo == pool->installed && trans->transaction_installed[to - pool->installed->start])
885 /* obsolete, map to install */
886 if (trans->transaction_installed[to - pool->installed->start] > 0)
887 to = trans->transaction_installed[to - pool->installed->start];
894 queue_init_buffer(&ti, tibuf, sizeof(tibuf)/sizeof(*tibuf));
895 transaction_all_obs_pkgs(trans, to, &ti);
896 for (i = 0; i < ti.count; i++)
897 ret |= addedge(od, from, ti.elements[i], type);
903 /* map from/to to te numbers */
904 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
911 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
917 return addteedge(od, i, to, type);
922 havechoice(struct orderdata *od, Id p, Id q1, Id q2)
924 Transaction *trans = od->trans;
925 Pool *pool = trans->pool;
926 Id ti1buf[5], ti2buf[5];
930 /* both q1 and q2 are uninstalls. check if their TEs intersect */
931 /* common case: just one TE for both packages */
933 printf("havechoice %d %d %d\n", p, q1, q2);
935 if (trans->transaction_installed[q1 - pool->installed->start] == 0)
937 if (trans->transaction_installed[q2 - pool->installed->start] == 0)
939 if (trans->transaction_installed[q1 - pool->installed->start] == trans->transaction_installed[q2 - pool->installed->start])
941 if (trans->transaction_installed[q1 - pool->installed->start] > 0 && trans->transaction_installed[q2 - pool->installed->start] > 0)
943 queue_init_buffer(&ti1, ti1buf, sizeof(ti1buf)/sizeof(*ti1buf));
944 transaction_all_obs_pkgs(trans, q1, &ti1);
945 queue_init_buffer(&ti2, ti2buf, sizeof(ti2buf)/sizeof(*ti2buf));
946 transaction_all_obs_pkgs(trans, q2, &ti2);
947 for (i = 0; i < ti1.count; i++)
948 for (j = 0; j < ti2.count; j++)
949 if (ti1.elements[i] == ti2.elements[j])
951 /* found a common edge */
963 havescripts(Pool *pool, Id solvid)
965 Solvable *s = pool->solvables + solvid;
971 reqp = s->repo->idarraydata + s->requires;
972 while ((req = *reqp++) != 0)
974 if (req == SOLVABLE_PREREQMARKER)
981 dep = id2str(pool, req);
982 if (*dep == '/' && strcmp(dep, "/sbin/ldconfig") != 0)
990 addsolvableedges(struct orderdata *od, Solvable *s)
992 Transaction *trans = od->trans;
993 Pool *pool = trans->pool;
994 Id req, *reqp, con, *conp;
996 int i, j, pre, numins;
997 Repo *installed = pool->installed;
1003 printf("addsolvableedges %s\n", solvable2str(pool, s));
1005 p = s - pool->solvables;
1009 reqp = s->repo->idarraydata + s->requires;
1011 while ((req = *reqp++) != 0)
1013 if (req == SOLVABLE_PREREQMARKER)
1019 if (pre != TYPE_PREREQ && installed && s->repo == installed)
1021 /* ignore normal requires if we're getting obsoleted */
1022 if (trans->transaction_installed[p - pool->installed->start])
1027 numins = 0; /* number of packages to be installed providing it */
1028 provbyinst = 0; /* provided by kept package */
1029 FOR_PROVIDES(p2, pp2, req)
1031 s2 = pool->solvables + p2;
1034 reqq.count = 0; /* self provides */
1037 if (s2->repo == installed && !MAPTST(&trans->transactsmap, p2))
1041 printf("IGNORE inst provides %s by %s\n", dep2str(pool, req), solvable2str(pool, s2));
1042 reqq.count = 0; /* provided by package that stays installed */
1048 if (s2->repo != installed && !MAPTST(&trans->transactsmap, p2))
1049 continue; /* package stays uninstalled */
1051 if (s->repo == installed)
1053 /* s gets uninstalled */
1054 queue_pushunique(&reqq, p2);
1055 if (s2->repo != installed)
1060 if (s2->repo == installed)
1061 continue; /* s2 gets uninstalled */
1062 queue_pushunique(&reqq, p2);
1067 /* prune to harmless ->inst edges */
1068 for (i = j = 0; i < reqq.count; i++)
1069 if (pool->solvables[reqq.elements[i]].repo != installed)
1070 reqq.elements[j++] = reqq.elements[i];
1074 if (numins && reqq.count)
1076 if (s->repo == installed)
1078 for (i = 0; i < reqq.count; i++)
1080 if (pool->solvables[reqq.elements[i]].repo == installed)
1082 for (j = 0; j < reqq.count; j++)
1084 if (pool->solvables[reqq.elements[j]].repo != installed)
1086 if (trans->transaction_installed[reqq.elements[i] - pool->installed->start] == reqq.elements[j])
1087 continue; /* no self edge */
1089 printf("add interrreq uninst->inst edge (%s -> %s -> %s)\n", solvid2str(pool, reqq.elements[i]), dep2str(pool, req), solvid2str(pool, reqq.elements[j]));
1091 addedge(od, reqq.elements[i], reqq.elements[j], pre == TYPE_PREREQ ? TYPE_PREREQ_P : TYPE_REQ_P);
1097 /* no mixed types, remove all deps on uninstalls */
1098 for (i = j = 0; i < reqq.count; i++)
1099 if (pool->solvables[reqq.elements[i]].repo != installed)
1100 reqq.elements[j++] = reqq.elements[i];
1105 for (i = 0; i < reqq.count; i++)
1108 p2 = reqq.elements[i];
1109 if (pool->solvables[p2].repo != installed)
1111 /* all elements of reqq are installs, thus have different TEs */
1112 choice = reqq.count - 1;
1113 if (pool->solvables[p].repo != installed)
1116 printf("add inst->inst edge choice %d (%s -> %s -> %s)\n", choice, solvid2str(pool, p), dep2str(pool, req), solvid2str(pool, p2));
1118 addedge(od, p, p2, pre);
1123 printf("add uninst->inst edge choice %d (%s -> %s -> %s)\n", choice, solvid2str(pool, p), dep2str(pool, req), solvid2str(pool, p2));
1125 addedge(od, p, p2, pre == TYPE_PREREQ ? TYPE_PREREQ_P : TYPE_REQ_P);
1130 if (s->repo != installed)
1131 continue; /* no inst->uninst edges, please! */
1133 /* uninst -> uninst edge. Those make trouble. Only add if we must */
1134 if (trans->transaction_installed[p - installed->start] && !havescripts(pool, p))
1136 /* p is obsoleted by another package and has no scripts */
1137 /* we assume that the obsoletor is good enough to replace p */
1142 for (j = 0; j < reqq.count; j++)
1146 if (havechoice(od, p, reqq.elements[i], reqq.elements[j]))
1151 printf("add uninst->uninst edge choice %d (%s -> %s -> %s)\n", choice, solvid2str(pool, p), dep2str(pool, req), solvid2str(pool, p2));
1153 addedge(od, p2, p, pre == TYPE_PREREQ ? TYPE_PREREQ_P : TYPE_REQ_P);
1160 conp = s->repo->idarraydata + s->conflicts;
1161 while ((con = *conp++) != 0)
1163 FOR_PROVIDES(p2, pp2, con)
1167 s2 = pool->solvables + p2;
1170 if (s->repo == installed)
1172 if (s2->repo != installed && MAPTST(&trans->transactsmap, p2))
1174 /* deinstall p before installing p2 */
1175 addedge(od, p2, p, TYPE_CON);
1180 if (s2->repo == installed && MAPTST(&trans->transactsmap, p2))
1182 /* deinstall p2 before installing p */
1183 addedge(od, p, p2, TYPE_CON);
1194 /* break an edge in a cycle */
1196 breakcycle(struct orderdata *od, Id *cycle)
1198 Pool *pool = od->trans->pool;
1199 Id ddegmin, ddegmax, ddeg;
1201 struct _TransactionElement *te;
1204 ddegmin = ddegmax = 0;
1205 for (k = 0; cycle[k + 1]; k += 2)
1207 ddeg = od->edgedata[cycle[k + 1] + 1];
1210 if (!k || ddeg < ddegmin)
1216 if (ddeg == ddegmin)
1218 if (havescripts(pool, od->tes[cycle[l]].p) && !havescripts(pool, od->tes[cycle[k]].p))
1220 /* prefer k, as l comes from a package with contains scriptlets */
1225 /* same edge value, check for prereq */
1229 /* record brkoen cycle starting with the tail */
1230 queue_push(&od->cycles, od->cyclesdata.count); /* offset into data */
1231 queue_push(&od->cycles, k / 2); /* cycle elements */
1232 queue_push(&od->cycles, od->edgedata[cycle[l + 1] + 1]); /* broken edge */
1239 queue_push(&od->cyclesdata, cycle[k]);
1243 queue_push(&od->cyclesdata, 0); /* mark end */
1245 /* break that edge */
1246 od->edgedata[cycle[l + 1] + 1] |= TYPE_BROKEN;
1249 if (ddegmin < TYPE_REQ)
1253 /* cycle recorded, print it */
1254 if (ddegmin >= TYPE_REQ && (ddegmax & TYPE_PREREQ) != 0)
1255 POOL_DEBUG(SAT_DEBUG_STATS, "CRITICAL ");
1256 POOL_DEBUG(SAT_DEBUG_STATS, "cycle: --> ");
1257 for (k = 0; cycle[k + 1]; k += 2)
1259 te = od->tes + cycle[k];
1260 if ((od->edgedata[cycle[k + 1] + 1] & TYPE_BROKEN) != 0)
1261 POOL_DEBUG(SAT_DEBUG_STATS, "%s ##%x##> ", solvid2str(pool, te->p), od->edgedata[cycle[k + 1] + 1]);
1263 POOL_DEBUG(SAT_DEBUG_STATS, "%s --%x--> ", solvid2str(pool, te->p), od->edgedata[cycle[k + 1] + 1]);
1265 POOL_DEBUG(SAT_DEBUG_STATS, "\n");
1269 dump_tes(struct orderdata *od)
1271 Pool *pool = od->trans->pool;
1274 struct _TransactionElement *te, *te2;
1277 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1279 Solvable *s = pool->solvables + te->p;
1280 POOL_DEBUG(SAT_DEBUG_RESULT, "TE %4d: %c%s\n", i, s->repo == pool->installed ? '-' : '+', solvable2str(pool, s));
1281 if (s->repo != pool->installed)
1284 transaction_all_obs_pkgs(od->trans, te->p, &obsq);
1285 for (j = 0; j < obsq.count; j++)
1286 POOL_DEBUG(SAT_DEBUG_RESULT, " -%s\n", solvid2str(pool, obsq.elements[j]));
1288 for (j = te->edges; od->edgedata[j]; j += 2)
1290 te2 = od->tes + od->edgedata[j];
1291 if ((od->edgedata[j + 1] & TYPE_BROKEN) == 0)
1292 POOL_DEBUG(SAT_DEBUG_RESULT, " --%x--> TE %4d: %s\n", od->edgedata[j + 1], od->edgedata[j], solvid2str(pool, te2->p));
1294 POOL_DEBUG(SAT_DEBUG_RESULT, " ##%x##> TE %4d: %s\n", od->edgedata[j + 1], od->edgedata[j], solvid2str(pool, te2->p));
1301 reachable(struct orderdata *od, Id i)
1303 struct _TransactionElement *te = od->tes + i;
1309 for (j = te->edges; (k = od->edgedata[j]) != 0; j += 2)
1311 if ((od->edgedata[j + 1] & TYPE_BROKEN) != 0)
1313 if (!od->tes[k].mark)
1315 if (od->tes[k].mark == 2)
1326 addcycleedges(struct orderdata *od, Id *cycle, Queue *todo)
1329 Transaction *trans = od->trans;
1330 Pool *pool = trans->pool;
1332 struct _TransactionElement *te;
1339 printf("addcycleedges\n");
1340 for (i = 0; (j = cycle[i]) != 0; i++)
1341 printf("cycle %s\n", solvid2str(pool, od->tes[j].p));
1344 /* first add all the tail cycle edges */
1346 /* see what we can reach from the cycle */
1348 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1350 for (i = 0; (j = cycle[i]) != 0; i++)
1352 od->tes[j].mark = -1;
1353 queue_push(todo, j);
1357 i = queue_pop(todo);
1361 te->mark = te->mark < 0 ? 2 : 1;
1362 for (j = te->edges; (k = od->edgedata[j]) != 0; j += 2)
1364 if ((od->edgedata[j + 1] & TYPE_BROKEN) != 0)
1366 if (od->tes[k].mark > 0)
1367 continue; /* no need to visit again */
1368 queue_push(todo, k);
1371 /* now all cycle TEs are marked with 2, all TEs reachable
1372 * from the cycle are marked with 1 */
1374 od->tes[tail].mark = 1; /* no need to add edges */
1376 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1379 continue; /* reachable from cycle */
1380 for (j = te->edges; (k = od->edgedata[j]) != 0; j += 2)
1382 if ((od->edgedata[j + 1] & TYPE_BROKEN) != 0)
1384 if (od->tes[k].mark != 2)
1386 /* We found an edge to the cycle. Add an extra edge to the tail */
1387 /* the TE was not reachable, so we're not creating a new cycle! */
1389 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));
1391 j -= te->edges; /* in case we move */
1392 addteedge(od, i, tail, TYPE_CYCLETAIL);
1394 break; /* one edge is enough */
1399 /* now add all head cycle edges */
1402 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1405 for (i = 0; (j = cycle[i]) != 0; i++)
1408 od->tes[j].mark = 2;
1410 /* first the head to save some time */
1411 te = od->tes + head;
1412 for (j = te->edges; (k = od->edgedata[j]) != 0; j += 2)
1414 if ((od->edgedata[j + 1] & TYPE_BROKEN) != 0)
1416 if (!od->tes[k].mark)
1418 if (od->tes[k].mark == -1)
1419 od->tes[k].mark = -2; /* no need for another edge */
1421 for (i = 0; cycle[i] != 0; i++)
1423 if (cycle[i] == head)
1425 te = od->tes + cycle[i];
1426 for (j = te->edges; (k = od->edgedata[j]) != 0; j += 2)
1428 if ((od->edgedata[j + 1] & TYPE_BROKEN) != 0)
1430 /* see if we can reach a cycle TE from k */
1431 if (!od->tes[k].mark)
1433 if (od->tes[k].mark == -1)
1436 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));
1438 addteedge(od, head, k, TYPE_CYCLEHEAD);
1439 od->tes[k].mark = -2; /* no need to add that one again */
1447 transaction_order(Transaction *trans, int flags)
1449 Pool *pool = trans->pool;
1450 Queue *tr = &trans->steps;
1451 Repo *installed = pool->installed;
1454 int i, j, k, numte, numedge;
1455 struct orderdata od;
1456 struct _TransactionElement *te;
1457 Queue todo, obsq, samerepoq, uninstq;
1458 int cycstart, cycel;
1466 start = now = sat_timems(0);
1467 POOL_DEBUG(SAT_DEBUG_STATS, "ordering transaction\n");
1468 /* free old data if present */
1469 if (trans->orderdata)
1471 struct _TransactionOrderdata *od = trans->orderdata;
1472 od->tes = sat_free(od->tes);
1473 od->invedgedata = sat_free(od->invedgedata);
1474 trans->orderdata = sat_free(trans->orderdata);
1477 /* create a transaction element for every active component */
1479 for (i = 0; i < tr->count; i++)
1481 p = tr->elements[i];
1482 s = pool->solvables + p;
1483 if (installed && s->repo == installed && trans->transaction_installed[p - installed->start])
1487 POOL_DEBUG(SAT_DEBUG_STATS, "transaction elements: %d\n", numte);
1489 return; /* nothing to do... */
1491 numte++; /* leave first one zero */
1492 memset(&od, 0, sizeof(od));
1495 od.tes = sat_calloc(numte, sizeof(*od.tes));
1496 od.edgedata = sat_extend(0, 0, 1, sizeof(Id), EDGEDATA_BLOCK);
1499 queue_init(&od.cycles);
1501 /* initialize TEs */
1502 for (i = 0, te = od.tes + 1; i < tr->count; i++)
1504 p = tr->elements[i];
1505 s = pool->solvables + p;
1506 if (installed && s->repo == installed && trans->transaction_installed[p - installed->start])
1512 /* create dependency graph */
1513 for (i = 0; i < tr->count; i++)
1514 addsolvableedges(&od, pool->solvables + tr->elements[i]);
1518 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1519 for (j = te->edges; od.edgedata[j]; j += 2)
1521 POOL_DEBUG(SAT_DEBUG_STATS, "edges: %d, edge space: %d\n", numedge, od.nedgedata / 2);
1522 POOL_DEBUG(SAT_DEBUG_STATS, "edge creation took %d ms\n", sat_timems(now));
1528 now = sat_timems(0);
1529 /* kill all cycles */
1531 for (i = numte - 1; i > 0; i--)
1532 queue_push(&todo, i);
1536 i = queue_pop(&todo);
1537 /* printf("- look at TE %d\n", i); */
1541 od.tes[i].mark = 2; /* done with that one */
1546 continue; /* already finished before */
1549 int edgestovisit = 0;
1550 /* new node, visit edges */
1551 for (j = te->edges; (k = od.edgedata[j]) != 0; j += 2)
1553 if ((od.edgedata[j + 1] & TYPE_BROKEN) != 0)
1555 if (od.tes[k].mark == 2)
1556 continue; /* no need to visit again */
1557 if (!edgestovisit++)
1558 queue_push(&todo, -i); /* end of edges marker */
1559 queue_push(&todo, k);
1562 te->mark = 2; /* no edges, done with that one */
1564 te->mark = 1; /* under investigation */
1567 /* oh no, we found a cycle */
1568 /* find start of cycle node (<0) */
1569 for (j = todo.count - 1; j >= 0; j--)
1570 if (todo.elements[j] == -i)
1574 /* build te/edge chain */
1576 for (j = k; j < todo.count; j++)
1577 if (todo.elements[j] < 0)
1578 todo.elements[k++] = -todo.elements[j];
1579 cycel = k - cycstart;
1581 /* make room for edges, two extra element for cycle loop + terminating 0 */
1582 while (todo.count < cycstart + 2 * cycel + 2)
1583 queue_push(&todo, 0);
1584 cycle = todo.elements + cycstart;
1585 cycle[cycel] = i; /* close the loop */
1586 cycle[2 * cycel + 1] = 0; /* terminator */
1587 for (k = cycel; k > 0; k--)
1589 cycle[k * 2] = cycle[k];
1590 te = od.tes + cycle[k - 1];
1591 assert(te->mark == 1);
1592 te->mark = 0; /* reset investigation marker */
1593 /* printf("searching for edge from %d to %d\n", cycle[k - 1], cycle[k]); */
1594 for (j = te->edges; od.edgedata[j]; j += 2)
1595 if (od.edgedata[j] == cycle[k])
1597 assert(od.edgedata[j]);
1598 cycle[k * 2 - 1] = j;
1600 /* now cycle looks like this: */
1601 /* te1 edge te2 edge te3 ... teN edge te1 0 */
1602 breakcycle(&od, cycle);
1603 /* restart with start of cycle */
1604 todo.count = cycstart + 1;
1606 POOL_DEBUG(SAT_DEBUG_STATS, "cycles broken: %d\n", od.ncycles);
1607 POOL_DEBUG(SAT_DEBUG_STATS, "cycle breaking took %d ms\n", sat_timems(now));
1609 now = sat_timems(0);
1610 /* now go through all broken cycles and create cycle edges to help
1612 for (i = od.cycles.count - 3; i >= 0; i -= 3)
1614 if (od.cycles.elements[i + 2] >= TYPE_REQ)
1615 addcycleedges(&od, od.cyclesdata.elements + od.cycles.elements[i], &todo);
1617 for (i = od.cycles.count - 3; i >= 0; i -= 3)
1619 if (od.cycles.elements[i + 2] < TYPE_REQ)
1620 addcycleedges(&od, od.cyclesdata.elements + od.cycles.elements[i], &todo);
1622 POOL_DEBUG(SAT_DEBUG_STATS, "cycle edge creation took %d ms\n", sat_timems(now));
1627 /* all edges are finally set up and there are no cycles, now the easy part.
1628 * Create an ordered transaction */
1629 now = sat_timems(0);
1630 /* first invert all edges */
1631 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1632 te->mark = 1; /* term 0 */
1633 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1635 for (j = te->edges; od.edgedata[j]; j += 2)
1637 if ((od.edgedata[j + 1] & TYPE_BROKEN) != 0)
1639 od.tes[od.edgedata[j]].mark++;
1643 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1648 POOL_DEBUG(SAT_DEBUG_STATS, "invedge space: %d\n", j + 1);
1649 od.invedgedata = sat_calloc(j + 1, sizeof(Id));
1650 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1652 for (j = te->edges; od.edgedata[j]; j += 2)
1654 if ((od.edgedata[j + 1] & TYPE_BROKEN) != 0)
1656 od.invedgedata[--od.tes[od.edgedata[j]].mark] = i;
1659 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1660 te->edges = te->mark; /* edges now points into invedgedata */
1661 od.edgedata = sat_free(od.edgedata);
1662 od.nedgedata = j + 1;
1664 /* now the final ordering */
1665 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1667 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1668 for (j = te->edges; od.invedgedata[j]; j++)
1669 od.tes[od.invedgedata[j]].mark++;
1671 queue_init(&samerepoq);
1672 queue_init(&uninstq);
1674 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1677 if (installed && pool->solvables[te->p].repo == installed)
1678 queue_push(&uninstq, i);
1680 queue_push(&todo, i);
1682 assert(todo.count > 0 || uninstq.count > 0);
1683 oldcount = tr->count;
1690 temedianr = sat_calloc(numte, sizeof(Id));
1691 for (i = 1; i < numte; i++)
1693 Solvable *s = pool->solvables + od.tes[i].p;
1694 if (installed && s->repo == installed)
1697 j = solvable_lookup_num(s, SOLVABLE_MEDIANR, 1);
1702 /* select an TE i */
1704 i = queue_shift(&uninstq);
1705 else if (samerepoq.count)
1706 i = queue_shift(&samerepoq);
1707 else if (todo.count)
1709 /* find next repo/media */
1710 for (j = 0; j < todo.count; j++)
1712 if (!j || temedianr[todo.elements[j]] < lastmedia)
1715 lastmedia = temedianr[todo.elements[j]];
1718 lastrepo = pool->solvables[od.tes[todo.elements[i]].p].repo;
1720 /* move all matching TEs to samerepoq */
1721 for (i = j = 0; j < todo.count; j++)
1723 int k = todo.elements[j];
1724 if (temedianr[k] == lastmedia && pool->solvables[od.tes[k].p].repo == lastrepo)
1725 queue_push(&samerepoq, k);
1727 todo.elements[i++] = k;
1731 assert(samerepoq.count);
1732 i = queue_shift(&samerepoq);
1738 queue_push(tr, te->p);
1740 printf("do %s [%d]\n", solvid2str(pool, te->p), temedianr[i]);
1742 s = pool->solvables + te->p;
1743 for (j = te->edges; od.invedgedata[j]; j++)
1745 struct _TransactionElement *te2 = od.tes + od.invedgedata[j];
1746 assert(te2->mark > 0);
1747 if (--te2->mark == 0)
1749 Solvable *s = pool->solvables + te2->p;
1751 printf("free %s [%d]\n", solvid2str(pool, te2->p), temedianr[od.invedgedata[j]]);
1753 if (installed && s->repo == installed)
1754 queue_push(&uninstq, od.invedgedata[j]);
1755 else if (s->repo == lastrepo && temedianr[od.invedgedata[j]] == lastmedia)
1756 queue_push(&samerepoq, od.invedgedata[j]);
1758 queue_push(&todo, od.invedgedata[j]);
1762 sat_free(temedianr);
1764 queue_free(&samerepoq);
1765 queue_free(&uninstq);
1767 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1768 assert(te->mark == 0);
1770 /* add back obsoleted packages */
1771 transaction_add_obsoleted(trans);
1772 assert(tr->count == oldcount);
1774 POOL_DEBUG(SAT_DEBUG_STATS, "creating new transaction took %d ms\n", sat_timems(now));
1775 POOL_DEBUG(SAT_DEBUG_STATS, "transaction ordering took %d ms\n", sat_timems(start));
1777 if ((flags & SOLVER_TRANSACTION_KEEP_ORDERDATA) != 0)
1779 trans->orderdata = sat_calloc(1, sizeof(*trans->orderdata));
1780 trans->orderdata->tes = od.tes;
1781 trans->orderdata->ntes = numte;
1782 trans->orderdata->invedgedata = od.invedgedata;
1783 trans->orderdata->ninvedgedata = od.nedgedata;
1788 sat_free(od.invedgedata);
1794 transaction_order_add_choices(Transaction *trans, Id chosen, Queue *choices)
1797 struct _TransactionOrderdata *od = trans->orderdata;
1798 struct _TransactionElement *te;
1801 return choices->count;
1804 /* initialization step */
1805 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1807 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1809 for (j = te->edges; od->invedgedata[j]; j++)
1810 od->tes[od->invedgedata[j]].mark++;
1812 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1814 queue_push(choices, te->p);
1815 return choices->count;
1817 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1818 if (te->p == chosen)
1821 return choices->count;
1824 /* hey! out-of-order installation! */
1827 for (j = te->edges; od->invedgedata[j]; j++)
1829 te = od->tes + od->invedgedata[j];
1830 assert(te->mark > 0 || te->mark == -1);
1831 if (te->mark > 0 && --te->mark == 0)
1832 queue_push(choices, te->p);
1834 return choices->count;
1838 transaction_add_obsoleted(Transaction *trans)
1840 Pool *pool = trans->pool;
1841 Repo *installed = pool->installed;
1844 int i, j, k, max, oldcount;
1848 if (!installed || !trans->steps.count)
1850 /* calculate upper bound */
1852 FOR_REPO_SOLVABLES(installed, p, s)
1853 if (MAPTST(&trans->transactsmap, p))
1858 steps = &trans->steps;
1859 oldcount = steps->count;
1860 queue_insertn(steps, 0, max);
1863 map_init(&done, installed->end - installed->start);
1865 for (j = 0, i = max; i < steps->count; i++)
1867 p = trans->steps.elements[i];
1868 if (pool->solvables[p].repo == installed)
1870 if (!trans->transaction_installed[p - pool->installed->start])
1871 trans->steps.elements[j++] = p;
1874 trans->steps.elements[j++] = p;
1876 transaction_all_obs_pkgs(trans, p, &obsq);
1877 for (k = 0; k < obsq.count; k++)
1879 p = obsq.elements[k];
1880 assert(p >= installed->start && p < installed->end);
1881 if (MAPTST(&done, p - installed->start))
1883 MAPSET(&done, p - installed->start);
1884 trans->steps.elements[j++] = p;
1888 /* free unneeded space */
1889 queue_truncate(steps, j);
1895 transaction_check_pkg(Transaction *trans, Id tepkg, Id pkg, Map *ins, Map *seen, int onlyprereq, Id noconfpkg, int depth)
1897 Pool *pool = trans->pool;
1902 if (MAPTST(seen, pkg))
1905 s = pool->solvables + pkg;
1907 printf("- %*s%c%s\n", depth * 2, "", s->repo == pool->installed ? '-' : '+', solvable2str(pool, s));
1913 reqp = s->repo->idarraydata + s->requires;
1914 while ((req = *reqp++) != 0)
1916 if (req == SOLVABLE_PREREQMARKER)
1921 if (onlyprereq && !inpre)
1923 if (!strncmp(id2str(pool, req), "rpmlib(", 7))
1926 /* first check kept packages, then freshly installed, then not yet uninstalled */
1927 FOR_PROVIDES(p, pp, req)
1929 if (!MAPTST(ins, p))
1931 if (MAPTST(&trans->transactsmap, p))
1934 transaction_check_pkg(trans, tepkg, p, ins, seen, 0, noconfpkg, depth + 1);
1938 FOR_PROVIDES(p, pp, req)
1940 if (!MAPTST(ins, p))
1942 if (pool->solvables[p].repo == pool->installed)
1945 transaction_check_pkg(trans, tepkg, p, ins, seen, 0, noconfpkg, depth + 1);
1950 FOR_PROVIDES(p, pp, req)
1952 if (!MAPTST(ins, p))
1955 transaction_check_pkg(trans, tepkg, p, ins, seen, 0, noconfpkg, depth + 1);
1960 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));
1967 transaction_check_order(Transaction *trans)
1969 Pool *pool = trans->pool;
1975 POOL_DEBUG(SAT_WARN, "\nchecking transaction order...\n");
1976 map_init(&ins, pool->nsolvables);
1977 map_init(&seen, pool->nsolvables);
1978 if (pool->installed)
1979 FOR_REPO_SOLVABLES(pool->installed, p, s)
1982 for (i = 0; i < trans->steps.count; i++)
1984 p = trans->steps.elements[i];
1985 s = pool->solvables + p;
1986 if (s->repo != pool->installed)
1988 if (s->repo != pool->installed)
1990 if (havescripts(pool, p))
1993 transaction_check_pkg(trans, p, p, &ins, &seen, 1, lastins, 0);
1995 if (s->repo == pool->installed)
2000 POOL_DEBUG(SAT_WARN, "transaction order check done.\n");