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];
80 /* only a single obsoleting package */
84 /* find which packages obsolete us */
85 for (i = 0; i < ti->count; i += 2)
86 if (ti->elements[i + 1] == p)
87 queue_push2(pkgs, p, ti->elements[i]);
90 solv_sort(pkgs->elements, pkgs->count / 2, 2 * sizeof(Id), obsq_sortcmp, pool);
91 for (i = 0; i < pkgs->count; i += 2)
92 pkgs->elements[i / 2] = pkgs->elements[i + 1];
93 queue_truncate(pkgs, pkgs->count / 2);
97 /* find the packages we obsolete */
98 for (i = 0; i < ti->count; i += 2)
100 if (ti->elements[i] == p)
101 queue_push(pkgs, ti->elements[i + 1]);
102 else if (pkgs->count)
109 transaction_obs_pkg(Transaction *trans, Id p)
111 Pool *pool = trans->pool;
112 Solvable *s = pool->solvables + p;
116 if (p <= 0 || !s->repo)
118 if (s->repo == pool->installed)
120 p = trans->transaction_installed[p - pool->installed->start];
121 return p < 0 ? -p : p;
123 ti = &trans->transaction_info;
124 for (i = 0; i < ti->count; i += 2)
125 if (ti->elements[i] == p)
126 return ti->elements[i + 1];
132 * calculate base type of transaction element
136 transaction_base_type(Transaction *trans, Id p)
138 Pool *pool = trans->pool;
143 if (!MAPTST(&trans->transactsmap, p))
144 return SOLVER_TRANSACTION_IGNORE;
145 p2 = transaction_obs_pkg(trans, p);
146 if (pool->installed && pool->solvables[p].repo == pool->installed)
150 return SOLVER_TRANSACTION_ERASE;
151 s = pool->solvables + p;
152 s2 = pool->solvables + p2;
153 if (s->name == s2->name)
155 if (s->evr == s2->evr && solvable_identical(s, s2))
156 return SOLVER_TRANSACTION_REINSTALLED;
157 r = pool_evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
159 return SOLVER_TRANSACTION_UPGRADED;
161 return SOLVER_TRANSACTION_DOWNGRADED;
162 return SOLVER_TRANSACTION_CHANGED;
164 return SOLVER_TRANSACTION_OBSOLETED;
168 int multi = trans->multiversionmap.size && MAPTST(&trans->multiversionmap, p);
170 return p2 ? SOLVER_TRANSACTION_MULTIREINSTALL : SOLVER_TRANSACTION_MULTIINSTALL;
172 return SOLVER_TRANSACTION_INSTALL;
173 s = pool->solvables + p;
174 s2 = pool->solvables + p2;
175 if (s->name == s2->name)
177 if (s->evr == s2->evr && solvable_identical(s, s2))
178 return SOLVER_TRANSACTION_REINSTALL;
179 r = pool_evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
181 return SOLVER_TRANSACTION_UPGRADE;
183 return SOLVER_TRANSACTION_DOWNGRADE;
185 return SOLVER_TRANSACTION_CHANGE;
187 return SOLVER_TRANSACTION_OBSOLETES;
192 * return type of transaction element
194 * filtering is needed if either not all packages are shown
195 * or replaces are not shown, as otherwise parts of the
196 * transaction might not be shown to the user */
199 transaction_type(Transaction *trans, Id p, int mode)
201 Pool *pool = trans->pool;
202 Solvable *s = pool->solvables + p;
208 return SOLVER_TRANSACTION_IGNORE;
210 /* XXX: SUSE only? */
211 if (!(mode & SOLVER_TRANSACTION_KEEP_PSEUDO))
213 const char *n = pool_id2str(pool, s->name);
214 if (!strncmp(n, "patch:", 6))
215 return SOLVER_TRANSACTION_IGNORE;
216 if (!strncmp(n, "pattern:", 8))
217 return SOLVER_TRANSACTION_IGNORE;
220 type = transaction_base_type(trans, p);
222 if (type == SOLVER_TRANSACTION_IGNORE)
223 return SOLVER_TRANSACTION_IGNORE; /* not part of the transaction */
225 if ((mode & SOLVER_TRANSACTION_RPM_ONLY) != 0)
227 /* application wants to know what to feed to rpm */
228 if (type == SOLVER_TRANSACTION_ERASE || type == SOLVER_TRANSACTION_INSTALL || type == SOLVER_TRANSACTION_MULTIINSTALL)
230 if (s->repo == pool->installed)
231 return SOLVER_TRANSACTION_IGNORE; /* ignore as we're being obsoleted */
232 if (type == SOLVER_TRANSACTION_MULTIREINSTALL)
233 return SOLVER_TRANSACTION_MULTIINSTALL;
234 return SOLVER_TRANSACTION_INSTALL;
237 if ((mode & SOLVER_TRANSACTION_SHOW_MULTIINSTALL) == 0)
239 /* application wants to make no difference between install
240 * and multiinstall */
241 if (type == SOLVER_TRANSACTION_MULTIINSTALL)
242 type = SOLVER_TRANSACTION_INSTALL;
243 if (type == SOLVER_TRANSACTION_MULTIREINSTALL)
244 type = SOLVER_TRANSACTION_REINSTALL;
247 if ((mode & SOLVER_TRANSACTION_CHANGE_IS_REINSTALL) != 0)
249 /* application wants to make no difference between change
251 if (type == SOLVER_TRANSACTION_CHANGED)
252 type = SOLVER_TRANSACTION_REINSTALLED;
253 else if (type == SOLVER_TRANSACTION_CHANGE)
254 type = SOLVER_TRANSACTION_REINSTALL;
257 if (type == SOLVER_TRANSACTION_ERASE || type == SOLVER_TRANSACTION_INSTALL || type == SOLVER_TRANSACTION_MULTIINSTALL)
260 if (s->repo == pool->installed && (mode & SOLVER_TRANSACTION_SHOW_ACTIVE) == 0)
262 /* erase element and we're showing the passive side */
263 if (type == SOLVER_TRANSACTION_OBSOLETED && (mode & SOLVER_TRANSACTION_SHOW_OBSOLETES) == 0)
264 type = SOLVER_TRANSACTION_ERASE;
265 if (type == SOLVER_TRANSACTION_OBSOLETED && (mode & SOLVER_TRANSACTION_OBSOLETE_IS_UPGRADE) != 0)
266 type = SOLVER_TRANSACTION_UPGRADED;
269 if (s->repo != pool->installed && (mode & SOLVER_TRANSACTION_SHOW_ACTIVE) != 0)
271 /* install element and we're showing the active side */
272 if (type == SOLVER_TRANSACTION_OBSOLETES && (mode & SOLVER_TRANSACTION_SHOW_OBSOLETES) == 0)
273 type = SOLVER_TRANSACTION_INSTALL;
274 if (type == SOLVER_TRANSACTION_OBSOLETES && (mode & SOLVER_TRANSACTION_OBSOLETE_IS_UPGRADE) != 0)
275 type = SOLVER_TRANSACTION_UPGRADE;
279 /* the element doesn't match the show mode */
281 /* if we're showing all references, we can ignore this package */
282 if ((mode & (SOLVER_TRANSACTION_SHOW_ALL|SOLVER_TRANSACTION_SHOW_OBSOLETES)) == (SOLVER_TRANSACTION_SHOW_ALL|SOLVER_TRANSACTION_SHOW_OBSOLETES))
283 return SOLVER_TRANSACTION_IGNORE;
285 /* we're not showing all refs. check if some other package
286 * references us. If yes, it's safe to ignore this package,
287 * otherwise we need to map the type */
289 /* most of the time there's only one reference, so check it first */
290 q = transaction_obs_pkg(trans, p);
292 if ((mode & SOLVER_TRANSACTION_SHOW_OBSOLETES) == 0)
294 Solvable *sq = pool->solvables + q;
295 if (sq->name != s->name)
297 /* it's a replace but we're not showing replaces. map type. */
298 if (s->repo == pool->installed)
299 return SOLVER_TRANSACTION_ERASE;
300 else if (type == SOLVER_TRANSACTION_MULTIREINSTALL)
301 return SOLVER_TRANSACTION_MULTIINSTALL;
303 return SOLVER_TRANSACTION_INSTALL;
307 /* if there's a match, p will be shown when q
309 if (transaction_obs_pkg(trans, q) == p)
310 return SOLVER_TRANSACTION_IGNORE;
312 /* too bad, a miss. check em all */
315 transaction_all_obs_pkgs(trans, p, &oq);
316 for (i = 0; i < oq.count; i++)
319 if ((mode & SOLVER_TRANSACTION_SHOW_OBSOLETES) == 0)
321 Solvable *sq = pool->solvables + q;
322 if (sq->name != s->name)
325 /* check if we are referenced? */
326 if ((mode & SOLVER_TRANSACTION_SHOW_ALL) != 0)
328 transaction_all_obs_pkgs(trans, q, &rq);
329 for (j = 0; j < rq.count; j++)
330 if (rq.elements[j] == p)
338 else if (transaction_obs_pkg(trans, q) == p)
349 /* we're not referenced. map type */
350 if (s->repo == pool->installed)
351 return SOLVER_TRANSACTION_ERASE;
352 else if (type == SOLVER_TRANSACTION_MULTIREINSTALL)
353 return SOLVER_TRANSACTION_MULTIINSTALL;
355 return SOLVER_TRANSACTION_INSTALL;
357 /* there was a ref, so p is shown with some other package */
358 return SOLVER_TRANSACTION_IGNORE;
364 classify_cmp(const void *ap, const void *bp, void *dp)
366 Transaction *trans = dp;
367 Pool *pool = trans->pool;
377 return a[2] && b[2] ? strcmp(pool_id2str(pool, a[2]), pool_id2str(pool, b[2])) : r;
380 return a[3] && b[3] ? strcmp(pool_id2str(pool, a[3]), pool_id2str(pool, b[3])) : r;
385 classify_cmp_pkgs(const void *ap, const void *bp, void *dp)
387 Transaction *trans = dp;
388 Pool *pool = trans->pool;
393 sa = pool->solvables + a;
394 sb = pool->solvables + b;
395 if (sa->name != sb->name)
396 return strcmp(pool_id2str(pool, sa->name), pool_id2str(pool, sb->name));
397 if (sa->evr != sb->evr)
399 int r = pool_evrcmp(pool, sa->evr, sb->evr, EVRCMP_COMPARE);
407 transaction_classify(Transaction *trans, int mode, Queue *classes)
409 Pool *pool = trans->pool;
410 int ntypes[SOLVER_TRANSACTION_MAXTYPE + 1];
412 Id v, vq, type, p, q;
415 queue_empty(classes);
416 memset(ntypes, 0, sizeof(ntypes));
417 /* go through transaction and classify each step */
418 for (i = 0; i < trans->steps.count; i++)
420 p = trans->steps.elements[i];
421 s = pool->solvables + p;
422 type = transaction_type(trans, p, mode);
424 if (!pool->installed || s->repo != pool->installed)
426 /* don't report vendor/arch changes if we were mapped to erase. */
427 if (type == SOLVER_TRANSACTION_ERASE)
429 /* look at arch/vendor changes */
430 q = transaction_obs_pkg(trans, p);
433 sq = pool->solvables + q;
439 if ((mode & SOLVER_TRANSACTION_MERGE_ARCHCHANGES) != 0)
441 for (j = 0; j < classes->count; j += 4)
442 if (classes->elements[j] == SOLVER_TRANSACTION_ARCHCHANGE && classes->elements[j + 2] == v && classes->elements[j + 3] == vq)
444 if (j == classes->count)
446 queue_push(classes, SOLVER_TRANSACTION_ARCHCHANGE);
447 queue_push(classes, 1);
448 queue_push(classes, v);
449 queue_push(classes, vq);
452 classes->elements[j + 1]++;
455 v = s->vendor ? s->vendor : 1;
456 vq = sq->vendor ? sq->vendor : 1;
459 if ((mode & SOLVER_TRANSACTION_MERGE_VENDORCHANGES) != 0)
461 for (j = 0; j < classes->count; j += 4)
462 if (classes->elements[j] == SOLVER_TRANSACTION_VENDORCHANGE && classes->elements[j + 2] == v && classes->elements[j + 3] == vq)
464 if (j == classes->count)
466 queue_push(classes, SOLVER_TRANSACTION_VENDORCHANGE);
467 queue_push(classes, 1);
468 queue_push(classes, v);
469 queue_push(classes, vq);
472 classes->elements[j + 1]++;
475 /* now sort all vendor/arch changes */
476 if (classes->count > 4)
477 solv_sort(classes->elements, classes->count / 4, 4 * sizeof(Id), classify_cmp, trans);
478 /* finally add all classes. put erases last */
479 i = SOLVER_TRANSACTION_ERASE;
482 queue_unshift(classes, 0);
483 queue_unshift(classes, 0);
484 queue_unshift(classes, ntypes[i]);
485 queue_unshift(classes, i);
487 for (i = SOLVER_TRANSACTION_MAXTYPE; i > 0; i--)
491 if (i == SOLVER_TRANSACTION_ERASE)
493 queue_unshift(classes, 0);
494 queue_unshift(classes, 0);
495 queue_unshift(classes, ntypes[i]);
496 queue_unshift(classes, i);
501 transaction_classify_pkgs(Transaction *trans, int mode, Id class, Id from, Id to, Queue *pkgs)
503 Pool *pool = trans->pool;
509 for (i = 0; i < trans->steps.count; i++)
511 p = trans->steps.elements[i];
512 s = pool->solvables + p;
513 if (class <= SOLVER_TRANSACTION_MAXTYPE)
515 type = transaction_type(trans, p, mode);
520 if (!pool->installed || s->repo != pool->installed)
522 q = transaction_obs_pkg(trans, p);
525 sq = pool->solvables + q;
526 if (class == SOLVER_TRANSACTION_ARCHCHANGE)
528 if ((!from && !to) || (s->arch == from && sq->arch == to))
532 if (class == SOLVER_TRANSACTION_VENDORCHANGE)
534 Id v = s->vendor ? s->vendor : 1;
535 Id vq = sq->vendor ? sq->vendor : 1;
536 if ((!from && !to) || (v == from && vq == to))
542 solv_sort(pkgs->elements, pkgs->count, sizeof(Id), classify_cmp_pkgs, trans);
546 create_transaction_info(Transaction *trans, Queue *decisionq)
548 Pool *pool = trans->pool;
549 Queue *ti = &trans->transaction_info;
550 Repo *installed = pool->installed;
556 trans->transaction_installed = solv_free(trans->transaction_installed);
558 return; /* no info needed */
559 for (i = 0; i < decisionq->count; i++)
561 p = decisionq->elements[i];
562 if (p <= 0 || p == SYSTEMSOLVABLE)
564 s = pool->solvables + p;
565 if (!s->repo || s->repo == installed)
567 multi = trans->multiversionmap.size && MAPTST(&trans->multiversionmap, p);
568 FOR_PROVIDES(p2, pp2, s->name)
570 if (!MAPTST(&trans->transactsmap, p2))
572 s2 = pool->solvables + p2;
573 if (s2->repo != installed)
575 if (multi && (s->name != s2->name || s->evr != s2->evr || s->arch != s2->arch))
577 if (!pool->implicitobsoleteusesprovides && s->name != s2->name)
579 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, s2))
581 queue_push2(ti, p, p2);
583 if (s->obsoletes && !multi)
585 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
586 while ((obs = *obsp++) != 0)
588 FOR_PROVIDES(p2, pp2, obs)
590 s2 = pool->solvables + p2;
591 if (s2->repo != installed)
593 if (!pool->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p2, obs))
595 if (pool->obsoleteusescolors && !pool_colormatch(pool, s, s2))
597 queue_push2(ti, p, p2);
605 solv_sort(ti->elements, ti->count / 2, 2 * sizeof(Id), obsq_sortcmp, pool);
606 for (i = j = 2; i < ti->count; i += 2)
608 if (ti->elements[i] == ti->elements[j - 2] && ti->elements[i + 1] == ti->elements[j - 1])
610 ti->elements[j++] = ti->elements[i];
611 ti->elements[j++] = ti->elements[i + 1];
613 queue_truncate(ti, j);
616 /* create transaction_installed helper */
617 /* entry > 0: exactly one obsoleter, entry < 0: multiple obsoleters, -entry is "best" */
618 trans->transaction_installed = solv_calloc(installed->end - installed->start, sizeof(Id));
619 for (i = 0; i < ti->count; i += 2)
621 j = ti->elements[i + 1] - installed->start;
622 if (!trans->transaction_installed[j])
623 trans->transaction_installed[j] = ti->elements[i];
626 /* more than one package obsoletes us. compare to find "best" */
628 if (trans->transaction_installed[j] > 0)
629 trans->transaction_installed[j] = -trans->transaction_installed[j];
630 q[0] = q[2] = ti->elements[i + 1];
631 q[1] = ti->elements[i];
632 q[3] = -trans->transaction_installed[j];
633 if (obsq_sortcmp(q, q + 2, pool) < 0)
634 trans->transaction_installed[j] = -ti->elements[i];
641 transaction_create_decisionq(Pool *pool, Queue *decisionq, Map *multiversionmap)
643 Repo *installed = pool->installed;
649 trans = transaction_create(pool);
650 if (multiversionmap && !multiversionmap->size)
651 multiversionmap = 0; /* ignore empty map */
652 queue_empty(&trans->steps);
653 map_init(&trans->transactsmap, pool->nsolvables);
655 for (i = 0; i < decisionq->count; i++)
657 p = decisionq->elements[i];
658 s = pool->solvables + (p > 0 ? p : -p);
661 if (installed && s->repo == installed && p < 0)
662 MAPSET(&trans->transactsmap, -p);
663 if ((!installed || s->repo != installed) && p > 0)
666 const char *n = pool_id2str(pool, s->name);
667 if (!strncmp(n, "patch:", 6))
669 if (!strncmp(n, "pattern:", 8))
672 MAPSET(&trans->transactsmap, p);
673 if (multiversionmap && MAPTST(multiversionmap, p))
677 MAPCLR(&trans->transactsmap, SYSTEMSOLVABLE);
679 map_init_clone(&trans->multiversionmap, multiversionmap);
681 create_transaction_info(trans, decisionq);
685 FOR_REPO_SOLVABLES(installed, p, s)
687 if (MAPTST(&trans->transactsmap, p))
688 queue_push(&trans->steps, p);
691 for (i = 0; i < decisionq->count; i++)
693 p = decisionq->elements[i];
694 if (p > 0 && MAPTST(&trans->transactsmap, p))
695 queue_push(&trans->steps, p);
701 transaction_installedresult(Transaction *trans, Queue *installedq)
703 Pool *pool = trans->pool;
704 Repo *installed = pool->installed;
709 queue_empty(installedq);
710 /* first the new installs, than the kept packages */
711 for (i = 0; i < trans->steps.count; i++)
713 p = trans->steps.elements[i];
714 s = pool->solvables + p;
715 if (installed && s->repo == installed)
717 queue_push(installedq, p);
719 cutoff = installedq->count;
722 FOR_REPO_SOLVABLES(installed, p, s)
723 if (!MAPTST(&trans->transactsmap, p))
724 queue_push(installedq, p);
730 transaction_create_installedmap(Transaction *trans, Map *installedmap)
732 Pool *pool = trans->pool;
733 Repo *installed = pool->installed;
738 map_init(installedmap, pool->nsolvables);
739 for (i = 0; i < trans->steps.count; i++)
741 p = trans->steps.elements[i];
742 s = pool->solvables + p;
743 if (!installed || s->repo != installed)
744 MAPSET(installedmap, p);
748 FOR_REPO_SOLVABLES(installed, p, s)
749 if (!MAPTST(&trans->transactsmap, p))
750 MAPSET(installedmap, p);
755 transaction_calc_installsizechange(Transaction *trans)
760 transaction_create_installedmap(trans, &installedmap);
761 change = pool_calc_installsizechange(trans->pool, &installedmap);
762 map_free(&installedmap);
767 transaction_calc_duchanges(Transaction *trans, DUChanges *mps, int nmps)
771 transaction_create_installedmap(trans, &installedmap);
772 pool_calc_duchanges(trans->pool, &installedmap, mps, nmps);
773 map_free(&installedmap);
776 struct _TransactionElement {
777 Id p; /* solvable id */
778 Id edges; /* pointer into edges data */
782 struct _TransactionOrderdata {
783 struct _TransactionElement *tes;
789 #define TYPE_BROKEN (1<<0)
790 #define TYPE_CON (1<<1)
792 #define TYPE_REQ_P (1<<2)
793 #define TYPE_PREREQ_P (1<<3)
795 #define TYPE_REQ (1<<4)
796 #define TYPE_PREREQ (1<<5)
798 #define TYPE_CYCLETAIL (1<<16)
799 #define TYPE_CYCLEHEAD (1<<17)
801 #define EDGEDATA_BLOCK 127
804 transaction_create(Pool *pool)
806 Transaction *trans = solv_calloc(1, sizeof(*trans));
812 transaction_create_clone(Transaction *srctrans)
814 Transaction *trans = transaction_create(srctrans->pool);
815 queue_init_clone(&trans->steps, &srctrans->steps);
816 queue_init_clone(&trans->transaction_info, &srctrans->transaction_info);
817 if (srctrans->transaction_installed)
819 Repo *installed = srctrans->pool->installed;
820 trans->transaction_installed = solv_calloc(installed->end - installed->start, sizeof(Id));
821 memcpy(trans->transaction_installed, srctrans->transaction_installed, (installed->end - installed->start) * sizeof(Id));
823 map_init_clone(&trans->transactsmap, &srctrans->transactsmap);
824 map_init_clone(&trans->multiversionmap, &srctrans->multiversionmap);
825 if (srctrans->orderdata)
827 struct _TransactionOrderdata *od = srctrans->orderdata;
828 trans->orderdata = solv_calloc(1, sizeof(*trans->orderdata));
829 trans->orderdata->tes = solv_malloc2(od->ntes, sizeof(*od->tes));
830 memcpy(trans->orderdata->tes, od->tes, od->ntes * sizeof(*od->tes));
831 trans->orderdata->ntes = od->ntes;
832 trans->orderdata->invedgedata = solv_malloc2(od->ninvedgedata, sizeof(Id));
833 memcpy(trans->orderdata->invedgedata, od->invedgedata, od->ninvedgedata * sizeof(Id));
834 trans->orderdata->ninvedgedata = od->ninvedgedata;
840 transaction_free(Transaction *trans)
842 queue_free(&trans->steps);
843 queue_free(&trans->transaction_info);
844 trans->transaction_installed = solv_free(trans->transaction_installed);
845 map_free(&trans->transactsmap);
846 map_free(&trans->multiversionmap);
847 transaction_free_orderdata(trans);
852 transaction_free_orderdata(Transaction *trans)
854 if (trans->orderdata)
856 struct _TransactionOrderdata *od = trans->orderdata;
857 od->tes = solv_free(od->tes);
858 od->invedgedata = solv_free(od->invedgedata);
859 trans->orderdata = solv_free(trans->orderdata);
865 struct _TransactionElement *tes;
877 addteedge(struct orderdata *od, int from, int to, int type)
880 struct _TransactionElement *te;
885 /* 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); */
888 for (i = te->edges; od->edgedata[i]; i += 2)
889 if (od->edgedata[i] == to)
891 /* test of brokenness */
892 if (type == TYPE_BROKEN)
893 return od->edgedata[i] && (od->edgedata[i + 1] & TYPE_BROKEN) != 0 ? 1 : 0;
896 od->edgedata[i + 1] |= type;
899 if (i + 1 == od->nedgedata)
901 /* printf("tail add %d\n", i - te->edges); */
904 od->edgedata = solv_extend(od->edgedata, od->nedgedata, 3, sizeof(Id), EDGEDATA_BLOCK);
908 /* printf("extend %d\n", i - te->edges); */
909 od->edgedata = solv_extend(od->edgedata, od->nedgedata, 3 + (i - te->edges), sizeof(Id), EDGEDATA_BLOCK);
911 memcpy(od->edgedata + od->nedgedata, od->edgedata + te->edges, sizeof(Id) * (i - te->edges));
912 i = od->nedgedata + (i - te->edges);
913 te->edges = od->nedgedata;
915 od->edgedata[i] = to;
916 od->edgedata[i + 1] = type;
917 od->edgedata[i + 2] = 0; /* end marker */
918 od->nedgedata = i + 3;
923 addedge(struct orderdata *od, Id from, Id to, int type)
925 Transaction *trans = od->trans;
926 Pool *pool = trans->pool;
928 struct _TransactionElement *te;
931 /* printf("addedge %d %d type %d\n", from, to, type); */
932 s = pool->solvables + from;
933 if (s->repo == pool->installed && trans->transaction_installed[from - pool->installed->start])
935 /* obsolete, map to install */
936 if (trans->transaction_installed[from - pool->installed->start] > 0)
937 from = trans->transaction_installed[from - pool->installed->start];
944 queue_init_buffer(&ti, tibuf, sizeof(tibuf)/sizeof(*tibuf));
945 transaction_all_obs_pkgs(trans, from, &ti);
946 for (i = 0; i < ti.count; i++)
947 ret |= addedge(od, ti.elements[i], to, type);
952 s = pool->solvables + to;
953 if (s->repo == pool->installed && trans->transaction_installed[to - pool->installed->start])
955 /* obsolete, map to install */
956 if (trans->transaction_installed[to - pool->installed->start] > 0)
957 to = trans->transaction_installed[to - pool->installed->start];
964 queue_init_buffer(&ti, tibuf, sizeof(tibuf)/sizeof(*tibuf));
965 transaction_all_obs_pkgs(trans, to, &ti);
966 for (i = 0; i < ti.count; i++)
967 ret |= addedge(od, from, ti.elements[i], type);
973 /* map from/to to te numbers */
974 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
981 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
987 return addteedge(od, i, to, type);
992 havechoice(struct orderdata *od, Id p, Id q1, Id q2)
994 Transaction *trans = od->trans;
995 Pool *pool = trans->pool;
996 Id ti1buf[5], ti2buf[5];
1000 /* both q1 and q2 are uninstalls. check if their TEs intersect */
1001 /* common case: just one TE for both packages */
1003 printf("havechoice %d %d %d\n", p, q1, q2);
1005 if (trans->transaction_installed[q1 - pool->installed->start] == 0)
1007 if (trans->transaction_installed[q2 - pool->installed->start] == 0)
1009 if (trans->transaction_installed[q1 - pool->installed->start] == trans->transaction_installed[q2 - pool->installed->start])
1011 if (trans->transaction_installed[q1 - pool->installed->start] > 0 && trans->transaction_installed[q2 - pool->installed->start] > 0)
1013 queue_init_buffer(&ti1, ti1buf, sizeof(ti1buf)/sizeof(*ti1buf));
1014 transaction_all_obs_pkgs(trans, q1, &ti1);
1015 queue_init_buffer(&ti2, ti2buf, sizeof(ti2buf)/sizeof(*ti2buf));
1016 transaction_all_obs_pkgs(trans, q2, &ti2);
1017 for (i = 0; i < ti1.count; i++)
1018 for (j = 0; j < ti2.count; j++)
1019 if (ti1.elements[i] == ti2.elements[j])
1021 /* found a common edge */
1033 havescripts(Pool *pool, Id solvid)
1035 Solvable *s = pool->solvables + solvid;
1041 reqp = s->repo->idarraydata + s->requires;
1042 while ((req = *reqp++) != 0)
1044 if (req == SOLVABLE_PREREQMARKER)
1051 dep = pool_id2str(pool, req);
1052 if (*dep == '/' && strcmp(dep, "/sbin/ldconfig") != 0)
1060 addsolvableedges(struct orderdata *od, Solvable *s)
1062 Transaction *trans = od->trans;
1063 Pool *pool = trans->pool;
1064 Id req, *reqp, con, *conp;
1066 int i, j, pre, numins;
1067 Repo *installed = pool->installed;
1073 printf("addsolvableedges %s\n", pool_solvable2str(pool, s));
1075 p = s - pool->solvables;
1079 reqp = s->repo->idarraydata + s->requires;
1081 while ((req = *reqp++) != 0)
1083 if (req == SOLVABLE_PREREQMARKER)
1089 if (pre != TYPE_PREREQ && installed && s->repo == installed)
1091 /* ignore normal requires if we're getting obsoleted */
1092 if (trans->transaction_installed[p - pool->installed->start])
1097 numins = 0; /* number of packages to be installed providing it */
1098 provbyinst = 0; /* provided by kept package */
1099 FOR_PROVIDES(p2, pp2, req)
1101 s2 = pool->solvables + p2;
1104 reqq.count = 0; /* self provides */
1107 if (s2->repo == installed && !MAPTST(&trans->transactsmap, p2))
1111 printf("IGNORE inst provides %s by %s\n", pool_dep2str(pool, req), pool_solvable2str(pool, s2));
1112 reqq.count = 0; /* provided by package that stays installed */
1118 if (s2->repo != installed && !MAPTST(&trans->transactsmap, p2))
1119 continue; /* package stays uninstalled */
1121 if (s->repo == installed)
1123 /* s gets uninstalled */
1124 queue_pushunique(&reqq, p2);
1125 if (s2->repo != installed)
1130 if (s2->repo == installed)
1131 continue; /* s2 gets uninstalled */
1132 queue_pushunique(&reqq, p2);
1137 /* prune to harmless ->inst edges */
1138 for (i = j = 0; i < reqq.count; i++)
1139 if (pool->solvables[reqq.elements[i]].repo != installed)
1140 reqq.elements[j++] = reqq.elements[i];
1144 if (numins && reqq.count)
1146 if (s->repo == installed)
1148 for (i = 0; i < reqq.count; i++)
1150 if (pool->solvables[reqq.elements[i]].repo == installed)
1152 for (j = 0; j < reqq.count; j++)
1154 if (pool->solvables[reqq.elements[j]].repo != installed)
1156 if (trans->transaction_installed[reqq.elements[i] - pool->installed->start] == reqq.elements[j])
1157 continue; /* no self edge */
1159 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]));
1161 addedge(od, reqq.elements[i], reqq.elements[j], pre == TYPE_PREREQ ? TYPE_PREREQ_P : TYPE_REQ_P);
1167 /* no mixed types, remove all deps on uninstalls */
1168 for (i = j = 0; i < reqq.count; i++)
1169 if (pool->solvables[reqq.elements[i]].repo != installed)
1170 reqq.elements[j++] = reqq.elements[i];
1175 for (i = 0; i < reqq.count; i++)
1178 p2 = reqq.elements[i];
1179 if (pool->solvables[p2].repo != installed)
1181 /* all elements of reqq are installs, thus have different TEs */
1182 choice = reqq.count - 1;
1183 if (pool->solvables[p].repo != installed)
1186 printf("add inst->inst edge choice %d (%s -> %s -> %s)\n", choice, pool_solvid2str(pool, p), pool_dep2str(pool, req), pool_solvid2str(pool, p2));
1188 addedge(od, p, p2, pre);
1193 printf("add uninst->inst edge choice %d (%s -> %s -> %s)\n", choice, pool_solvid2str(pool, p), pool_dep2str(pool, req), pool_solvid2str(pool, p2));
1195 addedge(od, p, p2, pre == TYPE_PREREQ ? TYPE_PREREQ_P : TYPE_REQ_P);
1200 if (s->repo != installed)
1201 continue; /* no inst->uninst edges, please! */
1203 /* uninst -> uninst edge. Those make trouble. Only add if we must */
1204 if (trans->transaction_installed[p - installed->start] && !havescripts(pool, p))
1206 /* p is obsoleted by another package and has no scripts */
1207 /* we assume that the obsoletor is good enough to replace p */
1212 for (j = 0; j < reqq.count; j++)
1216 if (havechoice(od, p, reqq.elements[i], reqq.elements[j]))
1221 printf("add uninst->uninst edge choice %d (%s -> %s -> %s)\n", choice, pool_solvid2str(pool, p), pool_dep2str(pool, req), pool_solvid2str(pool, p2));
1223 addedge(od, p2, p, pre == TYPE_PREREQ ? TYPE_PREREQ_P : TYPE_REQ_P);
1230 conp = s->repo->idarraydata + s->conflicts;
1231 while ((con = *conp++) != 0)
1233 FOR_PROVIDES(p2, pp2, con)
1237 s2 = pool->solvables + p2;
1240 if (s->repo == installed)
1242 if (s2->repo != installed && MAPTST(&trans->transactsmap, p2))
1244 /* deinstall p before installing p2 */
1246 printf("add conflict uninst->inst edge (%s -> %s -> %s)\n", pool_solvid2str(pool, p2), pool_dep2str(pool, con), pool_solvid2str(pool, p));
1248 addedge(od, p2, p, TYPE_CON);
1253 if (s2->repo == installed && MAPTST(&trans->transactsmap, p2))
1255 /* deinstall p2 before installing p */
1257 printf("add conflict uninst->inst edge (%s -> %s -> %s)\n", pool_solvid2str(pool, p), pool_dep2str(pool, con), pool_solvid2str(pool, p2));
1259 addedge(od, p, p2, TYPE_CON);
1266 if (s->repo == installed && solvable_lookup_idarray(s, SOLVABLE_TRIGGERS, &reqq) && reqq.count)
1268 /* we're getting deinstalled/updated. Try to do this before our
1269 * triggers are hit */
1270 for (i = 0; i < reqq.count; i++)
1272 Id tri = reqq.elements[i];
1273 FOR_PROVIDES(p2, pp2, tri)
1277 s2 = pool->solvables + p2;
1280 if (s2->name == s->name)
1281 continue; /* obsoleted anyway */
1282 if (s2->repo != installed && MAPTST(&trans->transactsmap, p2))
1284 /* deinstall/update p before installing p2 */
1286 printf("add trigger uninst->inst edge (%s -> %s -> %s)\n", pool_solvid2str(pool, p2), pool_dep2str(pool, tri), pool_solvid2str(pool, p));
1288 addedge(od, p2, p, TYPE_CON);
1297 /* break an edge in a cycle */
1299 breakcycle(struct orderdata *od, Id *cycle)
1301 Pool *pool = od->trans->pool;
1302 Id ddegmin, ddegmax, ddeg;
1304 struct _TransactionElement *te;
1307 ddegmin = ddegmax = 0;
1308 for (k = 0; cycle[k + 1]; k += 2)
1310 ddeg = od->edgedata[cycle[k + 1] + 1];
1313 if (!k || ddeg < ddegmin)
1319 if (ddeg == ddegmin)
1321 if (havescripts(pool, od->tes[cycle[l]].p) && !havescripts(pool, od->tes[cycle[k]].p))
1323 /* prefer k, as l comes from a package with contains scriptlets */
1328 /* same edge value, check for prereq */
1332 /* record brkoen cycle starting with the tail */
1333 queue_push(&od->cycles, od->cyclesdata.count); /* offset into data */
1334 queue_push(&od->cycles, k / 2); /* cycle elements */
1335 queue_push(&od->cycles, od->edgedata[cycle[l + 1] + 1]); /* broken edge */
1342 queue_push(&od->cyclesdata, cycle[k]);
1346 queue_push(&od->cyclesdata, 0); /* mark end */
1348 /* break that edge */
1349 od->edgedata[cycle[l + 1] + 1] |= TYPE_BROKEN;
1352 if (ddegmin < TYPE_REQ)
1356 /* cycle recorded, print it */
1357 if (ddegmin >= TYPE_REQ && (ddegmax & TYPE_PREREQ) != 0)
1358 POOL_DEBUG(SOLV_DEBUG_STATS, "CRITICAL ");
1359 POOL_DEBUG(SOLV_DEBUG_STATS, "cycle: --> ");
1360 for (k = 0; cycle[k + 1]; k += 2)
1362 te = od->tes + cycle[k];
1363 if ((od->edgedata[cycle[k + 1] + 1] & TYPE_BROKEN) != 0)
1364 POOL_DEBUG(SOLV_DEBUG_STATS, "%s ##%x##> ", pool_solvid2str(pool, te->p), od->edgedata[cycle[k + 1] + 1]);
1366 POOL_DEBUG(SOLV_DEBUG_STATS, "%s --%x--> ", pool_solvid2str(pool, te->p), od->edgedata[cycle[k + 1] + 1]);
1368 POOL_DEBUG(SOLV_DEBUG_STATS, "\n");
1372 dump_tes(struct orderdata *od)
1374 Pool *pool = od->trans->pool;
1377 struct _TransactionElement *te, *te2;
1380 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1382 Solvable *s = pool->solvables + te->p;
1383 POOL_DEBUG(SOLV_DEBUG_RESULT, "TE %4d: %c%s\n", i, s->repo == pool->installed ? '-' : '+', pool_solvable2str(pool, s));
1384 if (s->repo != pool->installed)
1387 transaction_all_obs_pkgs(od->trans, te->p, &obsq);
1388 for (j = 0; j < obsq.count; j++)
1389 POOL_DEBUG(SOLV_DEBUG_RESULT, " -%s\n", pool_solvid2str(pool, obsq.elements[j]));
1391 for (j = te->edges; od->edgedata[j]; j += 2)
1393 te2 = od->tes + od->edgedata[j];
1394 if ((od->edgedata[j + 1] & TYPE_BROKEN) == 0)
1395 POOL_DEBUG(SOLV_DEBUG_RESULT, " --%x--> TE %4d: %s\n", od->edgedata[j + 1], od->edgedata[j], pool_solvid2str(pool, te2->p));
1397 POOL_DEBUG(SOLV_DEBUG_RESULT, " ##%x##> TE %4d: %s\n", od->edgedata[j + 1], od->edgedata[j], pool_solvid2str(pool, te2->p));
1404 reachable(struct orderdata *od, Id i)
1406 struct _TransactionElement *te = od->tes + i;
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 == 2)
1429 addcycleedges(struct orderdata *od, Id *cycle, Queue *todo)
1432 Transaction *trans = od->trans;
1433 Pool *pool = trans->pool;
1435 struct _TransactionElement *te;
1442 printf("addcycleedges\n");
1443 for (i = 0; (j = cycle[i]) != 0; i++)
1444 printf("cycle %s\n", pool_solvid2str(pool, od->tes[j].p));
1447 /* first add all the tail cycle edges */
1449 /* see what we can reach from the cycle */
1451 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1453 for (i = 0; (j = cycle[i]) != 0; i++)
1455 od->tes[j].mark = -1;
1456 queue_push(todo, j);
1460 i = queue_pop(todo);
1464 te->mark = te->mark < 0 ? 2 : 1;
1465 for (j = te->edges; (k = od->edgedata[j]) != 0; j += 2)
1467 if ((od->edgedata[j + 1] & TYPE_BROKEN) != 0)
1469 if (od->tes[k].mark > 0)
1470 continue; /* no need to visit again */
1471 queue_push(todo, k);
1474 /* now all cycle TEs are marked with 2, all TEs reachable
1475 * from the cycle are marked with 1 */
1477 od->tes[tail].mark = 1; /* no need to add edges */
1479 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1482 continue; /* reachable from cycle */
1483 for (j = te->edges; (k = od->edgedata[j]) != 0; j += 2)
1485 if ((od->edgedata[j + 1] & TYPE_BROKEN) != 0)
1487 if (od->tes[k].mark != 2)
1489 /* We found an edge to the cycle. Add an extra edge to the tail */
1490 /* the TE was not reachable, so we're not creating a new cycle! */
1492 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));
1494 j -= te->edges; /* in case we move */
1495 addteedge(od, i, tail, TYPE_CYCLETAIL);
1497 break; /* one edge is enough */
1502 /* now add all head cycle edges */
1505 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1508 for (i = 0; (j = cycle[i]) != 0; i++)
1511 od->tes[j].mark = 2;
1513 /* first the head to save some time */
1514 te = od->tes + head;
1515 for (j = te->edges; (k = od->edgedata[j]) != 0; j += 2)
1517 if ((od->edgedata[j + 1] & TYPE_BROKEN) != 0)
1519 if (!od->tes[k].mark)
1521 if (od->tes[k].mark == -1)
1522 od->tes[k].mark = -2; /* no need for another edge */
1524 for (i = 0; cycle[i] != 0; i++)
1526 if (cycle[i] == head)
1528 te = od->tes + cycle[i];
1529 for (j = te->edges; (k = od->edgedata[j]) != 0; j += 2)
1531 if ((od->edgedata[j + 1] & TYPE_BROKEN) != 0)
1533 /* see if we can reach a cycle TE from k */
1534 if (!od->tes[k].mark)
1536 if (od->tes[k].mark == -1)
1539 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));
1541 addteedge(od, head, k, TYPE_CYCLEHEAD);
1542 od->tes[k].mark = -2; /* no need to add that one again */
1550 transaction_order(Transaction *trans, int flags)
1552 Pool *pool = trans->pool;
1553 Queue *tr = &trans->steps;
1554 Repo *installed = pool->installed;
1557 int i, j, k, numte, numedge;
1558 struct orderdata od;
1559 struct _TransactionElement *te;
1560 Queue todo, obsq, samerepoq, uninstq;
1561 int cycstart, cycel;
1569 start = now = solv_timems(0);
1570 POOL_DEBUG(SOLV_DEBUG_STATS, "ordering transaction\n");
1571 /* free old data if present */
1572 if (trans->orderdata)
1574 struct _TransactionOrderdata *od = trans->orderdata;
1575 od->tes = solv_free(od->tes);
1576 od->invedgedata = solv_free(od->invedgedata);
1577 trans->orderdata = solv_free(trans->orderdata);
1580 /* create a transaction element for every active component */
1582 for (i = 0; i < tr->count; i++)
1584 p = tr->elements[i];
1585 s = pool->solvables + p;
1586 if (installed && s->repo == installed && trans->transaction_installed[p - installed->start])
1590 POOL_DEBUG(SOLV_DEBUG_STATS, "transaction elements: %d\n", numte);
1592 return; /* nothing to do... */
1594 numte++; /* leave first one zero */
1595 memset(&od, 0, sizeof(od));
1598 od.tes = solv_calloc(numte, sizeof(*od.tes));
1599 od.edgedata = solv_extend(0, 0, 1, sizeof(Id), EDGEDATA_BLOCK);
1602 queue_init(&od.cycles);
1604 /* initialize TEs */
1605 for (i = 0, te = od.tes + 1; i < tr->count; i++)
1607 p = tr->elements[i];
1608 s = pool->solvables + p;
1609 if (installed && s->repo == installed && trans->transaction_installed[p - installed->start])
1615 /* create dependency graph */
1616 for (i = 0; i < tr->count; i++)
1617 addsolvableedges(&od, pool->solvables + tr->elements[i]);
1621 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1622 for (j = te->edges; od.edgedata[j]; j += 2)
1624 POOL_DEBUG(SOLV_DEBUG_STATS, "edges: %d, edge space: %d\n", numedge, od.nedgedata / 2);
1625 POOL_DEBUG(SOLV_DEBUG_STATS, "edge creation took %d ms\n", solv_timems(now));
1631 now = solv_timems(0);
1632 /* kill all cycles */
1634 for (i = numte - 1; i > 0; i--)
1635 queue_push(&todo, i);
1639 i = queue_pop(&todo);
1640 /* printf("- look at TE %d\n", i); */
1644 od.tes[i].mark = 2; /* done with that one */
1649 continue; /* already finished before */
1652 int edgestovisit = 0;
1653 /* new node, visit edges */
1654 for (j = te->edges; (k = od.edgedata[j]) != 0; j += 2)
1656 if ((od.edgedata[j + 1] & TYPE_BROKEN) != 0)
1658 if (od.tes[k].mark == 2)
1659 continue; /* no need to visit again */
1660 if (!edgestovisit++)
1661 queue_push(&todo, -i); /* end of edges marker */
1662 queue_push(&todo, k);
1665 te->mark = 2; /* no edges, done with that one */
1667 te->mark = 1; /* under investigation */
1670 /* oh no, we found a cycle */
1671 /* find start of cycle node (<0) */
1672 for (j = todo.count - 1; j >= 0; j--)
1673 if (todo.elements[j] == -i)
1677 /* build te/edge chain */
1679 for (j = k; j < todo.count; j++)
1680 if (todo.elements[j] < 0)
1681 todo.elements[k++] = -todo.elements[j];
1682 cycel = k - cycstart;
1684 /* make room for edges, two extra element for cycle loop + terminating 0 */
1685 while (todo.count < cycstart + 2 * cycel + 2)
1686 queue_push(&todo, 0);
1687 cycle = todo.elements + cycstart;
1688 cycle[cycel] = i; /* close the loop */
1689 cycle[2 * cycel + 1] = 0; /* terminator */
1690 for (k = cycel; k > 0; k--)
1692 cycle[k * 2] = cycle[k];
1693 te = od.tes + cycle[k - 1];
1694 assert(te->mark == 1);
1695 te->mark = 0; /* reset investigation marker */
1696 /* printf("searching for edge from %d to %d\n", cycle[k - 1], cycle[k]); */
1697 for (j = te->edges; od.edgedata[j]; j += 2)
1698 if (od.edgedata[j] == cycle[k])
1700 assert(od.edgedata[j]);
1701 cycle[k * 2 - 1] = j;
1703 /* now cycle looks like this: */
1704 /* te1 edge te2 edge te3 ... teN edge te1 0 */
1705 breakcycle(&od, cycle);
1706 /* restart with start of cycle */
1707 todo.count = cycstart + 1;
1709 POOL_DEBUG(SOLV_DEBUG_STATS, "cycles broken: %d\n", od.ncycles);
1710 POOL_DEBUG(SOLV_DEBUG_STATS, "cycle breaking took %d ms\n", solv_timems(now));
1712 now = solv_timems(0);
1713 /* now go through all broken cycles and create cycle edges to help
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 for (i = od.cycles.count - 3; i >= 0; i -= 3)
1722 if (od.cycles.elements[i + 2] < TYPE_REQ)
1723 addcycleedges(&od, od.cyclesdata.elements + od.cycles.elements[i], &todo);
1725 POOL_DEBUG(SOLV_DEBUG_STATS, "cycle edge creation took %d ms\n", solv_timems(now));
1730 /* all edges are finally set up and there are no cycles, now the easy part.
1731 * Create an ordered transaction */
1732 now = solv_timems(0);
1733 /* first invert all edges */
1734 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1735 te->mark = 1; /* term 0 */
1736 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1738 for (j = te->edges; od.edgedata[j]; j += 2)
1740 if ((od.edgedata[j + 1] & TYPE_BROKEN) != 0)
1742 od.tes[od.edgedata[j]].mark++;
1746 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1751 POOL_DEBUG(SOLV_DEBUG_STATS, "invedge space: %d\n", j + 1);
1752 od.invedgedata = solv_calloc(j + 1, sizeof(Id));
1753 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1755 for (j = te->edges; od.edgedata[j]; j += 2)
1757 if ((od.edgedata[j + 1] & TYPE_BROKEN) != 0)
1759 od.invedgedata[--od.tes[od.edgedata[j]].mark] = i;
1762 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1763 te->edges = te->mark; /* edges now points into invedgedata */
1764 od.edgedata = solv_free(od.edgedata);
1765 od.nedgedata = j + 1;
1767 /* now the final ordering */
1768 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1770 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1771 for (j = te->edges; od.invedgedata[j]; j++)
1772 od.tes[od.invedgedata[j]].mark++;
1774 queue_init(&samerepoq);
1775 queue_init(&uninstq);
1777 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1780 if (installed && pool->solvables[te->p].repo == installed)
1781 queue_push(&uninstq, i);
1783 queue_push(&todo, i);
1785 assert(todo.count > 0 || uninstq.count > 0);
1786 oldcount = tr->count;
1793 temedianr = solv_calloc(numte, sizeof(Id));
1794 for (i = 1; i < numte; i++)
1796 Solvable *s = pool->solvables + od.tes[i].p;
1797 if (installed && s->repo == installed)
1800 j = solvable_lookup_num(s, SOLVABLE_MEDIANR, 1);
1805 /* select an TE i */
1807 i = queue_shift(&uninstq);
1808 else if (samerepoq.count)
1809 i = queue_shift(&samerepoq);
1810 else if (todo.count)
1812 /* find next repo/media */
1813 for (j = 0; j < todo.count; j++)
1815 if (!j || temedianr[todo.elements[j]] < lastmedia)
1818 lastmedia = temedianr[todo.elements[j]];
1821 lastrepo = pool->solvables[od.tes[todo.elements[i]].p].repo;
1823 /* move all matching TEs to samerepoq */
1824 for (i = j = 0; j < todo.count; j++)
1826 int k = todo.elements[j];
1827 if (temedianr[k] == lastmedia && pool->solvables[od.tes[k].p].repo == lastrepo)
1828 queue_push(&samerepoq, k);
1830 todo.elements[i++] = k;
1834 assert(samerepoq.count);
1835 i = queue_shift(&samerepoq);
1841 queue_push(tr, te->p);
1843 printf("do %s [%d]\n", pool_solvid2str(pool, te->p), temedianr[i]);
1845 s = pool->solvables + te->p;
1846 for (j = te->edges; od.invedgedata[j]; j++)
1848 struct _TransactionElement *te2 = od.tes + od.invedgedata[j];
1849 assert(te2->mark > 0);
1850 if (--te2->mark == 0)
1852 Solvable *s = pool->solvables + te2->p;
1854 printf("free %s [%d]\n", pool_solvid2str(pool, te2->p), temedianr[od.invedgedata[j]]);
1856 if (installed && s->repo == installed)
1857 queue_push(&uninstq, od.invedgedata[j]);
1858 else if (s->repo == lastrepo && temedianr[od.invedgedata[j]] == lastmedia)
1859 queue_push(&samerepoq, od.invedgedata[j]);
1861 queue_push(&todo, od.invedgedata[j]);
1865 solv_free(temedianr);
1867 queue_free(&samerepoq);
1868 queue_free(&uninstq);
1870 for (i = 1, te = od.tes + i; i < numte; i++, te++)
1871 assert(te->mark == 0);
1873 /* add back obsoleted packages */
1874 transaction_add_obsoleted(trans);
1875 assert(tr->count == oldcount);
1877 POOL_DEBUG(SOLV_DEBUG_STATS, "creating new transaction took %d ms\n", solv_timems(now));
1878 POOL_DEBUG(SOLV_DEBUG_STATS, "transaction ordering took %d ms\n", solv_timems(start));
1880 if ((flags & SOLVER_TRANSACTION_KEEP_ORDERDATA) != 0)
1882 trans->orderdata = solv_calloc(1, sizeof(*trans->orderdata));
1883 trans->orderdata->tes = od.tes;
1884 trans->orderdata->ntes = numte;
1885 trans->orderdata->invedgedata = od.invedgedata;
1886 trans->orderdata->ninvedgedata = od.nedgedata;
1891 solv_free(od.invedgedata);
1893 queue_free(&od.cycles);
1894 queue_free(&od.cyclesdata);
1899 transaction_order_add_choices(Transaction *trans, Id chosen, Queue *choices)
1902 struct _TransactionOrderdata *od = trans->orderdata;
1903 struct _TransactionElement *te;
1906 return choices->count;
1909 /* initialization step */
1910 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1912 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1914 for (j = te->edges; od->invedgedata[j]; j++)
1915 od->tes[od->invedgedata[j]].mark++;
1917 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1919 queue_push(choices, te->p);
1920 return choices->count;
1922 for (i = 1, te = od->tes + i; i < od->ntes; i++, te++)
1923 if (te->p == chosen)
1926 return choices->count;
1929 /* hey! out-of-order installation! */
1932 for (j = te->edges; od->invedgedata[j]; j++)
1934 te = od->tes + od->invedgedata[j];
1935 assert(te->mark > 0 || te->mark == -1);
1936 if (te->mark > 0 && --te->mark == 0)
1937 queue_push(choices, te->p);
1939 return choices->count;
1943 transaction_add_obsoleted(Transaction *trans)
1945 Pool *pool = trans->pool;
1946 Repo *installed = pool->installed;
1953 if (!installed || !trans->steps.count)
1955 /* calculate upper bound */
1957 FOR_REPO_SOLVABLES(installed, p, s)
1958 if (MAPTST(&trans->transactsmap, p))
1963 steps = &trans->steps;
1964 queue_insertn(steps, 0, max, 0);
1967 map_init(&done, installed->end - installed->start);
1969 for (j = 0, i = max; i < steps->count; i++)
1971 p = trans->steps.elements[i];
1972 if (pool->solvables[p].repo == installed)
1974 if (!trans->transaction_installed[p - pool->installed->start])
1975 trans->steps.elements[j++] = p;
1978 trans->steps.elements[j++] = p;
1980 transaction_all_obs_pkgs(trans, p, &obsq);
1981 for (k = 0; k < obsq.count; k++)
1983 p = obsq.elements[k];
1984 assert(p >= installed->start && p < installed->end);
1985 if (MAPTST(&done, p - installed->start))
1987 MAPSET(&done, p - installed->start);
1988 trans->steps.elements[j++] = p;
1992 /* free unneeded space */
1993 queue_truncate(steps, j);
1999 transaction_check_pkg(Transaction *trans, Id tepkg, Id pkg, Map *ins, Map *seen, int onlyprereq, Id noconfpkg, int depth)
2001 Pool *pool = trans->pool;
2006 if (MAPTST(seen, pkg))
2009 s = pool->solvables + pkg;
2011 printf("- %*s%c%s\n", depth * 2, "", s->repo == pool->installed ? '-' : '+', pool_solvable2str(pool, s));
2017 reqp = s->repo->idarraydata + s->requires;
2018 while ((req = *reqp++) != 0)
2020 if (req == SOLVABLE_PREREQMARKER)
2025 if (onlyprereq && !inpre)
2027 if (!strncmp(pool_id2str(pool, req), "rpmlib(", 7))
2030 /* first check kept packages, then freshly installed, then not yet uninstalled */
2031 FOR_PROVIDES(p, pp, req)
2033 if (!MAPTST(ins, p))
2035 if (MAPTST(&trans->transactsmap, p))
2038 transaction_check_pkg(trans, tepkg, p, ins, seen, 0, noconfpkg, depth + 1);
2042 FOR_PROVIDES(p, pp, req)
2044 if (!MAPTST(ins, p))
2046 if (pool->solvables[p].repo == pool->installed)
2049 transaction_check_pkg(trans, tepkg, p, ins, seen, 0, noconfpkg, depth + 1);
2054 FOR_PROVIDES(p, pp, req)
2056 if (!MAPTST(ins, p))
2059 transaction_check_pkg(trans, tepkg, p, ins, seen, 0, noconfpkg, depth + 1);
2064 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));
2071 transaction_check_order(Transaction *trans)
2073 Pool *pool = trans->pool;
2079 POOL_DEBUG(SOLV_WARN, "\nchecking transaction order...\n");
2080 map_init(&ins, pool->nsolvables);
2081 map_init(&seen, pool->nsolvables);
2082 if (pool->installed)
2083 FOR_REPO_SOLVABLES(pool->installed, p, s)
2086 for (i = 0; i < trans->steps.count; i++)
2088 p = trans->steps.elements[i];
2089 s = pool->solvables + p;
2090 if (s->repo != pool->installed)
2092 if (s->repo != pool->installed)
2094 if (havescripts(pool, p))
2097 transaction_check_pkg(trans, p, p, &ins, &seen, 1, lastins, 0);
2099 if (s->repo == pool->installed)
2104 POOL_DEBUG(SOLV_WARN, "transaction order check done.\n");