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(pool_id2str(pool, oas->name), pool_id2str(pool, obs->name));
55 r = pool_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 solv_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 = pool_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 = pool_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 if (!(mode & SOLVER_TRANSACTION_KEEP_PSEUDO))
214 const char *n = pool_id2str(pool, s->name);
215 if (!strncmp(n, "patch:", 6))
216 return SOLVER_TRANSACTION_IGNORE;
217 if (!strncmp(n, "pattern:", 8))
218 return SOLVER_TRANSACTION_IGNORE;
221 type = transaction_base_type(trans, p);
223 if (type == SOLVER_TRANSACTION_IGNORE)
224 return SOLVER_TRANSACTION_IGNORE; /* not part of the transaction */
226 if ((mode & SOLVER_TRANSACTION_RPM_ONLY) != 0)
228 /* application wants to know what to feed to rpm */
229 if (type == SOLVER_TRANSACTION_ERASE || type == SOLVER_TRANSACTION_INSTALL || type == SOLVER_TRANSACTION_MULTIINSTALL)
231 if (s->repo == pool->installed)
232 return SOLVER_TRANSACTION_IGNORE; /* ignore as we're being obsoleted */
233 if (type == SOLVER_TRANSACTION_MULTIREINSTALL)
234 return SOLVER_TRANSACTION_MULTIINSTALL;
235 return SOLVER_TRANSACTION_INSTALL;
238 if ((mode & SOLVER_TRANSACTION_SHOW_MULTIINSTALL) == 0)
240 /* application wants to make no difference between install
241 * and multiinstall */
242 if (type == SOLVER_TRANSACTION_MULTIINSTALL)
243 type = SOLVER_TRANSACTION_INSTALL;
244 if (type == SOLVER_TRANSACTION_MULTIREINSTALL)
245 type = SOLVER_TRANSACTION_REINSTALL;
248 if ((mode & SOLVER_TRANSACTION_CHANGE_IS_REINSTALL))
250 /* application wants to make no difference between change
252 if (type == SOLVER_TRANSACTION_CHANGED)
253 type = SOLVER_TRANSACTION_REINSTALLED;
254 else if (type == SOLVER_TRANSACTION_CHANGE)
255 type = SOLVER_TRANSACTION_REINSTALL;
258 if (type == SOLVER_TRANSACTION_ERASE || type == SOLVER_TRANSACTION_INSTALL || type == SOLVER_TRANSACTION_MULTIINSTALL)
261 if (s->repo == pool->installed && (mode & SOLVER_TRANSACTION_SHOW_ACTIVE) == 0)
263 /* erase element and we're showing the passive side */
264 if ((mode & SOLVER_TRANSACTION_SHOW_OBSOLETES) == 0 && type == SOLVER_TRANSACTION_OBSOLETED)
265 type = SOLVER_TRANSACTION_ERASE;
268 if (s->repo != pool->installed && (mode & SOLVER_TRANSACTION_SHOW_ACTIVE) != 0)
270 /* install element and we're showing the active side */
271 if ((mode & SOLVER_TRANSACTION_SHOW_OBSOLETES) == 0 && type == SOLVER_TRANSACTION_OBSOLETES)
272 type = SOLVER_TRANSACTION_INSTALL;
276 /* the element doesn't match the show mode */
278 /* if we're showing all references, we can ignore this package */
279 if ((mode & (SOLVER_TRANSACTION_SHOW_ALL|SOLVER_TRANSACTION_SHOW_OBSOLETES)) == (SOLVER_TRANSACTION_SHOW_ALL|SOLVER_TRANSACTION_SHOW_OBSOLETES))
280 return SOLVER_TRANSACTION_IGNORE;
282 /* we're not showing all refs. check if some other package
283 * references us. If yes, it's safe to ignore this package,
284 * otherwise we need to map the type */
286 /* most of the time there's only one reference, so check it first */
287 q = transaction_obs_pkg(trans, p);
289 if ((mode & SOLVER_TRANSACTION_SHOW_OBSOLETES) == 0)
291 Solvable *sq = pool->solvables + q;
292 if (sq->name != s->name)
294 /* it's a replace but we're not showing replaces. map type. */
295 if (s->repo == pool->installed)
296 return SOLVER_TRANSACTION_ERASE;
297 else if (type == SOLVER_TRANSACTION_MULTIREINSTALL)
298 return SOLVER_TRANSACTION_MULTIINSTALL;
300 return SOLVER_TRANSACTION_INSTALL;
304 /* if there's a match, p will be shown when q
306 if (transaction_obs_pkg(trans, q) == p)
307 return SOLVER_TRANSACTION_IGNORE;
309 /* too bad, a miss. check em all */
312 transaction_all_obs_pkgs(trans, p, &oq);
313 for (i = 0; i < oq.count; i++)
316 if ((mode & SOLVER_TRANSACTION_SHOW_OBSOLETES) == 0)
318 Solvable *sq = pool->solvables + q;
319 if (sq->name != s->name)
322 /* check if we are referenced? */
323 if ((mode & SOLVER_TRANSACTION_SHOW_ALL) != 0)
325 transaction_all_obs_pkgs(trans, q, &rq);
326 for (j = 0; j < rq.count; j++)
327 if (rq.elements[j] == p)
335 else if (transaction_obs_pkg(trans, q) == p)
346 /* we're not referenced. map type */
347 if (s->repo == pool->installed)
348 return SOLVER_TRANSACTION_ERASE;
349 else if (type == SOLVER_TRANSACTION_MULTIREINSTALL)
350 return SOLVER_TRANSACTION_MULTIINSTALL;
352 return SOLVER_TRANSACTION_INSTALL;
354 /* there was a ref, so p is shown with some other package */
355 return SOLVER_TRANSACTION_IGNORE;
361 classify_cmp(const void *ap, const void *bp, void *dp)
363 Transaction *trans = dp;
364 Pool *pool = trans->pool;
374 return a[2] && b[2] ? strcmp(pool_id2str(pool, a[2]), pool_id2str(pool, b[2])) : r;
377 return a[3] && b[3] ? strcmp(pool_id2str(pool, a[3]), pool_id2str(pool, b[3])) : r;
382 classify_cmp_pkgs(const void *ap, const void *bp, void *dp)
384 Transaction *trans = dp;
385 Pool *pool = trans->pool;
390 sa = pool->solvables + a;
391 sb = pool->solvables + b;
392 if (sa->name != sb->name)
393 return strcmp(pool_id2str(pool, sa->name), pool_id2str(pool, sb->name));
394 if (sa->evr != sb->evr)
396 int r = pool_evrcmp(pool, sa->evr, sb->evr, EVRCMP_COMPARE);
404 transaction_classify(Transaction *trans, int mode, Queue *classes)
406 Pool *pool = trans->pool;
407 int ntypes[SOLVER_TRANSACTION_MAXTYPE + 1];
409 Id v, vq, type, p, q;
412 queue_empty(classes);
413 memset(ntypes, 0, sizeof(ntypes));
414 /* go through transaction and classify each step */
415 for (i = 0; i < trans->steps.count; i++)
417 p = trans->steps.elements[i];
418 s = pool->solvables + p;
419 type = transaction_type(trans, p, mode);
421 if (!pool->installed || s->repo != pool->installed)
423 /* don't report vendor/arch changes if we were mapped to erase. */
424 if (type == SOLVER_TRANSACTION_ERASE)
426 /* look at arch/vendor changes */
427 q = transaction_obs_pkg(trans, p);
430 sq = pool->solvables + q;
436 if ((mode & SOLVER_TRANSACTION_MERGE_ARCHCHANGES) != 0)
438 for (j = 0; j < classes->count; j += 4)
439 if (classes->elements[j] == SOLVER_TRANSACTION_ARCHCHANGE && classes->elements[j + 2] == v && classes->elements[j + 3] == vq)
441 if (j == classes->count)
443 queue_push(classes, SOLVER_TRANSACTION_ARCHCHANGE);
444 queue_push(classes, 1);
445 queue_push(classes, v);
446 queue_push(classes, vq);
449 classes->elements[j + 1]++;
452 v = s->vendor ? s->vendor : 1;
453 vq = sq->vendor ? sq->vendor : 1;
456 if ((mode & SOLVER_TRANSACTION_MERGE_VENDORCHANGES) != 0)
458 for (j = 0; j < classes->count; j += 4)
459 if (classes->elements[j] == SOLVER_TRANSACTION_VENDORCHANGE && classes->elements[j + 2] == v && classes->elements[j + 3] == vq)
461 if (j == classes->count)
463 queue_push(classes, SOLVER_TRANSACTION_VENDORCHANGE);
464 queue_push(classes, 1);
465 queue_push(classes, v);
466 queue_push(classes, vq);
469 classes->elements[j + 1]++;
472 /* now sort all vendor/arch changes */
473 if (classes->count > 4)
474 solv_sort(classes->elements, classes->count / 4, 4 * sizeof(Id), classify_cmp, trans);
475 /* finally add all classes. put erases last */
476 i = SOLVER_TRANSACTION_ERASE;
479 queue_unshift(classes, 0);
480 queue_unshift(classes, 0);
481 queue_unshift(classes, ntypes[i]);
482 queue_unshift(classes, i);
484 for (i = SOLVER_TRANSACTION_MAXTYPE; i > 0; i--)
488 if (i == SOLVER_TRANSACTION_ERASE)
490 queue_unshift(classes, 0);
491 queue_unshift(classes, 0);
492 queue_unshift(classes, ntypes[i]);
493 queue_unshift(classes, i);
498 transaction_classify_pkgs(Transaction *trans, int mode, Id class, Id from, Id to, Queue *pkgs)
500 Pool *pool = trans->pool;
506 for (i = 0; i < trans->steps.count; i++)
508 p = trans->steps.elements[i];
509 s = pool->solvables + p;
510 if (class <= SOLVER_TRANSACTION_MAXTYPE)
512 type = transaction_type(trans, p, mode);
517 if (!pool->installed || s->repo != pool->installed)
519 q = transaction_obs_pkg(trans, p);
522 sq = pool->solvables + q;
523 if (class == SOLVER_TRANSACTION_ARCHCHANGE)
525 if ((!from && !to) || (s->arch == from && sq->arch == to))
529 if (class == SOLVER_TRANSACTION_VENDORCHANGE)
531 Id v = s->vendor ? s->vendor : 1;
532 Id vq = sq->vendor ? sq->vendor : 1;
533 if ((!from && !to) || (v == from && vq == to))
539 solv_sort(pkgs->elements, pkgs->count, sizeof(Id), classify_cmp_pkgs, trans);
543 create_transaction_info(Transaction *trans, Queue *decisionq)
545 Pool *pool = trans->pool;
546 Queue *ti = &trans->transaction_info;
547 Repo *installed = pool->installed;
553 trans->transaction_installed = solv_free(trans->transaction_installed);
555 return; /* no info needed */
556 for (i = 0; i < decisionq->count; i++)
558 p = decisionq->elements[i];
559 if (p <= 0 || p == SYSTEMSOLVABLE)
561 s = pool->solvables + p;
562 if (!s->repo || s->repo == installed)
564 noobs = trans->noobsmap.size && MAPTST(&trans->noobsmap, p);
565 FOR_PROVIDES(p2, pp2, s->name)
567 if (!MAPTST(&trans->transactsmap, p2))
569 s2 = pool->solvables + p2;
570 if (s2->repo != installed)
572 if (noobs && (s->name != s2->name || s->evr != s2->evr || s->arch != s2->arch))
574 if (!pool->implicitobsoleteusesprovides && s->name != s2->name)
576 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, s2))
581 if (s->obsoletes && !noobs)
583 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
584 while ((obs = *obsp++) != 0)
586 FOR_PROVIDES(p2, pp2, obs)
588 s2 = pool->solvables + p2;
589 if (s2->repo != installed)
591 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p2, obs))
593 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, s2))
601 solv_sort(ti->elements, ti->count / 2, 2 * sizeof(Id), obsq_sortcmp, pool);
603 for (i = j = 0; i < ti->count; i += 2)
605 if (j && ti->elements[i] == ti->elements[j - 2] && ti->elements[i + 1] == ti->elements[j - 1])
607 ti->elements[j++] = ti->elements[i];
608 ti->elements[j++] = ti->elements[i + 1];
612 /* create transaction_installed helper */
613 trans->transaction_installed = solv_calloc(installed->end - installed->start, sizeof(Id));
614 for (i = 0; i < ti->count; i += 2)
616 j = ti->elements[i + 1] - installed->start;
617 if (!trans->transaction_installed[j])
618 trans->transaction_installed[j] = ti->elements[i];
621 /* more than one package obsoletes us. compare */
623 if (trans->transaction_installed[j] > 0)
624 trans->transaction_installed[j] = -trans->transaction_installed[j];
625 q[0] = q[2] = ti->elements[i + 1];
626 q[1] = ti->elements[i];
627 q[3] = -trans->transaction_installed[j];
628 if (obsq_sortcmp(q, q + 2, pool) < 0)
629 trans->transaction_installed[j] = -ti->elements[i];
636 transaction_create_decisionq(Pool *pool, Queue *decisionq, Map *noobsmap)
638 Repo *installed = pool->installed;
644 trans = transaction_create(pool);
645 if (noobsmap && !noobsmap->size)
646 noobsmap = 0; /* ignore empty map */
647 queue_empty(&trans->steps);
648 map_init(&trans->transactsmap, pool->nsolvables);
650 for (i = 0; i < decisionq->count; i++)
652 p = decisionq->elements[i];
653 s = pool->solvables + (p > 0 ? p : -p);
656 if (installed && s->repo == installed && p < 0)
657 MAPSET(&trans->transactsmap, -p);
658 if ((!installed || s->repo != installed) && p > 0)
661 const char *n = pool_id2str(pool, s->name);
662 if (!strncmp(n, "patch:", 6))
664 if (!strncmp(n, "pattern:", 8))
667 MAPSET(&trans->transactsmap, p);
668 if (noobsmap && MAPTST(noobsmap, p))
672 MAPCLR(&trans->transactsmap, SYSTEMSOLVABLE);
674 map_init_clone(&trans->noobsmap, noobsmap);
676 create_transaction_info(trans, decisionq);
680 FOR_REPO_SOLVABLES(installed, p, s)
682 if (MAPTST(&trans->transactsmap, p))
683 queue_push(&trans->steps, p);
686 for (i = 0; i < decisionq->count; i++)
688 p = decisionq->elements[i];
689 if (p > 0 && MAPTST(&trans->transactsmap, p))
690 queue_push(&trans->steps, p);
696 transaction_installedresult(Transaction *trans, Queue *installedq)
698 Pool *pool = trans->pool;
699 Repo *installed = pool->installed;
704 queue_empty(installedq);
705 /* first the new installs, than the kept packages */
706 for (i = 0; i < trans->steps.count; i++)
708 p = trans->steps.elements[i];
709 s = pool->solvables + p;
710 if (installed && s->repo == installed)
712 queue_push(installedq, p);
714 cutoff = installedq->count;
717 FOR_REPO_SOLVABLES(installed, p, s)
718 if (!MAPTST(&trans->transactsmap, p))
719 queue_push(installedq, p);
725 transaction_create_installedmap(Transaction *trans, Map *installedmap)
727 Pool *pool = trans->pool;
728 Repo *installed = pool->installed;
733 map_init(installedmap, pool->nsolvables);
734 for (i = 0; i < trans->steps.count; i++)
736 p = trans->steps.elements[i];
737 s = pool->solvables + p;
738 if (!installed || s->repo != installed)
739 MAPSET(installedmap, p);
743 FOR_REPO_SOLVABLES(installed, p, s)
744 if (!MAPTST(&trans->transactsmap, p))
745 MAPSET(installedmap, p);
750 transaction_calc_installsizechange(Transaction *trans)
755 transaction_create_installedmap(trans, &installedmap);
756 change = pool_calc_installsizechange(trans->pool, &installedmap);
757 map_free(&installedmap);
762 transaction_calc_duchanges(Transaction *trans, DUChanges *mps, int nmps)
766 transaction_create_installedmap(trans, &installedmap);
767 pool_calc_duchanges(trans->pool, &installedmap, mps, nmps);
768 map_free(&installedmap);
771 struct _TransactionElement {
772 Id p; /* solvable id */
773 Id edges; /* pointer into edges data */
777 struct _TransactionOrderdata {
778 struct _TransactionElement *tes;
784 #define TYPE_BROKEN (1<<0)
785 #define TYPE_CON (1<<1)
787 #define TYPE_REQ_P (1<<2)
788 #define TYPE_PREREQ_P (1<<3)
790 #define TYPE_REQ (1<<4)
791 #define TYPE_PREREQ (1<<5)
793 #define TYPE_CYCLETAIL (1<<16)
794 #define TYPE_CYCLEHEAD (1<<17)
796 #define EDGEDATA_BLOCK 127
799 transaction_create(Pool *pool)
801 Transaction *trans = solv_calloc(1, sizeof(*trans));
807 transaction_create_clone(Transaction *srctrans)
809 Transaction *trans = transaction_create(srctrans->pool);
810 queue_init_clone(&trans->steps, &srctrans->steps);
811 queue_init_clone(&trans->transaction_info, &srctrans->transaction_info);
812 if (srctrans->transaction_installed)
814 Repo *installed = srctrans->pool->installed;
815 trans->transaction_installed = solv_calloc(installed->end - installed->start, sizeof(Id));
816 memcpy(trans->transaction_installed, srctrans->transaction_installed, (installed->end - installed->start) * sizeof(Id));
818 map_init_clone(&trans->transactsmap, &srctrans->transactsmap);
819 map_init_clone(&trans->noobsmap, &srctrans->noobsmap);
820 if (srctrans->orderdata)
822 struct _TransactionOrderdata *od = srctrans->orderdata;
823 trans->orderdata = solv_calloc(1, sizeof(*trans->orderdata));
824 trans->orderdata->tes = solv_malloc2(od->ntes, sizeof(*od->tes));
825 memcpy(trans->orderdata->tes, od->tes, od->ntes * sizeof(*od->tes));
826 trans->orderdata->ntes = od->ntes;
827 trans->orderdata->invedgedata = solv_malloc2(od->ninvedgedata, sizeof(Id));
828 memcpy(trans->orderdata->invedgedata, od->invedgedata, od->ninvedgedata * sizeof(Id));
829 trans->orderdata->ninvedgedata = od->ninvedgedata;
835 transaction_free(Transaction *trans)
837 queue_free(&trans->steps);
838 queue_free(&trans->transaction_info);
839 trans->transaction_installed = solv_free(trans->transaction_installed);
840 map_free(&trans->transactsmap);
841 map_free(&trans->noobsmap);
842 transaction_free_orderdata(trans);
847 transaction_free_orderdata(Transaction *trans)
849 if (trans->orderdata)
851 struct _TransactionOrderdata *od = trans->orderdata;
852 od->tes = solv_free(od->tes);
853 od->invedgedata = solv_free(od->invedgedata);
854 trans->orderdata = solv_free(trans->orderdata);
860 struct _TransactionElement *tes;
872 addteedge(struct orderdata *od, int from, int to, int type)
875 struct _TransactionElement *te;
880 /* printf("edge %d(%s) -> %d(%s) type %x\n", from, pool_solvid2str(pool, od->tes[from].p), to, pool_solvid2str(pool, od->tes[to].p), type); */
883 for (i = te->edges; od->edgedata[i]; i += 2)
884 if (od->edgedata[i] == to)
886 /* test of brokenness */
887 if (type == TYPE_BROKEN)
888 return od->edgedata[i] && (od->edgedata[i + 1] & TYPE_BROKEN) != 0 ? 1 : 0;
891 od->edgedata[i + 1] |= type;
894 if (i + 1 == od->nedgedata)
896 /* printf("tail add %d\n", i - te->edges); */
899 od->edgedata = solv_extend(od->edgedata, od->nedgedata, 3, sizeof(Id), EDGEDATA_BLOCK);
903 /* printf("extend %d\n", i - te->edges); */
904 od->edgedata = solv_extend(od->edgedata, od->nedgedata, 3 + (i - te->edges), sizeof(Id), EDGEDATA_BLOCK);
906 memcpy(od->edgedata + od->nedgedata, od->edgedata + te->edges, sizeof(Id) * (i - te->edges));
907 i = od->nedgedata + (i - te->edges);
908 te->edges = od->nedgedata;
910 od->edgedata[i] = to;
911 od->edgedata[i + 1] = type;
912 od->edgedata[i + 2] = 0; /* end marker */
913 od->nedgedata = i + 3;
918 addedge(struct orderdata *od, Id from, Id to, int type)
920 Transaction *trans = od->trans;
921 Pool *pool = trans->pool;
923 struct _TransactionElement *te;
926 /* printf("addedge %d %d type %d\n", from, to, type); */
927 s = pool->solvables + from;
928 if (s->repo == pool->installed && trans->transaction_installed[from - pool->installed->start])
930 /* obsolete, map to install */
931 if (trans->transaction_installed[from - pool->installed->start] > 0)
932 from = trans->transaction_installed[from - pool->installed->start];
939 queue_init_buffer(&ti, tibuf, sizeof(tibuf)/sizeof(*tibuf));
940 transaction_all_obs_pkgs(trans, from, &ti);
941 for (i = 0; i < ti.count; i++)
942 ret |= addedge(od, ti.elements[i], to, type);
947 s = pool->solvables + to;
948 if (s->repo == pool->installed && trans->transaction_installed[to - pool->installed->start])
950 /* obsolete, map to install */
951 if (trans->transaction_installed[to - pool->installed->start] > 0)
952 to = trans->transaction_installed[to - pool->installed->start];
959 queue_init_buffer(&ti, tibuf, sizeof(tibuf)/sizeof(*tibuf));
960 transaction_all_obs_pkgs(trans, to, &ti);
961 for (i = 0; i < ti.count; i++)
962 ret |= addedge(od, from, ti.elements[i], type);
968 /* map from/to to te numbers */
969 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
976 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
982 return addteedge(od, i, to, type);
987 havechoice(struct orderdata *od, Id p, Id q1, Id q2)
989 Transaction *trans = od->trans;
990 Pool *pool = trans->pool;
991 Id ti1buf[5], ti2buf[5];
995 /* both q1 and q2 are uninstalls. check if their TEs intersect */
996 /* common case: just one TE for both packages */
998 printf("havechoice %d %d %d\n", p, q1, q2);
1000 if (trans->transaction_installed[q1 - pool->installed->start] == 0)
1002 if (trans->transaction_installed[q2 - pool->installed->start] == 0)
1004 if (trans->transaction_installed[q1 - pool->installed->start] == trans->transaction_installed[q2 - pool->installed->start])
1006 if (trans->transaction_installed[q1 - pool->installed->start] > 0 && trans->transaction_installed[q2 - pool->installed->start] > 0)
1008 queue_init_buffer(&ti1, ti1buf, sizeof(ti1buf)/sizeof(*ti1buf));
1009 transaction_all_obs_pkgs(trans, q1, &ti1);
1010 queue_init_buffer(&ti2, ti2buf, sizeof(ti2buf)/sizeof(*ti2buf));
1011 transaction_all_obs_pkgs(trans, q2, &ti2);
1012 for (i = 0; i < ti1.count; i++)
1013 for (j = 0; j < ti2.count; j++)
1014 if (ti1.elements[i] == ti2.elements[j])
1016 /* found a common edge */
1028 havescripts(Pool *pool, Id solvid)
1030 Solvable *s = pool->solvables + solvid;
1036 reqp = s->repo->idarraydata + s->requires;
1037 while ((req = *reqp++) != 0)
1039 if (req == SOLVABLE_PREREQMARKER)
1046 dep = pool_id2str(pool, req);
1047 if (*dep == '/' && strcmp(dep, "/sbin/ldconfig") != 0)
1055 addsolvableedges(struct orderdata *od, Solvable *s)
1057 Transaction *trans = od->trans;
1058 Pool *pool = trans->pool;
1059 Id req, *reqp, con, *conp;
1061 int i, j, pre, numins;
1062 Repo *installed = pool->installed;
1068 printf("addsolvableedges %s\n", pool_solvable2str(pool, s));
1070 p = s - pool->solvables;
1074 reqp = s->repo->idarraydata + s->requires;
1076 while ((req = *reqp++) != 0)
1078 if (req == SOLVABLE_PREREQMARKER)
1084 if (pre != TYPE_PREREQ && installed && s->repo == installed)
1086 /* ignore normal requires if we're getting obsoleted */
1087 if (trans->transaction_installed[p - pool->installed->start])
1092 numins = 0; /* number of packages to be installed providing it */
1093 provbyinst = 0; /* provided by kept package */
1094 FOR_PROVIDES(p2, pp2, req)
1096 s2 = pool->solvables + p2;
1099 reqq.count = 0; /* self provides */
1102 if (s2->repo == installed && !MAPTST(&trans->transactsmap, p2))
1106 printf("IGNORE inst provides %s by %s\n", pool_dep2str(pool, req), pool_solvable2str(pool, s2));
1107 reqq.count = 0; /* provided by package that stays installed */
1113 if (s2->repo != installed && !MAPTST(&trans->transactsmap, p2))
1114 continue; /* package stays uninstalled */
1116 if (s->repo == installed)
1118 /* s gets uninstalled */
1119 queue_pushunique(&reqq, p2);
1120 if (s2->repo != installed)
1125 if (s2->repo == installed)
1126 continue; /* s2 gets uninstalled */
1127 queue_pushunique(&reqq, p2);
1132 /* prune to harmless ->inst edges */
1133 for (i = j = 0; i < reqq.count; i++)
1134 if (pool->solvables[reqq.elements[i]].repo != installed)
1135 reqq.elements[j++] = reqq.elements[i];
1139 if (numins && reqq.count)
1141 if (s->repo == installed)
1143 for (i = 0; i < reqq.count; i++)
1145 if (pool->solvables[reqq.elements[i]].repo == installed)
1147 for (j = 0; j < reqq.count; j++)
1149 if (pool->solvables[reqq.elements[j]].repo != installed)
1151 if (trans->transaction_installed[reqq.elements[i] - pool->installed->start] == reqq.elements[j])
1152 continue; /* no self edge */
1154 printf("add interrreq uninst->inst edge (%s -> %s -> %s)\n", pool_solvid2str(pool, reqq.elements[i]), pool_dep2str(pool, req), pool_solvid2str(pool, reqq.elements[j]));
1156 addedge(od, reqq.elements[i], reqq.elements[j], pre == TYPE_PREREQ ? TYPE_PREREQ_P : TYPE_REQ_P);
1162 /* no mixed types, remove all deps on uninstalls */
1163 for (i = j = 0; i < reqq.count; i++)
1164 if (pool->solvables[reqq.elements[i]].repo != installed)
1165 reqq.elements[j++] = reqq.elements[i];
1170 for (i = 0; i < reqq.count; i++)
1173 p2 = reqq.elements[i];
1174 if (pool->solvables[p2].repo != installed)
1176 /* all elements of reqq are installs, thus have different TEs */
1177 choice = reqq.count - 1;
1178 if (pool->solvables[p].repo != installed)
1181 printf("add inst->inst edge choice %d (%s -> %s -> %s)\n", choice, pool_solvid2str(pool, p), pool_dep2str(pool, req), pool_solvid2str(pool, p2));
1183 addedge(od, p, p2, pre);
1188 printf("add uninst->inst edge choice %d (%s -> %s -> %s)\n", choice, pool_solvid2str(pool, p), pool_dep2str(pool, req), pool_solvid2str(pool, p2));
1190 addedge(od, p, p2, pre == TYPE_PREREQ ? TYPE_PREREQ_P : TYPE_REQ_P);
1195 if (s->repo != installed)
1196 continue; /* no inst->uninst edges, please! */
1198 /* uninst -> uninst edge. Those make trouble. Only add if we must */
1199 if (trans->transaction_installed[p - installed->start] && !havescripts(pool, p))
1201 /* p is obsoleted by another package and has no scripts */
1202 /* we assume that the obsoletor is good enough to replace p */
1207 for (j = 0; j < reqq.count; j++)
1211 if (havechoice(od, p, reqq.elements[i], reqq.elements[j]))
1216 printf("add uninst->uninst edge choice %d (%s -> %s -> %s)\n", choice, pool_solvid2str(pool, p), pool_dep2str(pool, req), pool_solvid2str(pool, p2));
1218 addedge(od, p2, p, pre == TYPE_PREREQ ? TYPE_PREREQ_P : TYPE_REQ_P);
1225 conp = s->repo->idarraydata + s->conflicts;
1226 while ((con = *conp++) != 0)
1228 FOR_PROVIDES(p2, pp2, con)
1232 s2 = pool->solvables + p2;
1235 if (s->repo == installed)
1237 if (s2->repo != installed && MAPTST(&trans->transactsmap, p2))
1239 /* deinstall p before installing p2 */
1241 printf("add conflict uninst->inst edge (%s -> %s -> %s)\n", pool_solvid2str(pool, p2), pool_dep2str(pool, con), pool_solvid2str(pool, p));
1243 addedge(od, p2, p, TYPE_CON);
1248 if (s2->repo == installed && MAPTST(&trans->transactsmap, p2))
1250 /* deinstall p2 before installing p */
1252 printf("add conflict uninst->inst edge (%s -> %s -> %s)\n", pool_solvid2str(pool, p), pool_dep2str(pool, con), pool_solvid2str(pool, p2));
1254 addedge(od, p, p2, TYPE_CON);
1261 if (s->repo == installed && solvable_lookup_idarray(s, SOLVABLE_TRIGGERS, &reqq) && reqq.count)
1263 /* we're getting deinstalled/updated. Try to do this before our
1264 * triggers are hit */
1265 for (i = 0; i < reqq.count; i++)
1267 Id tri = reqq.elements[i];
1268 FOR_PROVIDES(p2, pp2, tri)
1272 s2 = pool->solvables + p2;
1275 if (s2->name == s->name)
1276 continue; /* obsoleted anyway */
1277 if (s2->repo != installed && MAPTST(&trans->transactsmap, p2))
1279 /* deinstall/update p before installing p2 */
1281 printf("add trigger uninst->inst edge (%s -> %s -> %s)\n", pool_solvid2str(pool, p2), pool_dep2str(pool, tri), pool_solvid2str(pool, p));
1283 addedge(od, p2, p, TYPE_CON);
1292 /* break an edge in a cycle */
1294 breakcycle(struct orderdata *od, Id *cycle)
1296 Pool *pool = od->trans->pool;
1297 Id ddegmin, ddegmax, ddeg;
1299 struct _TransactionElement *te;
1302 ddegmin = ddegmax = 0;
1303 for (k = 0; cycle[k + 1]; k += 2)
1305 ddeg = od->edgedata[cycle[k + 1] + 1];
1308 if (!k || ddeg < ddegmin)
1314 if (ddeg == ddegmin)
1316 if (havescripts(pool, od->tes[cycle[l]].p) && !havescripts(pool, od->tes[cycle[k]].p))
1318 /* prefer k, as l comes from a package with contains scriptlets */
1323 /* same edge value, check for prereq */
1327 /* record brkoen cycle starting with the tail */
1328 queue_push(&od->cycles, od->cyclesdata.count); /* offset into data */
1329 queue_push(&od->cycles, k / 2); /* cycle elements */
1330 queue_push(&od->cycles, od->edgedata[cycle[l + 1] + 1]); /* broken edge */
1337 queue_push(&od->cyclesdata, cycle[k]);
1341 queue_push(&od->cyclesdata, 0); /* mark end */
1343 /* break that edge */
1344 od->edgedata[cycle[l + 1] + 1] |= TYPE_BROKEN;
1347 if (ddegmin < TYPE_REQ)
1351 /* cycle recorded, print it */
1352 if (ddegmin >= TYPE_REQ && (ddegmax & TYPE_PREREQ) != 0)
1353 POOL_DEBUG(SOLV_DEBUG_STATS, "CRITICAL ");
1354 POOL_DEBUG(SOLV_DEBUG_STATS, "cycle: --> ");
1355 for (k = 0; cycle[k + 1]; k += 2)
1357 te = od->tes + cycle[k];
1358 if ((od->edgedata[cycle[k + 1] + 1] & TYPE_BROKEN) != 0)
1359 POOL_DEBUG(SOLV_DEBUG_STATS, "%s ##%x##> ", pool_solvid2str(pool, te->p), od->edgedata[cycle[k + 1] + 1]);
1361 POOL_DEBUG(SOLV_DEBUG_STATS, "%s --%x--> ", pool_solvid2str(pool, te->p), od->edgedata[cycle[k + 1] + 1]);
1363 POOL_DEBUG(SOLV_DEBUG_STATS, "\n");
1367 dump_tes(struct orderdata *od)
1369 Pool *pool = od->trans->pool;
1372 struct _TransactionElement *te, *te2;
1375 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1377 Solvable *s = pool->solvables + te->p;
1378 POOL_DEBUG(SOLV_DEBUG_RESULT, "TE %4d: %c%s\n", i, s->repo == pool->installed ? '-' : '+', pool_solvable2str(pool, s));
1379 if (s->repo != pool->installed)
1382 transaction_all_obs_pkgs(od->trans, te->p, &obsq);
1383 for (j = 0; j < obsq.count; j++)
1384 POOL_DEBUG(SOLV_DEBUG_RESULT, " -%s\n", pool_solvid2str(pool, obsq.elements[j]));
1386 for (j = te->edges; od->edgedata[j]; j += 2)
1388 te2 = od->tes + od->edgedata[j];
1389 if ((od->edgedata[j + 1] & TYPE_BROKEN) == 0)
1390 POOL_DEBUG(SOLV_DEBUG_RESULT, " --%x--> TE %4d: %s\n", od->edgedata[j + 1], od->edgedata[j], pool_solvid2str(pool, te2->p));
1392 POOL_DEBUG(SOLV_DEBUG_RESULT, " ##%x##> TE %4d: %s\n", od->edgedata[j + 1], od->edgedata[j], pool_solvid2str(pool, te2->p));
1399 reachable(struct orderdata *od, Id i)
1401 struct _TransactionElement *te = od->tes + i;
1407 for (j = te->edges; (k = od->edgedata[j]) != 0; j += 2)
1409 if ((od->edgedata[j + 1] & TYPE_BROKEN) != 0)
1411 if (!od->tes[k].mark)
1413 if (od->tes[k].mark == 2)
1424 addcycleedges(struct orderdata *od, Id *cycle, Queue *todo)
1427 Transaction *trans = od->trans;
1428 Pool *pool = trans->pool;
1430 struct _TransactionElement *te;
1437 printf("addcycleedges\n");
1438 for (i = 0; (j = cycle[i]) != 0; i++)
1439 printf("cycle %s\n", pool_solvid2str(pool, od->tes[j].p));
1442 /* first add all the tail cycle edges */
1444 /* see what we can reach from the cycle */
1446 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1448 for (i = 0; (j = cycle[i]) != 0; i++)
1450 od->tes[j].mark = -1;
1451 queue_push(todo, j);
1455 i = queue_pop(todo);
1459 te->mark = te->mark < 0 ? 2 : 1;
1460 for (j = te->edges; (k = od->edgedata[j]) != 0; j += 2)
1462 if ((od->edgedata[j + 1] & TYPE_BROKEN) != 0)
1464 if (od->tes[k].mark > 0)
1465 continue; /* no need to visit again */
1466 queue_push(todo, k);
1469 /* now all cycle TEs are marked with 2, all TEs reachable
1470 * from the cycle are marked with 1 */
1472 od->tes[tail].mark = 1; /* no need to add edges */
1474 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1477 continue; /* reachable from cycle */
1478 for (j = te->edges; (k = od->edgedata[j]) != 0; j += 2)
1480 if ((od->edgedata[j + 1] & TYPE_BROKEN) != 0)
1482 if (od->tes[k].mark != 2)
1484 /* We found an edge to the cycle. Add an extra edge to the tail */
1485 /* the TE was not reachable, so we're not creating a new cycle! */
1487 printf("adding TO TAIL cycle edge %d->%d %s->%s!\n", i, tail, pool_solvid2str(pool, od->tes[i].p), pool_solvid2str(pool, od->tes[tail].p));
1489 j -= te->edges; /* in case we move */
1490 addteedge(od, i, tail, TYPE_CYCLETAIL);
1492 break; /* one edge is enough */
1497 /* now add all head cycle edges */
1500 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1503 for (i = 0; (j = cycle[i]) != 0; i++)
1506 od->tes[j].mark = 2;
1508 /* first the head to save some time */
1509 te = od->tes + head;
1510 for (j = te->edges; (k = od->edgedata[j]) != 0; j += 2)
1512 if ((od->edgedata[j + 1] & TYPE_BROKEN) != 0)
1514 if (!od->tes[k].mark)
1516 if (od->tes[k].mark == -1)
1517 od->tes[k].mark = -2; /* no need for another edge */
1519 for (i = 0; cycle[i] != 0; i++)
1521 if (cycle[i] == head)
1523 te = od->tes + cycle[i];
1524 for (j = te->edges; (k = od->edgedata[j]) != 0; j += 2)
1526 if ((od->edgedata[j + 1] & TYPE_BROKEN) != 0)
1528 /* see if we can reach a cycle TE from k */
1529 if (!od->tes[k].mark)
1531 if (od->tes[k].mark == -1)
1534 printf("adding FROM HEAD cycle edge %d->%d %s->%s [%s]!\n", head, k, pool_solvid2str(pool, od->tes[head].p), pool_solvid2str(pool, od->tes[k].p), pool_solvid2str(pool, od->tes[cycle[i]].p));
1536 addteedge(od, head, k, TYPE_CYCLEHEAD);
1537 od->tes[k].mark = -2; /* no need to add that one again */
1545 transaction_order(Transaction *trans, int flags)
1547 Pool *pool = trans->pool;
1548 Queue *tr = &trans->steps;
1549 Repo *installed = pool->installed;
1552 int i, j, k, numte, numedge;
1553 struct orderdata od;
1554 struct _TransactionElement *te;
1555 Queue todo, obsq, samerepoq, uninstq;
1556 int cycstart, cycel;
1564 start = now = solv_timems(0);
1565 POOL_DEBUG(SOLV_DEBUG_STATS, "ordering transaction\n");
1566 /* free old data if present */
1567 if (trans->orderdata)
1569 struct _TransactionOrderdata *od = trans->orderdata;
1570 od->tes = solv_free(od->tes);
1571 od->invedgedata = solv_free(od->invedgedata);
1572 trans->orderdata = solv_free(trans->orderdata);
1575 /* create a transaction element for every active component */
1577 for (i = 0; i < tr->count; i++)
1579 p = tr->elements[i];
1580 s = pool->solvables + p;
1581 if (installed && s->repo == installed && trans->transaction_installed[p - installed->start])
1585 POOL_DEBUG(SOLV_DEBUG_STATS, "transaction elements: %d\n", numte);
1587 return; /* nothing to do... */
1589 numte++; /* leave first one zero */
1590 memset(&od, 0, sizeof(od));
1593 od.tes = solv_calloc(numte, sizeof(*od.tes));
1594 od.edgedata = solv_extend(0, 0, 1, sizeof(Id), EDGEDATA_BLOCK);
1597 queue_init(&od.cycles);
1599 /* initialize TEs */
1600 for (i = 0, te = od.tes + 1; i < tr->count; i++)
1602 p = tr->elements[i];
1603 s = pool->solvables + p;
1604 if (installed && s->repo == installed && trans->transaction_installed[p - installed->start])
1610 /* create dependency graph */
1611 for (i = 0; i < tr->count; i++)
1612 addsolvableedges(&od, pool->solvables + tr->elements[i]);
1616 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1617 for (j = te->edges; od.edgedata[j]; j += 2)
1619 POOL_DEBUG(SOLV_DEBUG_STATS, "edges: %d, edge space: %d\n", numedge, od.nedgedata / 2);
1620 POOL_DEBUG(SOLV_DEBUG_STATS, "edge creation took %d ms\n", solv_timems(now));
1626 now = solv_timems(0);
1627 /* kill all cycles */
1629 for (i = numte - 1; i > 0; i--)
1630 queue_push(&todo, i);
1634 i = queue_pop(&todo);
1635 /* printf("- look at TE %d\n", i); */
1639 od.tes[i].mark = 2; /* done with that one */
1644 continue; /* already finished before */
1647 int edgestovisit = 0;
1648 /* new node, visit edges */
1649 for (j = te->edges; (k = od.edgedata[j]) != 0; j += 2)
1651 if ((od.edgedata[j + 1] & TYPE_BROKEN) != 0)
1653 if (od.tes[k].mark == 2)
1654 continue; /* no need to visit again */
1655 if (!edgestovisit++)
1656 queue_push(&todo, -i); /* end of edges marker */
1657 queue_push(&todo, k);
1660 te->mark = 2; /* no edges, done with that one */
1662 te->mark = 1; /* under investigation */
1665 /* oh no, we found a cycle */
1666 /* find start of cycle node (<0) */
1667 for (j = todo.count - 1; j >= 0; j--)
1668 if (todo.elements[j] == -i)
1672 /* build te/edge chain */
1674 for (j = k; j < todo.count; j++)
1675 if (todo.elements[j] < 0)
1676 todo.elements[k++] = -todo.elements[j];
1677 cycel = k - cycstart;
1679 /* make room for edges, two extra element for cycle loop + terminating 0 */
1680 while (todo.count < cycstart + 2 * cycel + 2)
1681 queue_push(&todo, 0);
1682 cycle = todo.elements + cycstart;
1683 cycle[cycel] = i; /* close the loop */
1684 cycle[2 * cycel + 1] = 0; /* terminator */
1685 for (k = cycel; k > 0; k--)
1687 cycle[k * 2] = cycle[k];
1688 te = od.tes + cycle[k - 1];
1689 assert(te->mark == 1);
1690 te->mark = 0; /* reset investigation marker */
1691 /* printf("searching for edge from %d to %d\n", cycle[k - 1], cycle[k]); */
1692 for (j = te->edges; od.edgedata[j]; j += 2)
1693 if (od.edgedata[j] == cycle[k])
1695 assert(od.edgedata[j]);
1696 cycle[k * 2 - 1] = j;
1698 /* now cycle looks like this: */
1699 /* te1 edge te2 edge te3 ... teN edge te1 0 */
1700 breakcycle(&od, cycle);
1701 /* restart with start of cycle */
1702 todo.count = cycstart + 1;
1704 POOL_DEBUG(SOLV_DEBUG_STATS, "cycles broken: %d\n", od.ncycles);
1705 POOL_DEBUG(SOLV_DEBUG_STATS, "cycle breaking took %d ms\n", solv_timems(now));
1707 now = solv_timems(0);
1708 /* now go through all broken cycles and create cycle edges to help
1710 for (i = od.cycles.count - 3; i >= 0; i -= 3)
1712 if (od.cycles.elements[i + 2] >= TYPE_REQ)
1713 addcycleedges(&od, od.cyclesdata.elements + od.cycles.elements[i], &todo);
1715 for (i = od.cycles.count - 3; i >= 0; i -= 3)
1717 if (od.cycles.elements[i + 2] < TYPE_REQ)
1718 addcycleedges(&od, od.cyclesdata.elements + od.cycles.elements[i], &todo);
1720 POOL_DEBUG(SOLV_DEBUG_STATS, "cycle edge creation took %d ms\n", solv_timems(now));
1725 /* all edges are finally set up and there are no cycles, now the easy part.
1726 * Create an ordered transaction */
1727 now = solv_timems(0);
1728 /* first invert all edges */
1729 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1730 te->mark = 1; /* term 0 */
1731 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1733 for (j = te->edges; od.edgedata[j]; j += 2)
1735 if ((od.edgedata[j + 1] & TYPE_BROKEN) != 0)
1737 od.tes[od.edgedata[j]].mark++;
1741 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1746 POOL_DEBUG(SOLV_DEBUG_STATS, "invedge space: %d\n", j + 1);
1747 od.invedgedata = solv_calloc(j + 1, sizeof(Id));
1748 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1750 for (j = te->edges; od.edgedata[j]; j += 2)
1752 if ((od.edgedata[j + 1] & TYPE_BROKEN) != 0)
1754 od.invedgedata[--od.tes[od.edgedata[j]].mark] = i;
1757 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1758 te->edges = te->mark; /* edges now points into invedgedata */
1759 od.edgedata = solv_free(od.edgedata);
1760 od.nedgedata = j + 1;
1762 /* now the final ordering */
1763 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1765 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1766 for (j = te->edges; od.invedgedata[j]; j++)
1767 od.tes[od.invedgedata[j]].mark++;
1769 queue_init(&samerepoq);
1770 queue_init(&uninstq);
1772 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1775 if (installed && pool->solvables[te->p].repo == installed)
1776 queue_push(&uninstq, i);
1778 queue_push(&todo, i);
1780 assert(todo.count > 0 || uninstq.count > 0);
1781 oldcount = tr->count;
1788 temedianr = solv_calloc(numte, sizeof(Id));
1789 for (i = 1; i < numte; i++)
1791 Solvable *s = pool->solvables + od.tes[i].p;
1792 if (installed && s->repo == installed)
1795 j = solvable_lookup_num(s, SOLVABLE_MEDIANR, 1);
1800 /* select an TE i */
1802 i = queue_shift(&uninstq);
1803 else if (samerepoq.count)
1804 i = queue_shift(&samerepoq);
1805 else if (todo.count)
1807 /* find next repo/media */
1808 for (j = 0; j < todo.count; j++)
1810 if (!j || temedianr[todo.elements[j]] < lastmedia)
1813 lastmedia = temedianr[todo.elements[j]];
1816 lastrepo = pool->solvables[od.tes[todo.elements[i]].p].repo;
1818 /* move all matching TEs to samerepoq */
1819 for (i = j = 0; j < todo.count; j++)
1821 int k = todo.elements[j];
1822 if (temedianr[k] == lastmedia && pool->solvables[od.tes[k].p].repo == lastrepo)
1823 queue_push(&samerepoq, k);
1825 todo.elements[i++] = k;
1829 assert(samerepoq.count);
1830 i = queue_shift(&samerepoq);
1836 queue_push(tr, te->p);
1838 printf("do %s [%d]\n", pool_solvid2str(pool, te->p), temedianr[i]);
1840 s = pool->solvables + te->p;
1841 for (j = te->edges; od.invedgedata[j]; j++)
1843 struct _TransactionElement *te2 = od.tes + od.invedgedata[j];
1844 assert(te2->mark > 0);
1845 if (--te2->mark == 0)
1847 Solvable *s = pool->solvables + te2->p;
1849 printf("free %s [%d]\n", pool_solvid2str(pool, te2->p), temedianr[od.invedgedata[j]]);
1851 if (installed && s->repo == installed)
1852 queue_push(&uninstq, od.invedgedata[j]);
1853 else if (s->repo == lastrepo && temedianr[od.invedgedata[j]] == lastmedia)
1854 queue_push(&samerepoq, od.invedgedata[j]);
1856 queue_push(&todo, od.invedgedata[j]);
1860 solv_free(temedianr);
1862 queue_free(&samerepoq);
1863 queue_free(&uninstq);
1865 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1866 assert(te->mark == 0);
1868 /* add back obsoleted packages */
1869 transaction_add_obsoleted(trans);
1870 assert(tr->count == oldcount);
1872 POOL_DEBUG(SOLV_DEBUG_STATS, "creating new transaction took %d ms\n", solv_timems(now));
1873 POOL_DEBUG(SOLV_DEBUG_STATS, "transaction ordering took %d ms\n", solv_timems(start));
1875 if ((flags & SOLVER_TRANSACTION_KEEP_ORDERDATA) != 0)
1877 trans->orderdata = solv_calloc(1, sizeof(*trans->orderdata));
1878 trans->orderdata->tes = od.tes;
1879 trans->orderdata->ntes = numte;
1880 trans->orderdata->invedgedata = od.invedgedata;
1881 trans->orderdata->ninvedgedata = od.nedgedata;
1886 solv_free(od.invedgedata);
1888 queue_free(&od.cycles);
1889 queue_free(&od.cyclesdata);
1894 transaction_order_add_choices(Transaction *trans, Id chosen, Queue *choices)
1897 struct _TransactionOrderdata *od = trans->orderdata;
1898 struct _TransactionElement *te;
1901 return choices->count;
1904 /* initialization step */
1905 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1907 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1909 for (j = te->edges; od->invedgedata[j]; j++)
1910 od->tes[od->invedgedata[j]].mark++;
1912 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1914 queue_push(choices, te->p);
1915 return choices->count;
1917 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1918 if (te->p == chosen)
1921 return choices->count;
1924 /* hey! out-of-order installation! */
1927 for (j = te->edges; od->invedgedata[j]; j++)
1929 te = od->tes + od->invedgedata[j];
1930 assert(te->mark > 0 || te->mark == -1);
1931 if (te->mark > 0 && --te->mark == 0)
1932 queue_push(choices, te->p);
1934 return choices->count;
1938 transaction_add_obsoleted(Transaction *trans)
1940 Pool *pool = trans->pool;
1941 Repo *installed = pool->installed;
1948 if (!installed || !trans->steps.count)
1950 /* calculate upper bound */
1952 FOR_REPO_SOLVABLES(installed, p, s)
1953 if (MAPTST(&trans->transactsmap, p))
1958 steps = &trans->steps;
1959 queue_insertn(steps, 0, max);
1962 map_init(&done, installed->end - installed->start);
1964 for (j = 0, i = max; i < steps->count; i++)
1966 p = trans->steps.elements[i];
1967 if (pool->solvables[p].repo == installed)
1969 if (!trans->transaction_installed[p - pool->installed->start])
1970 trans->steps.elements[j++] = p;
1973 trans->steps.elements[j++] = p;
1975 transaction_all_obs_pkgs(trans, p, &obsq);
1976 for (k = 0; k < obsq.count; k++)
1978 p = obsq.elements[k];
1979 assert(p >= installed->start && p < installed->end);
1980 if (MAPTST(&done, p - installed->start))
1982 MAPSET(&done, p - installed->start);
1983 trans->steps.elements[j++] = p;
1987 /* free unneeded space */
1988 queue_truncate(steps, j);
1994 transaction_check_pkg(Transaction *trans, Id tepkg, Id pkg, Map *ins, Map *seen, int onlyprereq, Id noconfpkg, int depth)
1996 Pool *pool = trans->pool;
2001 if (MAPTST(seen, pkg))
2004 s = pool->solvables + pkg;
2006 printf("- %*s%c%s\n", depth * 2, "", s->repo == pool->installed ? '-' : '+', pool_solvable2str(pool, s));
2012 reqp = s->repo->idarraydata + s->requires;
2013 while ((req = *reqp++) != 0)
2015 if (req == SOLVABLE_PREREQMARKER)
2020 if (onlyprereq && !inpre)
2022 if (!strncmp(pool_id2str(pool, req), "rpmlib(", 7))
2025 /* first check kept packages, then freshly installed, then not yet uninstalled */
2026 FOR_PROVIDES(p, pp, req)
2028 if (!MAPTST(ins, p))
2030 if (MAPTST(&trans->transactsmap, p))
2033 transaction_check_pkg(trans, tepkg, p, ins, seen, 0, noconfpkg, depth + 1);
2037 FOR_PROVIDES(p, pp, req)
2039 if (!MAPTST(ins, p))
2041 if (pool->solvables[p].repo == pool->installed)
2044 transaction_check_pkg(trans, tepkg, p, ins, seen, 0, noconfpkg, depth + 1);
2049 FOR_PROVIDES(p, pp, req)
2051 if (!MAPTST(ins, p))
2054 transaction_check_pkg(trans, tepkg, p, ins, seen, 0, noconfpkg, depth + 1);
2059 POOL_DEBUG(SOLV_DEBUG_RESULT, " %c%s: nothing provides %s needed by %c%s\n", pool->solvables[tepkg].repo == pool->installed ? '-' : '+', pool_solvid2str(pool, tepkg), pool_dep2str(pool, req), s->repo == pool->installed ? '-' : '+', pool_solvable2str(pool, s));
2066 transaction_check_order(Transaction *trans)
2068 Pool *pool = trans->pool;
2074 POOL_DEBUG(SOLV_WARN, "\nchecking transaction order...\n");
2075 map_init(&ins, pool->nsolvables);
2076 map_init(&seen, pool->nsolvables);
2077 if (pool->installed)
2078 FOR_REPO_SOLVABLES(pool->installed, p, s)
2081 for (i = 0; i < trans->steps.count; i++)
2083 p = trans->steps.elements[i];
2084 s = pool->solvables + p;
2085 if (s->repo != pool->installed)
2087 if (s->repo != pool->installed)
2089 if (havescripts(pool, p))
2092 transaction_check_pkg(trans, p, p, &ins, &seen, 1, lastins, 0);
2094 if (s->repo == pool->installed)
2099 POOL_DEBUG(SOLV_WARN, "transaction order check done.\n");