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);
709 transaction_create_installedmap(Transaction *trans, Map *installedmap)
711 Pool *pool = trans->pool;
712 Repo *installed = pool->installed;
717 map_init(installedmap, pool->nsolvables);
718 for (i = 0; i < trans->steps.count; i++)
720 p = trans->steps.elements[i];
721 s = pool->solvables + p;
722 if (!installed || s->repo != installed)
723 MAPSET(installedmap, p);
727 FOR_REPO_SOLVABLES(installed, p, s)
728 if (!MAPTST(&trans->transactsmap, p))
729 MAPSET(installedmap, p);
734 transaction_calc_installsizechange(Transaction *trans)
739 transaction_create_installedmap(trans, &installedmap);
740 change = pool_calc_installsizechange(trans->pool, &installedmap);
741 map_free(&installedmap);
746 transaction_calc_duchanges(Transaction *trans, DUChanges *mps, int nmps)
750 transaction_create_installedmap(trans, &installedmap);
751 pool_calc_duchanges(trans->pool, &installedmap, mps, nmps);
752 map_free(&installedmap);
755 struct _TransactionElement {
756 Id p; /* solvable id */
757 Id edges; /* pointer into edges data */
761 struct _TransactionOrderdata {
762 struct _TransactionElement *tes;
768 #define TYPE_BROKEN (1<<0)
769 #define TYPE_CON (1<<1)
771 #define TYPE_REQ_P (1<<2)
772 #define TYPE_PREREQ_P (1<<3)
774 #define TYPE_REQ (1<<4)
775 #define TYPE_PREREQ (1<<5)
777 #define TYPE_CYCLETAIL (1<<16)
778 #define TYPE_CYCLEHEAD (1<<17)
780 #define EDGEDATA_BLOCK 127
783 transaction_init(Transaction *trans, Pool *pool)
785 memset(trans, 0, sizeof(*trans));
790 transaction_init_clone(Transaction *trans, Transaction *srctrans)
792 memset(trans, 0, sizeof(*trans));
793 trans->pool = srctrans->pool;
794 queue_init_clone(&trans->steps, &srctrans->steps);
795 queue_init_clone(&trans->transaction_info, &srctrans->transaction_info);
796 if (srctrans->transaction_installed)
798 Repo *installed = srctrans->pool->installed;
799 trans->transaction_installed = sat_calloc(installed->end - installed->start, sizeof(Id));
800 memcpy(trans->transaction_installed, srctrans->transaction_installed, (installed->end - installed->start) * sizeof(Id));
802 map_init_clone(&trans->transactsmap, &srctrans->transactsmap);
803 map_init_clone(&trans->noobsmap, &srctrans->noobsmap);
804 if (srctrans->orderdata)
806 struct _TransactionOrderdata *od = srctrans->orderdata;
807 trans->orderdata = sat_calloc(1, sizeof(*trans->orderdata));
808 trans->orderdata->tes = sat_malloc2(od->ntes, sizeof(*od->tes));
809 memcpy(trans->orderdata->tes, od->tes, od->ntes * sizeof(*od->tes));
810 trans->orderdata->ntes = od->ntes;
811 trans->orderdata->invedgedata = sat_malloc2(od->ninvedgedata, sizeof(Id));
812 memcpy(trans->orderdata->invedgedata, od->invedgedata, od->ninvedgedata * sizeof(Id));
813 trans->orderdata->ninvedgedata = od->ninvedgedata;
818 transaction_free(Transaction *trans)
820 queue_free(&trans->steps);
821 queue_free(&trans->transaction_info);
822 trans->transaction_installed = sat_free(trans->transaction_installed);
823 map_free(&trans->transactsmap);
824 map_free(&trans->noobsmap);
825 transaction_free_orderdata(trans);
829 transaction_free_orderdata(Transaction *trans)
831 if (trans->orderdata)
833 struct _TransactionOrderdata *od = trans->orderdata;
834 od->tes = sat_free(od->tes);
835 od->invedgedata = sat_free(od->invedgedata);
836 trans->orderdata = sat_free(trans->orderdata);
842 struct _TransactionElement *tes;
854 addteedge(struct orderdata *od, int from, int to, int type)
857 struct _TransactionElement *te;
862 /* printf("edge %d(%s) -> %d(%s) type %x\n", from, solvid2str(pool, od->tes[from].p), to, solvid2str(pool, od->tes[to].p), type); */
865 for (i = te->edges; od->edgedata[i]; i += 2)
866 if (od->edgedata[i] == to)
868 /* test of brokenness */
869 if (type == TYPE_BROKEN)
870 return od->edgedata[i] && (od->edgedata[i + 1] & TYPE_BROKEN) != 0 ? 1 : 0;
873 od->edgedata[i + 1] |= type;
876 if (i + 1 == od->nedgedata)
878 /* printf("tail add %d\n", i - te->edges); */
881 od->edgedata = sat_extend(od->edgedata, od->nedgedata, 3, sizeof(Id), EDGEDATA_BLOCK);
885 /* printf("extend %d\n", i - te->edges); */
886 od->edgedata = sat_extend(od->edgedata, od->nedgedata, 3 + (i - te->edges), sizeof(Id), EDGEDATA_BLOCK);
888 memcpy(od->edgedata + od->nedgedata, od->edgedata + te->edges, sizeof(Id) * (i - te->edges));
889 i = od->nedgedata + (i - te->edges);
890 te->edges = od->nedgedata;
892 od->edgedata[i] = to;
893 od->edgedata[i + 1] = type;
894 od->edgedata[i + 2] = 0; /* end marker */
895 od->nedgedata = i + 3;
900 addedge(struct orderdata *od, Id from, Id to, int type)
902 Transaction *trans = od->trans;
903 Pool *pool = trans->pool;
905 struct _TransactionElement *te;
908 // printf("addedge %d %d type %d\n", from, to, type);
909 s = pool->solvables + from;
910 if (s->repo == pool->installed && trans->transaction_installed[from - pool->installed->start])
912 /* obsolete, map to install */
913 if (trans->transaction_installed[from - pool->installed->start] > 0)
914 from = trans->transaction_installed[from - pool->installed->start];
921 queue_init_buffer(&ti, tibuf, sizeof(tibuf)/sizeof(*tibuf));
922 transaction_all_obs_pkgs(trans, from, &ti);
923 for (i = 0; i < ti.count; i++)
924 ret |= addedge(od, ti.elements[i], to, type);
929 s = pool->solvables + to;
930 if (s->repo == pool->installed && trans->transaction_installed[to - pool->installed->start])
932 /* obsolete, map to install */
933 if (trans->transaction_installed[to - pool->installed->start] > 0)
934 to = trans->transaction_installed[to - pool->installed->start];
941 queue_init_buffer(&ti, tibuf, sizeof(tibuf)/sizeof(*tibuf));
942 transaction_all_obs_pkgs(trans, to, &ti);
943 for (i = 0; i < ti.count; i++)
944 ret |= addedge(od, from, ti.elements[i], type);
950 /* map from/to to te numbers */
951 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
958 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
964 return addteedge(od, i, to, type);
969 havechoice(struct orderdata *od, Id p, Id q1, Id q2)
971 Transaction *trans = od->trans;
972 Pool *pool = trans->pool;
973 Id ti1buf[5], ti2buf[5];
977 /* both q1 and q2 are uninstalls. check if their TEs intersect */
978 /* common case: just one TE for both packages */
980 printf("havechoice %d %d %d\n", p, q1, q2);
982 if (trans->transaction_installed[q1 - pool->installed->start] == 0)
984 if (trans->transaction_installed[q2 - pool->installed->start] == 0)
986 if (trans->transaction_installed[q1 - pool->installed->start] == trans->transaction_installed[q2 - pool->installed->start])
988 if (trans->transaction_installed[q1 - pool->installed->start] > 0 && trans->transaction_installed[q2 - pool->installed->start] > 0)
990 queue_init_buffer(&ti1, ti1buf, sizeof(ti1buf)/sizeof(*ti1buf));
991 transaction_all_obs_pkgs(trans, q1, &ti1);
992 queue_init_buffer(&ti2, ti2buf, sizeof(ti2buf)/sizeof(*ti2buf));
993 transaction_all_obs_pkgs(trans, q2, &ti2);
994 for (i = 0; i < ti1.count; i++)
995 for (j = 0; j < ti2.count; j++)
996 if (ti1.elements[i] == ti2.elements[j])
998 /* found a common edge */
1010 havescripts(Pool *pool, Id solvid)
1012 Solvable *s = pool->solvables + solvid;
1018 reqp = s->repo->idarraydata + s->requires;
1019 while ((req = *reqp++) != 0)
1021 if (req == SOLVABLE_PREREQMARKER)
1028 dep = id2str(pool, req);
1029 if (*dep == '/' && strcmp(dep, "/sbin/ldconfig") != 0)
1037 addsolvableedges(struct orderdata *od, Solvable *s)
1039 Transaction *trans = od->trans;
1040 Pool *pool = trans->pool;
1041 Id req, *reqp, con, *conp;
1043 int i, j, pre, numins;
1044 Repo *installed = pool->installed;
1050 printf("addsolvableedges %s\n", solvable2str(pool, s));
1052 p = s - pool->solvables;
1056 reqp = s->repo->idarraydata + s->requires;
1058 while ((req = *reqp++) != 0)
1060 if (req == SOLVABLE_PREREQMARKER)
1066 if (pre != TYPE_PREREQ && installed && s->repo == installed)
1068 /* ignore normal requires if we're getting obsoleted */
1069 if (trans->transaction_installed[p - pool->installed->start])
1074 numins = 0; /* number of packages to be installed providing it */
1075 provbyinst = 0; /* provided by kept package */
1076 FOR_PROVIDES(p2, pp2, req)
1078 s2 = pool->solvables + p2;
1081 reqq.count = 0; /* self provides */
1084 if (s2->repo == installed && !MAPTST(&trans->transactsmap, p2))
1088 printf("IGNORE inst provides %s by %s\n", dep2str(pool, req), solvable2str(pool, s2));
1089 reqq.count = 0; /* provided by package that stays installed */
1095 if (s2->repo != installed && !MAPTST(&trans->transactsmap, p2))
1096 continue; /* package stays uninstalled */
1098 if (s->repo == installed)
1100 /* s gets uninstalled */
1101 queue_pushunique(&reqq, p2);
1102 if (s2->repo != installed)
1107 if (s2->repo == installed)
1108 continue; /* s2 gets uninstalled */
1109 queue_pushunique(&reqq, p2);
1114 /* prune to harmless ->inst edges */
1115 for (i = j = 0; i < reqq.count; i++)
1116 if (pool->solvables[reqq.elements[i]].repo != installed)
1117 reqq.elements[j++] = reqq.elements[i];
1121 if (numins && reqq.count)
1123 if (s->repo == installed)
1125 for (i = 0; i < reqq.count; i++)
1127 if (pool->solvables[reqq.elements[i]].repo == installed)
1129 for (j = 0; j < reqq.count; j++)
1131 if (pool->solvables[reqq.elements[j]].repo != installed)
1133 if (trans->transaction_installed[reqq.elements[i] - pool->installed->start] == reqq.elements[j])
1134 continue; /* no self edge */
1136 printf("add interrreq uninst->inst edge (%s -> %s -> %s)\n", solvid2str(pool, reqq.elements[i]), dep2str(pool, req), solvid2str(pool, reqq.elements[j]));
1138 addedge(od, reqq.elements[i], reqq.elements[j], pre == TYPE_PREREQ ? TYPE_PREREQ_P : TYPE_REQ_P);
1144 /* no mixed types, remove all deps on uninstalls */
1145 for (i = j = 0; i < reqq.count; i++)
1146 if (pool->solvables[reqq.elements[i]].repo != installed)
1147 reqq.elements[j++] = reqq.elements[i];
1152 for (i = 0; i < reqq.count; i++)
1155 p2 = reqq.elements[i];
1156 if (pool->solvables[p2].repo != installed)
1158 /* all elements of reqq are installs, thus have different TEs */
1159 choice = reqq.count - 1;
1160 if (pool->solvables[p].repo != installed)
1163 printf("add inst->inst edge choice %d (%s -> %s -> %s)\n", choice, solvid2str(pool, p), dep2str(pool, req), solvid2str(pool, p2));
1165 addedge(od, p, p2, pre);
1170 printf("add uninst->inst edge choice %d (%s -> %s -> %s)\n", choice, solvid2str(pool, p), dep2str(pool, req), solvid2str(pool, p2));
1172 addedge(od, p, p2, pre == TYPE_PREREQ ? TYPE_PREREQ_P : TYPE_REQ_P);
1177 if (s->repo != installed)
1178 continue; /* no inst->uninst edges, please! */
1180 /* uninst -> uninst edge. Those make trouble. Only add if we must */
1181 if (trans->transaction_installed[p - installed->start] && !havescripts(pool, p))
1183 /* p is obsoleted by another package and has no scripts */
1184 /* we assume that the obsoletor is good enough to replace p */
1189 for (j = 0; j < reqq.count; j++)
1193 if (havechoice(od, p, reqq.elements[i], reqq.elements[j]))
1198 printf("add uninst->uninst edge choice %d (%s -> %s -> %s)\n", choice, solvid2str(pool, p), dep2str(pool, req), solvid2str(pool, p2));
1200 addedge(od, p2, p, pre == TYPE_PREREQ ? TYPE_PREREQ_P : TYPE_REQ_P);
1207 conp = s->repo->idarraydata + s->conflicts;
1208 while ((con = *conp++) != 0)
1210 FOR_PROVIDES(p2, pp2, con)
1214 s2 = pool->solvables + p2;
1217 if (s->repo == installed)
1219 if (s2->repo != installed && MAPTST(&trans->transactsmap, p2))
1221 /* deinstall p before installing p2 */
1222 addedge(od, p2, p, TYPE_CON);
1227 if (s2->repo == installed && MAPTST(&trans->transactsmap, p2))
1229 /* deinstall p2 before installing p */
1230 addedge(od, p, p2, TYPE_CON);
1241 /* break an edge in a cycle */
1243 breakcycle(struct orderdata *od, Id *cycle)
1245 Pool *pool = od->trans->pool;
1246 Id ddegmin, ddegmax, ddeg;
1248 struct _TransactionElement *te;
1251 ddegmin = ddegmax = 0;
1252 for (k = 0; cycle[k + 1]; k += 2)
1254 ddeg = od->edgedata[cycle[k + 1] + 1];
1257 if (!k || ddeg < ddegmin)
1263 if (ddeg == ddegmin)
1265 if (havescripts(pool, od->tes[cycle[l]].p) && !havescripts(pool, od->tes[cycle[k]].p))
1267 /* prefer k, as l comes from a package with contains scriptlets */
1272 /* same edge value, check for prereq */
1276 /* record brkoen cycle starting with the tail */
1277 queue_push(&od->cycles, od->cyclesdata.count); /* offset into data */
1278 queue_push(&od->cycles, k / 2); /* cycle elements */
1279 queue_push(&od->cycles, od->edgedata[cycle[l + 1] + 1]); /* broken edge */
1286 queue_push(&od->cyclesdata, cycle[k]);
1290 queue_push(&od->cyclesdata, 0); /* mark end */
1292 /* break that edge */
1293 od->edgedata[cycle[l + 1] + 1] |= TYPE_BROKEN;
1296 if (ddegmin < TYPE_REQ)
1300 /* cycle recorded, print it */
1301 if (ddegmin >= TYPE_REQ && (ddegmax & TYPE_PREREQ) != 0)
1302 POOL_DEBUG(SAT_DEBUG_STATS, "CRITICAL ");
1303 POOL_DEBUG(SAT_DEBUG_STATS, "cycle: --> ");
1304 for (k = 0; cycle[k + 1]; k += 2)
1306 te = od->tes + cycle[k];
1307 if ((od->edgedata[cycle[k + 1] + 1] & TYPE_BROKEN) != 0)
1308 POOL_DEBUG(SAT_DEBUG_STATS, "%s ##%x##> ", solvid2str(pool, te->p), od->edgedata[cycle[k + 1] + 1]);
1310 POOL_DEBUG(SAT_DEBUG_STATS, "%s --%x--> ", solvid2str(pool, te->p), od->edgedata[cycle[k + 1] + 1]);
1312 POOL_DEBUG(SAT_DEBUG_STATS, "\n");
1316 dump_tes(struct orderdata *od)
1318 Pool *pool = od->trans->pool;
1321 struct _TransactionElement *te, *te2;
1324 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1326 Solvable *s = pool->solvables + te->p;
1327 POOL_DEBUG(SAT_DEBUG_RESULT, "TE %4d: %c%s\n", i, s->repo == pool->installed ? '-' : '+', solvable2str(pool, s));
1328 if (s->repo != pool->installed)
1331 transaction_all_obs_pkgs(od->trans, te->p, &obsq);
1332 for (j = 0; j < obsq.count; j++)
1333 POOL_DEBUG(SAT_DEBUG_RESULT, " -%s\n", solvid2str(pool, obsq.elements[j]));
1335 for (j = te->edges; od->edgedata[j]; j += 2)
1337 te2 = od->tes + od->edgedata[j];
1338 if ((od->edgedata[j + 1] & TYPE_BROKEN) == 0)
1339 POOL_DEBUG(SAT_DEBUG_RESULT, " --%x--> TE %4d: %s\n", od->edgedata[j + 1], od->edgedata[j], solvid2str(pool, te2->p));
1341 POOL_DEBUG(SAT_DEBUG_RESULT, " ##%x##> TE %4d: %s\n", od->edgedata[j + 1], od->edgedata[j], solvid2str(pool, te2->p));
1348 reachable(struct orderdata *od, Id i)
1350 struct _TransactionElement *te = od->tes + i;
1356 for (j = te->edges; (k = od->edgedata[j]) != 0; j += 2)
1358 if ((od->edgedata[j + 1] & TYPE_BROKEN) != 0)
1360 if (!od->tes[k].mark)
1362 if (od->tes[k].mark == 2)
1373 addcycleedges(struct orderdata *od, Id *cycle, Queue *todo)
1376 Transaction *trans = od->trans;
1377 Pool *pool = trans->pool;
1379 struct _TransactionElement *te;
1386 printf("addcycleedges\n");
1387 for (i = 0; (j = cycle[i]) != 0; i++)
1388 printf("cycle %s\n", solvid2str(pool, od->tes[j].p));
1391 /* first add all the tail cycle edges */
1393 /* see what we can reach from the cycle */
1395 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1397 for (i = 0; (j = cycle[i]) != 0; i++)
1399 od->tes[j].mark = -1;
1400 queue_push(todo, j);
1404 i = queue_pop(todo);
1408 te->mark = te->mark < 0 ? 2 : 1;
1409 for (j = te->edges; (k = od->edgedata[j]) != 0; j += 2)
1411 if ((od->edgedata[j + 1] & TYPE_BROKEN) != 0)
1413 if (od->tes[k].mark > 0)
1414 continue; /* no need to visit again */
1415 queue_push(todo, k);
1418 /* now all cycle TEs are marked with 2, all TEs reachable
1419 * from the cycle are marked with 1 */
1421 od->tes[tail].mark = 1; /* no need to add edges */
1423 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1426 continue; /* reachable from cycle */
1427 for (j = te->edges; (k = od->edgedata[j]) != 0; j += 2)
1429 if ((od->edgedata[j + 1] & TYPE_BROKEN) != 0)
1431 if (od->tes[k].mark != 2)
1433 /* We found an edge to the cycle. Add an extra edge to the tail */
1434 /* the TE was not reachable, so we're not creating a new cycle! */
1436 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));
1438 j -= te->edges; /* in case we move */
1439 addteedge(od, i, tail, TYPE_CYCLETAIL);
1441 break; /* one edge is enough */
1446 /* now add all head cycle edges */
1449 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1452 for (i = 0; (j = cycle[i]) != 0; i++)
1455 od->tes[j].mark = 2;
1457 /* first the head to save some time */
1458 te = od->tes + head;
1459 for (j = te->edges; (k = od->edgedata[j]) != 0; j += 2)
1461 if ((od->edgedata[j + 1] & TYPE_BROKEN) != 0)
1463 if (!od->tes[k].mark)
1465 if (od->tes[k].mark == -1)
1466 od->tes[k].mark = -2; /* no need for another edge */
1468 for (i = 0; cycle[i] != 0; i++)
1470 if (cycle[i] == head)
1472 te = od->tes + cycle[i];
1473 for (j = te->edges; (k = od->edgedata[j]) != 0; j += 2)
1475 if ((od->edgedata[j + 1] & TYPE_BROKEN) != 0)
1477 /* see if we can reach a cycle TE from k */
1478 if (!od->tes[k].mark)
1480 if (od->tes[k].mark == -1)
1483 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));
1485 addteedge(od, head, k, TYPE_CYCLEHEAD);
1486 od->tes[k].mark = -2; /* no need to add that one again */
1494 transaction_order(Transaction *trans, int flags)
1496 Pool *pool = trans->pool;
1497 Queue *tr = &trans->steps;
1498 Repo *installed = pool->installed;
1501 int i, j, k, numte, numedge;
1502 struct orderdata od;
1503 struct _TransactionElement *te;
1504 Queue todo, obsq, samerepoq, uninstq;
1505 int cycstart, cycel;
1513 start = now = sat_timems(0);
1514 POOL_DEBUG(SAT_DEBUG_STATS, "ordering transaction\n");
1515 /* free old data if present */
1516 if (trans->orderdata)
1518 struct _TransactionOrderdata *od = trans->orderdata;
1519 od->tes = sat_free(od->tes);
1520 od->invedgedata = sat_free(od->invedgedata);
1521 trans->orderdata = sat_free(trans->orderdata);
1524 /* create a transaction element for every active component */
1526 for (i = 0; i < tr->count; i++)
1528 p = tr->elements[i];
1529 s = pool->solvables + p;
1530 if (installed && s->repo == installed && trans->transaction_installed[p - installed->start])
1534 POOL_DEBUG(SAT_DEBUG_STATS, "transaction elements: %d\n", numte);
1536 return; /* nothing to do... */
1538 numte++; /* leave first one zero */
1539 memset(&od, 0, sizeof(od));
1542 od.tes = sat_calloc(numte, sizeof(*od.tes));
1543 od.edgedata = sat_extend(0, 0, 1, sizeof(Id), EDGEDATA_BLOCK);
1546 queue_init(&od.cycles);
1548 /* initialize TEs */
1549 for (i = 0, te = od.tes + 1; i < tr->count; i++)
1551 p = tr->elements[i];
1552 s = pool->solvables + p;
1553 if (installed && s->repo == installed && trans->transaction_installed[p - installed->start])
1559 /* create dependency graph */
1560 for (i = 0; i < tr->count; i++)
1561 addsolvableedges(&od, pool->solvables + tr->elements[i]);
1565 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1566 for (j = te->edges; od.edgedata[j]; j += 2)
1568 POOL_DEBUG(SAT_DEBUG_STATS, "edges: %d, edge space: %d\n", numedge, od.nedgedata / 2);
1569 POOL_DEBUG(SAT_DEBUG_STATS, "edge creation took %d ms\n", sat_timems(now));
1575 now = sat_timems(0);
1576 /* kill all cycles */
1578 for (i = numte - 1; i > 0; i--)
1579 queue_push(&todo, i);
1583 i = queue_pop(&todo);
1584 /* printf("- look at TE %d\n", i); */
1588 od.tes[i].mark = 2; /* done with that one */
1593 continue; /* already finished before */
1596 int edgestovisit = 0;
1597 /* new node, visit edges */
1598 for (j = te->edges; (k = od.edgedata[j]) != 0; j += 2)
1600 if ((od.edgedata[j + 1] & TYPE_BROKEN) != 0)
1602 if (od.tes[k].mark == 2)
1603 continue; /* no need to visit again */
1604 if (!edgestovisit++)
1605 queue_push(&todo, -i); /* end of edges marker */
1606 queue_push(&todo, k);
1609 te->mark = 2; /* no edges, done with that one */
1611 te->mark = 1; /* under investigation */
1614 /* oh no, we found a cycle */
1615 /* find start of cycle node (<0) */
1616 for (j = todo.count - 1; j >= 0; j--)
1617 if (todo.elements[j] == -i)
1621 /* build te/edge chain */
1623 for (j = k; j < todo.count; j++)
1624 if (todo.elements[j] < 0)
1625 todo.elements[k++] = -todo.elements[j];
1626 cycel = k - cycstart;
1628 /* make room for edges, two extra element for cycle loop + terminating 0 */
1629 while (todo.count < cycstart + 2 * cycel + 2)
1630 queue_push(&todo, 0);
1631 cycle = todo.elements + cycstart;
1632 cycle[cycel] = i; /* close the loop */
1633 cycle[2 * cycel + 1] = 0; /* terminator */
1634 for (k = cycel; k > 0; k--)
1636 cycle[k * 2] = cycle[k];
1637 te = od.tes + cycle[k - 1];
1638 assert(te->mark == 1);
1639 te->mark = 0; /* reset investigation marker */
1640 /* printf("searching for edge from %d to %d\n", cycle[k - 1], cycle[k]); */
1641 for (j = te->edges; od.edgedata[j]; j += 2)
1642 if (od.edgedata[j] == cycle[k])
1644 assert(od.edgedata[j]);
1645 cycle[k * 2 - 1] = j;
1647 /* now cycle looks like this: */
1648 /* te1 edge te2 edge te3 ... teN edge te1 0 */
1649 breakcycle(&od, cycle);
1650 /* restart with start of cycle */
1651 todo.count = cycstart + 1;
1653 POOL_DEBUG(SAT_DEBUG_STATS, "cycles broken: %d\n", od.ncycles);
1654 POOL_DEBUG(SAT_DEBUG_STATS, "cycle breaking took %d ms\n", sat_timems(now));
1656 now = sat_timems(0);
1657 /* now go through all broken cycles and create cycle edges to help
1659 for (i = od.cycles.count - 3; i >= 0; i -= 3)
1661 if (od.cycles.elements[i + 2] >= TYPE_REQ)
1662 addcycleedges(&od, od.cyclesdata.elements + od.cycles.elements[i], &todo);
1664 for (i = od.cycles.count - 3; i >= 0; i -= 3)
1666 if (od.cycles.elements[i + 2] < TYPE_REQ)
1667 addcycleedges(&od, od.cyclesdata.elements + od.cycles.elements[i], &todo);
1669 POOL_DEBUG(SAT_DEBUG_STATS, "cycle edge creation took %d ms\n", sat_timems(now));
1674 /* all edges are finally set up and there are no cycles, now the easy part.
1675 * Create an ordered transaction */
1676 now = sat_timems(0);
1677 /* first invert all edges */
1678 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1679 te->mark = 1; /* term 0 */
1680 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1682 for (j = te->edges; od.edgedata[j]; j += 2)
1684 if ((od.edgedata[j + 1] & TYPE_BROKEN) != 0)
1686 od.tes[od.edgedata[j]].mark++;
1690 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1695 POOL_DEBUG(SAT_DEBUG_STATS, "invedge space: %d\n", j + 1);
1696 od.invedgedata = sat_calloc(j + 1, sizeof(Id));
1697 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1699 for (j = te->edges; od.edgedata[j]; j += 2)
1701 if ((od.edgedata[j + 1] & TYPE_BROKEN) != 0)
1703 od.invedgedata[--od.tes[od.edgedata[j]].mark] = i;
1706 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1707 te->edges = te->mark; /* edges now points into invedgedata */
1708 od.edgedata = sat_free(od.edgedata);
1709 od.nedgedata = j + 1;
1711 /* now the final ordering */
1712 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1714 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1715 for (j = te->edges; od.invedgedata[j]; j++)
1716 od.tes[od.invedgedata[j]].mark++;
1718 queue_init(&samerepoq);
1719 queue_init(&uninstq);
1721 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1724 if (installed && pool->solvables[te->p].repo == installed)
1725 queue_push(&uninstq, i);
1727 queue_push(&todo, i);
1729 assert(todo.count > 0 || uninstq.count > 0);
1730 oldcount = tr->count;
1737 temedianr = sat_calloc(numte, sizeof(Id));
1738 for (i = 1; i < numte; i++)
1740 Solvable *s = pool->solvables + od.tes[i].p;
1741 if (installed && s->repo == installed)
1744 j = solvable_lookup_num(s, SOLVABLE_MEDIANR, 1);
1749 /* select an TE i */
1751 i = queue_shift(&uninstq);
1752 else if (samerepoq.count)
1753 i = queue_shift(&samerepoq);
1754 else if (todo.count)
1756 /* find next repo/media */
1757 for (j = 0; j < todo.count; j++)
1759 if (!j || temedianr[todo.elements[j]] < lastmedia)
1762 lastmedia = temedianr[todo.elements[j]];
1765 lastrepo = pool->solvables[od.tes[todo.elements[i]].p].repo;
1767 /* move all matching TEs to samerepoq */
1768 for (i = j = 0; j < todo.count; j++)
1770 int k = todo.elements[j];
1771 if (temedianr[k] == lastmedia && pool->solvables[od.tes[k].p].repo == lastrepo)
1772 queue_push(&samerepoq, k);
1774 todo.elements[i++] = k;
1778 assert(samerepoq.count);
1779 i = queue_shift(&samerepoq);
1785 queue_push(tr, te->p);
1787 printf("do %s [%d]\n", solvid2str(pool, te->p), temedianr[i]);
1789 s = pool->solvables + te->p;
1790 for (j = te->edges; od.invedgedata[j]; j++)
1792 struct _TransactionElement *te2 = od.tes + od.invedgedata[j];
1793 assert(te2->mark > 0);
1794 if (--te2->mark == 0)
1796 Solvable *s = pool->solvables + te2->p;
1798 printf("free %s [%d]\n", solvid2str(pool, te2->p), temedianr[od.invedgedata[j]]);
1800 if (installed && s->repo == installed)
1801 queue_push(&uninstq, od.invedgedata[j]);
1802 else if (s->repo == lastrepo && temedianr[od.invedgedata[j]] == lastmedia)
1803 queue_push(&samerepoq, od.invedgedata[j]);
1805 queue_push(&todo, od.invedgedata[j]);
1809 sat_free(temedianr);
1811 queue_free(&samerepoq);
1812 queue_free(&uninstq);
1814 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1815 assert(te->mark == 0);
1817 /* add back obsoleted packages */
1818 transaction_add_obsoleted(trans);
1819 assert(tr->count == oldcount);
1821 POOL_DEBUG(SAT_DEBUG_STATS, "creating new transaction took %d ms\n", sat_timems(now));
1822 POOL_DEBUG(SAT_DEBUG_STATS, "transaction ordering took %d ms\n", sat_timems(start));
1824 if ((flags & SOLVER_TRANSACTION_KEEP_ORDERDATA) != 0)
1826 trans->orderdata = sat_calloc(1, sizeof(*trans->orderdata));
1827 trans->orderdata->tes = od.tes;
1828 trans->orderdata->ntes = numte;
1829 trans->orderdata->invedgedata = od.invedgedata;
1830 trans->orderdata->ninvedgedata = od.nedgedata;
1835 sat_free(od.invedgedata);
1841 transaction_order_add_choices(Transaction *trans, Id chosen, Queue *choices)
1844 struct _TransactionOrderdata *od = trans->orderdata;
1845 struct _TransactionElement *te;
1848 return choices->count;
1851 /* initialization step */
1852 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1854 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1856 for (j = te->edges; od->invedgedata[j]; j++)
1857 od->tes[od->invedgedata[j]].mark++;
1859 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1861 queue_push(choices, te->p);
1862 return choices->count;
1864 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1865 if (te->p == chosen)
1868 return choices->count;
1871 /* hey! out-of-order installation! */
1874 for (j = te->edges; od->invedgedata[j]; j++)
1876 te = od->tes + od->invedgedata[j];
1877 assert(te->mark > 0 || te->mark == -1);
1878 if (te->mark > 0 && --te->mark == 0)
1879 queue_push(choices, te->p);
1881 return choices->count;
1885 transaction_add_obsoleted(Transaction *trans)
1887 Pool *pool = trans->pool;
1888 Repo *installed = pool->installed;
1891 int i, j, k, max, oldcount;
1895 if (!installed || !trans->steps.count)
1897 /* calculate upper bound */
1899 FOR_REPO_SOLVABLES(installed, p, s)
1900 if (MAPTST(&trans->transactsmap, p))
1905 steps = &trans->steps;
1906 oldcount = steps->count;
1907 queue_insertn(steps, 0, max);
1910 map_init(&done, installed->end - installed->start);
1912 for (j = 0, i = max; i < steps->count; i++)
1914 p = trans->steps.elements[i];
1915 if (pool->solvables[p].repo == installed)
1917 if (!trans->transaction_installed[p - pool->installed->start])
1918 trans->steps.elements[j++] = p;
1921 trans->steps.elements[j++] = p;
1923 transaction_all_obs_pkgs(trans, p, &obsq);
1924 for (k = 0; k < obsq.count; k++)
1926 p = obsq.elements[k];
1927 assert(p >= installed->start && p < installed->end);
1928 if (MAPTST(&done, p - installed->start))
1930 MAPSET(&done, p - installed->start);
1931 trans->steps.elements[j++] = p;
1935 /* free unneeded space */
1936 queue_truncate(steps, j);
1942 transaction_check_pkg(Transaction *trans, Id tepkg, Id pkg, Map *ins, Map *seen, int onlyprereq, Id noconfpkg, int depth)
1944 Pool *pool = trans->pool;
1949 if (MAPTST(seen, pkg))
1952 s = pool->solvables + pkg;
1954 printf("- %*s%c%s\n", depth * 2, "", s->repo == pool->installed ? '-' : '+', solvable2str(pool, s));
1960 reqp = s->repo->idarraydata + s->requires;
1961 while ((req = *reqp++) != 0)
1963 if (req == SOLVABLE_PREREQMARKER)
1968 if (onlyprereq && !inpre)
1970 if (!strncmp(id2str(pool, req), "rpmlib(", 7))
1973 /* first check kept packages, then freshly installed, then not yet uninstalled */
1974 FOR_PROVIDES(p, pp, req)
1976 if (!MAPTST(ins, p))
1978 if (MAPTST(&trans->transactsmap, p))
1981 transaction_check_pkg(trans, tepkg, p, ins, seen, 0, noconfpkg, depth + 1);
1985 FOR_PROVIDES(p, pp, req)
1987 if (!MAPTST(ins, p))
1989 if (pool->solvables[p].repo == pool->installed)
1992 transaction_check_pkg(trans, tepkg, p, ins, seen, 0, noconfpkg, depth + 1);
1997 FOR_PROVIDES(p, pp, req)
1999 if (!MAPTST(ins, p))
2002 transaction_check_pkg(trans, tepkg, p, ins, seen, 0, noconfpkg, depth + 1);
2007 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));
2014 transaction_check_order(Transaction *trans)
2016 Pool *pool = trans->pool;
2022 POOL_DEBUG(SAT_WARN, "\nchecking transaction order...\n");
2023 map_init(&ins, pool->nsolvables);
2024 map_init(&seen, pool->nsolvables);
2025 if (pool->installed)
2026 FOR_REPO_SOLVABLES(pool->installed, p, s)
2029 for (i = 0; i < trans->steps.count; i++)
2031 p = trans->steps.elements[i];
2032 s = pool->solvables + p;
2033 if (s->repo != pool->installed)
2035 if (s->repo != pool->installed)
2037 if (havescripts(pool, p))
2040 transaction_check_pkg(trans, p, p, &ins, &seen, 1, lastins, 0);
2042 if (s->repo == pool->installed)
2047 POOL_DEBUG(SAT_WARN, "transaction order check done.\n");