/
rules.c
3096 lines (2885 loc) · 81.1 KB
/
rules.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2007-2009, Novell Inc.
*
* This program is licensed under the BSD license, read LICENSE.BSD
* for further information
*/
/*
* rules.c
*
* SAT based dependency solver
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include "solver.h"
#include "solver_private.h"
#include "bitmap.h"
#include "pool.h"
#include "poolarch.h"
#include "util.h"
#include "evr.h"
#include "policy.h"
#include "solverdebug.h"
#define RULES_BLOCK 63
static void addrpmruleinfo(Solver *solv, Id p, Id d, int type, Id dep);
static void solver_createcleandepsmap(Solver *solv, Map *cleandepsmap, int unneeded);
/*-------------------------------------------------------------------
* Check if dependency is possible
*
* mirrors solver_dep_fulfilled but uses map m instead of the decisionmap
* used in solver_addrpmrulesforweak and solver_createcleandepsmap
*/
static inline int
dep_possible(Solver *solv, Id dep, Map *m)
{
Pool *pool = solv->pool;
Id p, pp;
if (ISRELDEP(dep))
{
Reldep *rd = GETRELDEP(pool, dep);
if (rd->flags >= 8)
{
if (rd->flags == REL_AND)
{
if (!dep_possible(solv, rd->name, m))
return 0;
return dep_possible(solv, rd->evr, m);
}
if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_SPLITPROVIDES)
return solver_splitprovides(solv, rd->evr);
if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_INSTALLED)
return solver_dep_installed(solv, rd->evr);
}
}
FOR_PROVIDES(p, pp, dep)
{
if (MAPTST(m, p))
return 1;
}
return 0;
}
/********************************************************************
*
* Rule handling
*
* - unify rules, remove duplicates
*/
/*-------------------------------------------------------------------
*
* compare rules for unification sort
*
*/
static int
unifyrules_sortcmp(const void *ap, const void *bp, void *dp)
{
Pool *pool = dp;
Rule *a = (Rule *)ap;
Rule *b = (Rule *)bp;
Id *ad, *bd;
int x;
x = a->p - b->p;
if (x)
return x; /* p differs */
/* identical p */
if (a->d == 0 && b->d == 0)
return a->w2 - b->w2; /* assertion: return w2 diff */
if (a->d == 0) /* a is assertion, b not */
{
x = a->w2 - pool->whatprovidesdata[b->d];
return x ? x : -1;
}
if (b->d == 0) /* b is assertion, a not */
{
x = pool->whatprovidesdata[a->d] - b->w2;
return x ? x : 1;
}
/* compare whatprovidesdata */
ad = pool->whatprovidesdata + a->d;
bd = pool->whatprovidesdata + b->d;
while (*bd)
if ((x = *ad++ - *bd++) != 0)
return x;
return *ad;
}
int
solver_samerule(Solver *solv, Rule *r1, Rule *r2)
{
return unifyrules_sortcmp(r1, r2, solv->pool);
}
/*-------------------------------------------------------------------
*
* unify rules
* go over all rules and remove duplicates
*/
void
solver_unifyrules(Solver *solv)
{
Pool *pool = solv->pool;
int i, j;
Rule *ir, *jr;
if (solv->nrules <= 2) /* nothing to unify */
return;
/* sort rules first */
solv_sort(solv->rules + 1, solv->nrules - 1, sizeof(Rule), unifyrules_sortcmp, solv->pool);
/* prune rules
* i = unpruned
* j = pruned
*/
jr = 0;
for (i = j = 1, ir = solv->rules + i; i < solv->nrules; i++, ir++)
{
if (jr && !unifyrules_sortcmp(ir, jr, pool))
continue; /* prune! */
jr = solv->rules + j++; /* keep! */
if (ir != jr)
*jr = *ir;
}
/* reduced count from nrules to j rules */
POOL_DEBUG(SOLV_DEBUG_STATS, "pruned rules from %d to %d\n", solv->nrules, j);
/* adapt rule buffer */
solv->nrules = j;
solv->rules = solv_extend_resize(solv->rules, solv->nrules, sizeof(Rule), RULES_BLOCK);
/*
* debug: log rule statistics
*/
IF_POOLDEBUG (SOLV_DEBUG_STATS)
{
int binr = 0;
int lits = 0;
Id *dp;
Rule *r;
for (i = 1; i < solv->nrules; i++)
{
r = solv->rules + i;
if (r->d == 0)
binr++;
else
{
dp = solv->pool->whatprovidesdata + r->d;
while (*dp++)
lits++;
}
}
POOL_DEBUG(SOLV_DEBUG_STATS, " binary: %d\n", binr);
POOL_DEBUG(SOLV_DEBUG_STATS, " normal: %d, %d literals\n", solv->nrules - 1 - binr, lits);
}
}
#if 0
/*
* hash rule
*/
static Hashval
hashrule(Solver *solv, Id p, Id d, int n)
{
unsigned int x = (unsigned int)p;
int *dp;
if (n <= 1)
return (x * 37) ^ (unsigned int)d;
dp = solv->pool->whatprovidesdata + d;
while (*dp)
x = (x * 37) ^ (unsigned int)*dp++;
return x;
}
#endif
/*-------------------------------------------------------------------
*
*/
/*
* add rule
* p = direct literal; always < 0 for installed rpm rules
* d, if < 0 direct literal, if > 0 offset into whatprovides, if == 0 rule is assertion (look at p only)
*
*
* A requires b, b provided by B1,B2,B3 => (-A|B1|B2|B3)
*
* p < 0 : pkg id of A
* d > 0 : Offset in whatprovidesdata (list of providers of b)
*
* A conflicts b, b provided by B1,B2,B3 => (-A|-B1), (-A|-B2), (-A|-B3)
* p < 0 : pkg id of A
* d < 0 : Id of solvable (e.g. B1)
*
* d == 0: unary rule, assertion => (A) or (-A)
*
* Install: p > 0, d = 0 (A) user requested install
* Remove: p < 0, d = 0 (-A) user requested remove (also: uninstallable)
* Requires: p < 0, d > 0 (-A|B1|B2|...) d: <list of providers for requirement of p>
* Updates: p > 0, d > 0 (A|B1|B2|...) d: <list of updates for solvable p>
* Conflicts: p < 0, d < 0 (-A|-B) either p (conflict issuer) or d (conflict provider) (binary rule)
* also used for obsoletes
* ?: p > 0, d < 0 (A|-B)
* No-op ?: p = 0, d = 0 (null) (used as policy rule placeholder)
*
* resulting watches:
* ------------------
* Direct assertion (no watch needed) --> d = 0, w1 = p, w2 = 0
* Binary rule: p = first literal, d = 0, w2 = second literal, w1 = p
* every other : w1 = p, w2 = whatprovidesdata[d];
* Disabled rule: w1 = 0
*
* always returns a rule for non-rpm rules
*/
Rule *
solver_addrule(Solver *solv, Id p, Id d)
{
Pool *pool = solv->pool;
Rule *r = 0;
Id *dp = 0;
int n = 0; /* number of literals in rule - 1
0 = direct assertion (single literal)
1 = binary rule
>1 =
*/
/* it often happenes that requires lead to adding the same rpm rule
* multiple times, so we prune those duplicates right away to make
* the work for unifyrules a bit easier */
if (!solv->rpmrules_end) /* we add rpm rules */
{
r = solv->rules + solv->nrules - 1; /* get the last added rule */
if (r->p == p && r->d == d && (d != 0 || !r->w2))
return r;
}
/*
* compute number of literals (n) in rule
*/
if (d < 0)
{
/* always a binary rule */
if (p == d)
return 0; /* ignore self conflict */
n = 1;
}
else if (d > 0)
{
for (dp = pool->whatprovidesdata + d; *dp; dp++, n++)
if (*dp == -p)
return 0; /* rule is self-fulfilling */
if (n == 1) /* convert to binary rule */
d = dp[-1];
}
if (n == 1 && p > d && !solv->rpmrules_end)
{
/* smallest literal first so we can find dups */
n = p; p = d; d = n; /* p <-> d */
n = 1; /* re-set n, was used as temp var */
}
/*
* check for duplicate
*/
/* check if the last added rule (r) is exactly the same as what we're looking for. */
if (r && n == 1 && !r->d && r->p == p && r->w2 == d)
return r; /* binary rule */
/* have n-ary rule with same first literal, check other literals */
if (r && n > 1 && r->d && r->p == p)
{
/* Rule where d is an offset in whatprovidesdata */
Id *dp2;
if (d == r->d)
return r;
dp2 = pool->whatprovidesdata + r->d;
for (dp = pool->whatprovidesdata + d; *dp; dp++, dp2++)
if (*dp != *dp2)
break;
if (*dp == *dp2)
return r;
}
/*
* allocate new rule
*/
/* extend rule buffer */
solv->rules = solv_extend(solv->rules, solv->nrules, 1, sizeof(Rule), RULES_BLOCK);
r = solv->rules + solv->nrules++; /* point to rule space */
/*
* r = new rule
*/
r->p = p;
if (n == 0)
{
/* direct assertion, no watch needed */
r->d = 0;
r->w1 = p;
r->w2 = 0;
}
else if (n == 1)
{
/* binary rule */
r->d = 0;
r->w1 = p;
r->w2 = d;
}
else
{
r->d = d;
r->w1 = p;
r->w2 = pool->whatprovidesdata[d];
}
r->n1 = 0;
r->n2 = 0;
IF_POOLDEBUG (SOLV_DEBUG_RULE_CREATION)
{
POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, " Add rule: ");
solver_printrule(solv, SOLV_DEBUG_RULE_CREATION, r);
}
return r;
}
/******************************************************************************
***
*** rpm rule part: create rules representing the package dependencies
***
***/
/*
* special multiversion patch conflict handling:
* a patch conflict is also satisfied if some other
* version with the same name/arch that doesn't conflict
* gets installed. The generated rule is thus:
* -patch|-cpack|opack1|opack2|...
*/
static Id
makemultiversionconflict(Solver *solv, Id n, Id con)
{
Pool *pool = solv->pool;
Solvable *s, *sn;
Queue q;
Id p, pp, qbuf[64];
sn = pool->solvables + n;
queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
queue_push(&q, -n);
FOR_PROVIDES(p, pp, sn->name)
{
s = pool->solvables + p;
if (s->name != sn->name || s->arch != sn->arch)
continue;
if (!MAPTST(&solv->noobsoletes, p))
continue;
if (pool_match_nevr(pool, pool->solvables + p, con))
continue;
/* here we have a multiversion solvable that doesn't conflict */
/* thus we're not in conflict if it is installed */
queue_push(&q, p);
}
if (q.count == 1)
return -n; /* no other package found, generate normal conflict */
return pool_queuetowhatprovides(pool, &q);
}
static inline void
addrpmrule(Solver *solv, Id p, Id d, int type, Id dep)
{
if (!solv->ruleinfoq)
solver_addrule(solv, p, d);
else
addrpmruleinfo(solv, p, d, type, dep);
}
/*-------------------------------------------------------------------
*
* add (install) rules for solvable
*
* s: Solvable for which to add rules
* m: m[s] = 1 for solvables which have rules, prevent rule duplication
*
* Algorithm: 'visit all nodes of a graph'. The graph nodes are
* solvables, the edges their dependencies.
* Starting from an installed solvable, this will create all rules
* representing the graph created by the solvables dependencies.
*
* for unfulfilled requirements, conflicts, obsoletes,....
* add a negative assertion for solvables that are not installable
*
* It will also create rules for all solvables referenced by 's'
* i.e. descend to all providers of requirements of 's'
*
*/
void
solver_addrpmrulesforsolvable(Solver *solv, Solvable *s, Map *m)
{
Pool *pool = solv->pool;
Repo *installed = solv->installed;
/* 'work' queue. keeps Ids of solvables we still have to work on.
And buffer for it. */
Queue workq;
Id workqbuf[64];
int i;
/* if to add rules for broken deps ('rpm -V' functionality)
* 0 = yes, 1 = no
*/
int dontfix;
/* Id var and pointer for each dependency
* (not used in parallel)
*/
Id req, *reqp;
Id con, *conp;
Id obs, *obsp;
Id rec, *recp;
Id sug, *sugp;
Id p, pp; /* whatprovides loops */
Id *dp; /* ptr to 'whatprovides' */
Id n; /* Id for current solvable 's' */
queue_init_buffer(&workq, workqbuf, sizeof(workqbuf)/sizeof(*workqbuf));
queue_push(&workq, s - pool->solvables); /* push solvable Id to work queue */
/* loop until there's no more work left */
while (workq.count)
{
/*
* n: Id of solvable
* s: Pointer to solvable
*/
n = queue_shift(&workq); /* 'pop' next solvable to work on from queue */
if (m)
{
if (MAPTST(m, n)) /* continue if already visited */
continue;
MAPSET(m, n); /* mark as visited */
}
s = pool->solvables + n; /* s = Solvable in question */
dontfix = 0;
if (installed /* Installed system available */
&& s->repo == installed /* solvable is installed */
&& !solv->fixmap_all /* NOT repair errors in rpm dependency graph */
&& !(solv->fixmap.size && MAPTST(&solv->fixmap, n - installed->start)))
{
dontfix = 1; /* dont care about broken rpm deps */
}
if (!dontfix
&& s->arch != ARCH_SRC
&& s->arch != ARCH_NOSRC
&& !pool_installable(pool, s))
{
POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, "package %s [%d] is not installable\n", pool_solvable2str(pool, s), (Id)(s - pool->solvables));
addrpmrule(solv, -n, 0, SOLVER_RULE_RPM_NOT_INSTALLABLE, 0);
}
/* yet another SUSE hack, sigh */
if (pool->nscallback && !strncmp("product:", pool_id2str(pool, s->name), 8))
{
Id buddy = pool->nscallback(pool, pool->nscallbackdata, NAMESPACE_PRODUCTBUDDY, n);
if (buddy > 0 && buddy != SYSTEMSOLVABLE && buddy != n && buddy < pool->nsolvables)
{
addrpmrule(solv, n, -buddy, SOLVER_RULE_RPM_PACKAGE_REQUIRES, solvable_selfprovidedep(pool->solvables + n));
addrpmrule(solv, buddy, -n, SOLVER_RULE_RPM_PACKAGE_REQUIRES, solvable_selfprovidedep(pool->solvables + buddy));
if (m && !MAPTST(m, buddy))
queue_push(&workq, buddy);
}
}
/*-----------------------------------------
* check requires of s
*/
if (s->requires)
{
reqp = s->repo->idarraydata + s->requires;
while ((req = *reqp++) != 0) /* go through all requires */
{
if (req == SOLVABLE_PREREQMARKER) /* skip the marker */
continue;
/* find list of solvables providing 'req' */
dp = pool_whatprovides_ptr(pool, req);
if (*dp == SYSTEMSOLVABLE) /* always installed */
continue;
if (dontfix)
{
/* the strategy here is to not insist on dependencies
* that are already broken. so if we find one provider
* that was already installed, we know that the
* dependency was not broken before so we enforce it */
/* check if any of the providers for 'req' is installed */
for (i = 0; (p = dp[i]) != 0; i++)
{
if (pool->solvables[p].repo == installed)
break; /* provider was installed */
}
/* didn't find an installed provider: previously broken dependency */
if (!p)
{
POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, "ignoring broken requires %s of installed package %s\n", pool_dep2str(pool, req), pool_solvable2str(pool, s));
continue;
}
}
if (!*dp)
{
/* nothing provides req! */
POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, "package %s [%d] is not installable (%s)\n", pool_solvable2str(pool, s), (Id)(s - pool->solvables), pool_dep2str(pool, req));
addrpmrule(solv, -n, 0, SOLVER_RULE_RPM_NOTHING_PROVIDES_DEP, req);
continue;
}
IF_POOLDEBUG (SOLV_DEBUG_RULE_CREATION)
{
POOL_DEBUG(SOLV_DEBUG_RULE_CREATION," %s requires %s\n", pool_solvable2str(pool, s), pool_dep2str(pool, req));
for (i = 0; dp[i]; i++)
POOL_DEBUG(SOLV_DEBUG_RULE_CREATION, " provided by %s\n", pool_solvid2str(pool, dp[i]));
}
/* add 'requires' dependency */
/* rule: (-requestor|provider1|provider2|...|providerN) */
addrpmrule(solv, -n, dp - pool->whatprovidesdata, SOLVER_RULE_RPM_PACKAGE_REQUIRES, req);
/* descend the dependency tree
push all non-visited providers on the work queue */
if (m)
{
for (; *dp; dp++)
{
if (!MAPTST(m, *dp))
queue_push(&workq, *dp);
}
}
} /* while, requirements of n */
} /* if, requirements */
/* that's all we check for src packages */
if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
continue;
/*-----------------------------------------
* check conflicts of s
*/
if (s->conflicts)
{
int ispatch = 0;
/* we treat conflicts in patches a bit differen:
* - nevr matching
* - multiversion handling
* XXX: we should really handle this different, looking
* at the name is a bad hack
*/
if (!strncmp("patch:", pool_id2str(pool, s->name), 6))
ispatch = 1;
conp = s->repo->idarraydata + s->conflicts;
/* foreach conflicts of 's' */
while ((con = *conp++) != 0)
{
/* foreach providers of a conflict of 's' */
FOR_PROVIDES(p, pp, con)
{
if (ispatch && !pool_match_nevr(pool, pool->solvables + p, con))
continue;
/* dontfix: dont care about conflicts with already installed packs */
if (dontfix && pool->solvables[p].repo == installed)
continue;
/* p == n: self conflict */
if (p == n && pool->forbidselfconflicts)
{
if (ISRELDEP(con))
{
Reldep *rd = GETRELDEP(pool, con);
if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_OTHERPROVIDERS)
continue;
}
p = 0; /* make it a negative assertion, aka 'uninstallable' */
}
if (p && ispatch && solv->noobsoletes.size && MAPTST(&solv->noobsoletes, p) && ISRELDEP(con))
{
/* our patch conflicts with a noobsoletes (aka multiversion) package */
p = -makemultiversionconflict(solv, p, con);
}
/* rule: -n|-p: either solvable _or_ provider of conflict */
addrpmrule(solv, -n, -p, p ? SOLVER_RULE_RPM_PACKAGE_CONFLICT : SOLVER_RULE_RPM_SELF_CONFLICT, con);
}
}
}
/*-----------------------------------------
* check obsoletes and implicit obsoletes of a package
* if ignoreinstalledsobsoletes is not set, we're also checking
* obsoletes of installed packages (like newer rpm versions)
*/
if ((!installed || s->repo != installed) || !pool->noinstalledobsoletes)
{
int noobs = solv->noobsoletes.size && MAPTST(&solv->noobsoletes, n);
int isinstalled = (installed && s->repo == installed);
if (s->obsoletes && (!noobs || solv->keepexplicitobsoletes))
{
obsp = s->repo->idarraydata + s->obsoletes;
/* foreach obsoletes */
while ((obs = *obsp++) != 0)
{
/* foreach provider of an obsoletes of 's' */
FOR_PROVIDES(p, pp, obs)
{
Solvable *ps = pool->solvables + p;
if (p == n)
continue;
if (isinstalled && dontfix && ps->repo == installed)
continue; /* don't repair installed/installed problems */
if (!pool->obsoleteusesprovides /* obsoletes are matched names, not provides */
&& !pool_match_nevr(pool, ps, obs))
continue;
if (pool->obsoleteusescolors && !pool_colormatch(pool, s, ps))
continue;
if (!isinstalled)
addrpmrule(solv, -n, -p, SOLVER_RULE_RPM_PACKAGE_OBSOLETES, obs);
else
addrpmrule(solv, -n, -p, SOLVER_RULE_RPM_INSTALLEDPKG_OBSOLETES, obs);
}
}
}
/* check implicit obsoletes
* for installed packages we only need to check installed/installed problems (and
* only when dontfix is not set), as the others are picked up when looking at the
* uninstalled package.
*/
if (!isinstalled || !dontfix)
{
FOR_PROVIDES(p, pp, s->name)
{
Solvable *ps = pool->solvables + p;
if (p == n)
continue;
if (isinstalled && ps->repo != installed)
continue;
/* we still obsolete packages with same nevra, like rpm does */
/* (actually, rpm mixes those packages. yuck...) */
if (noobs && (s->name != ps->name || s->evr != ps->evr || s->arch != ps->arch))
continue;
if (!pool->implicitobsoleteusesprovides && s->name != ps->name)
continue;
if (pool->obsoleteusescolors && !pool_colormatch(pool, s, ps))
continue;
if (s->name == ps->name)
addrpmrule(solv, -n, -p, SOLVER_RULE_RPM_SAME_NAME, 0);
else
addrpmrule(solv, -n, -p, SOLVER_RULE_RPM_IMPLICIT_OBSOLETES, s->name);
}
}
}
/*-----------------------------------------
* add recommends to the work queue
*/
if (s->recommends && m)
{
recp = s->repo->idarraydata + s->recommends;
while ((rec = *recp++) != 0)
{
FOR_PROVIDES(p, pp, rec)
if (!MAPTST(m, p))
queue_push(&workq, p);
}
}
if (s->suggests && m)
{
sugp = s->repo->idarraydata + s->suggests;
while ((sug = *sugp++) != 0)
{
FOR_PROVIDES(p, pp, sug)
if (!MAPTST(m, p))
queue_push(&workq, p);
}
}
}
queue_free(&workq);
}
/*-------------------------------------------------------------------
*
* Add rules for packages possibly selected in by weak dependencies
*
* m: already added solvables
*/
void
solver_addrpmrulesforweak(Solver *solv, Map *m)
{
Pool *pool = solv->pool;
Solvable *s;
Id sup, *supp;
int i, n;
/* foreach solvable in pool */
for (i = n = 1; n < pool->nsolvables; i++, n++)
{
if (i == pool->nsolvables) /* wrap i */
i = 1;
if (MAPTST(m, i)) /* already added that one */
continue;
s = pool->solvables + i;
if (!pool_installable(pool, s)) /* only look at installable ones */
continue;
sup = 0;
if (s->supplements)
{
/* find possible supplements */
supp = s->repo->idarraydata + s->supplements;
while ((sup = *supp++) != 0)
if (dep_possible(solv, sup, m))
break;
}
/* if nothing found, check for enhances */
if (!sup && s->enhances)
{
supp = s->repo->idarraydata + s->enhances;
while ((sup = *supp++) != 0)
if (dep_possible(solv, sup, m))
break;
}
/* if nothing found, goto next solvables */
if (!sup)
continue;
solver_addrpmrulesforsolvable(solv, s, m);
n = 0; /* check all solvables again because we added solvables to m */
}
}
/*-------------------------------------------------------------------
*
* add package rules for possible updates
*
* s: solvable
* m: map of already visited solvables
* allow_all: 0 = dont allow downgrades, 1 = allow all candidates
*/
void
solver_addrpmrulesforupdaters(Solver *solv, Solvable *s, Map *m, int allow_all)
{
Pool *pool = solv->pool;
int i;
/* queue and buffer for it */
Queue qs;
Id qsbuf[64];
queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
/* find update candidates for 's' */
policy_findupdatepackages(solv, s, &qs, allow_all);
/* add rule for 's' if not already done */
if (!MAPTST(m, s - pool->solvables))
solver_addrpmrulesforsolvable(solv, s, m);
/* foreach update candidate, add rule if not already done */
for (i = 0; i < qs.count; i++)
if (!MAPTST(m, qs.elements[i]))
solver_addrpmrulesforsolvable(solv, pool->solvables + qs.elements[i], m);
queue_free(&qs);
}
/***********************************************************************
***
*** Update/Feature rule part
***
*** Those rules make sure an installed package isn't silently deleted
***
***/
static Id
finddistupgradepackages(Solver *solv, Solvable *s, Queue *qs, int allow_all)
{
Pool *pool = solv->pool;
int i;
policy_findupdatepackages(solv, s, qs, allow_all ? allow_all : 2);
if (!qs->count)
{
if (allow_all)
return 0; /* orphaned, don't create feature rule */
/* check if this is an orphaned package */
policy_findupdatepackages(solv, s, qs, 1);
if (!qs->count)
return 0; /* orphaned, don't create update rule */
qs->count = 0;
return -SYSTEMSOLVABLE; /* supported but not installable */
}
if (allow_all)
return s - pool->solvables;
/* check if it is ok to keep the installed package */
for (i = 0; i < qs->count; i++)
{
Solvable *ns = pool->solvables + qs->elements[i];
if (s->evr == ns->evr && solvable_identical(s, ns))
return s - pool->solvables;
}
/* nope, it must be some other package */
return -SYSTEMSOLVABLE;
}
/* add packages from the dup repositories to the update candidates
* this isn't needed for the global dup mode as all packages are
* from dup repos in that case */
static void
addduppackages(Solver *solv, Solvable *s, Queue *qs)
{
Queue dupqs;
Id p, dupqsbuf[64];
int i;
int oldnoupdateprovide = solv->noupdateprovide;
queue_init_buffer(&dupqs, dupqsbuf, sizeof(dupqsbuf)/sizeof(*dupqsbuf));
solv->noupdateprovide = 1;
policy_findupdatepackages(solv, s, &dupqs, 2);
solv->noupdateprovide = oldnoupdateprovide;
for (i = 0; i < dupqs.count; i++)
{
p = dupqs.elements[i];
if (MAPTST(&solv->dupmap, p))
queue_pushunique(qs, p);
}
queue_free(&dupqs);
}
/*-------------------------------------------------------------------
*
* add rule for update
* (A|A1|A2|A3...) An = update candidates for A
*
* s = (installed) solvable
*/
void
solver_addupdaterule(Solver *solv, Solvable *s, int allow_all)
{
/* installed packages get a special upgrade allowed rule */
Pool *pool = solv->pool;
Id p, d;
Queue qs;
Id qsbuf[64];
queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
p = s - pool->solvables;
/* find update candidates for 's' */
if (solv->dupmap_all)
p = finddistupgradepackages(solv, s, &qs, allow_all);
else
policy_findupdatepackages(solv, s, &qs, allow_all);
if (!allow_all && !solv->dupmap_all && solv->dupinvolvedmap.size && MAPTST(&solv->dupinvolvedmap, p))
addduppackages(solv, s, &qs);
if (!allow_all && qs.count && solv->noobsoletes.size)
{
int i, j;
d = pool_queuetowhatprovides(pool, &qs);
/* filter out all noobsoletes packages as they don't update */
for (i = j = 0; i < qs.count; i++)
{
if (MAPTST(&solv->noobsoletes, qs.elements[i]))
{
/* it's ok if they have same nevra */
Solvable *ps = pool->solvables + qs.elements[i];
if (ps->name != s->name || ps->evr != s->evr || ps->arch != s->arch)
continue;
}
qs.elements[j++] = qs.elements[i];
}
if (j < qs.count)
{
if (d && solv->installed && s->repo == solv->installed &&
(solv->updatemap_all || (solv->updatemap.size && MAPTST(&solv->updatemap, s - pool->solvables - solv->installed->start))))
{
if (!solv->multiversionupdaters)
solv->multiversionupdaters = solv_calloc(solv->installed->end - solv->installed->start, sizeof(Id));
solv->multiversionupdaters[s - pool->solvables - solv->installed->start] = d;
}
if (j == 0 && p == -SYSTEMSOLVABLE && solv->dupmap_all)
{
queue_push(&solv->orphaned, s - pool->solvables); /* treat as orphaned */
j = qs.count;
}
qs.count = j;
}
}
if (qs.count && p == -SYSTEMSOLVABLE)
p = queue_shift(&qs);
d = qs.count ? pool_queuetowhatprovides(pool, &qs) : 0;
queue_free(&qs);
solver_addrule(solv, p, d); /* allow update of s */
}
static inline void
disableupdaterule(Solver *solv, Id p)
{
Rule *r;
MAPSET(&solv->noupdate, p - solv->installed->start);
r = solv->rules + solv->updaterules + (p - solv->installed->start);
if (r->p && r->d >= 0)
solver_disablerule(solv, r);
r = solv->rules + solv->featurerules + (p - solv->installed->start);
if (r->p && r->d >= 0)
solver_disablerule(solv, r);
}
static inline void
reenableupdaterule(Solver *solv, Id p)
{
Pool *pool = solv->pool;
Rule *r;
MAPCLR(&solv->noupdate, p - solv->installed->start);
r = solv->rules + solv->updaterules + (p - solv->installed->start);
if (r->p)
{
if (r->d >= 0)
return;
solver_enablerule(solv, r);
IF_POOLDEBUG (SOLV_DEBUG_SOLUTIONS)
{
POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "@@@ re-enabling ");
solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, r);
}