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
|
/** \ingroup rpmts
* \file lib/depends.c
*/
#include "system.h"
#include <rpm/rpmcli.h> /* XXX rpmcliPackagesTotal */
#include <rpm/rpmlib.h> /* rpmVersionCompare, rpmlib provides */
#include <rpm/rpmtag.h>
#include <rpm/rpmlog.h>
#include <rpm/rpmdb.h>
#include <rpm/rpmds.h>
#include <rpm/rpmfi.h>
#include "lib/rpmdb_internal.h" /* XXX response cache needs dbiOpen et al. */
#include "lib/rpmts_internal.h"
#include "debug.h"
static int _cacheDependsRC = 1;
const char * const rpmNAME = PACKAGE;
const char * const rpmEVR = VERSION;
const int rpmFLAGS = RPMSENSE_EQUAL;
/* rpmlib provides */
static rpmds rpmlibP = NULL;
/**
* Compare removed package instances (qsort/bsearch).
* @param a 1st instance address
* @param b 2nd instance address
* @return result of comparison
*/
static int intcmp(const void * a, const void * b)
{
const int * aptr = a;
const int * bptr = b;
int rc = (*aptr - *bptr);
return rc;
}
/**
* Add removed package instance to ordered transaction set.
* @param ts transaction set
* @param h header
* @param depends installed package of pair (or RPMAL_NOMATCH on erase)
* @return 0 on success
*/
static int removePackage(rpmts ts, Header h, rpmte depends)
{
rpmte p;
unsigned int dboffset = headerGetInstance(h);
/* Filter out duplicate erasures. */
if (ts->numRemovedPackages > 0 && ts->removedPackages != NULL) {
if (bsearch(&dboffset, ts->removedPackages, ts->numRemovedPackages,
sizeof(*ts->removedPackages), intcmp) != NULL)
return 0;
}
if (ts->numRemovedPackages == ts->allocedRemovedPackages) {
ts->allocedRemovedPackages += ts->delta;
ts->removedPackages = xrealloc(ts->removedPackages,
sizeof(ts->removedPackages) * ts->allocedRemovedPackages);
}
if (ts->removedPackages != NULL) { /* XXX can't happen. */
ts->removedPackages[ts->numRemovedPackages] = dboffset;
ts->numRemovedPackages++;
if (ts->numRemovedPackages > 1)
qsort(ts->removedPackages, ts->numRemovedPackages,
sizeof(*ts->removedPackages), intcmp);
}
if (ts->orderCount >= ts->orderAlloced) {
ts->orderAlloced += (ts->orderCount - ts->orderAlloced) + ts->delta;
ts->order = xrealloc(ts->order, sizeof(*ts->order) * ts->orderAlloced);
}
p = rpmteNew(ts, h, TR_REMOVED, NULL, NULL, -1);
rpmteSetDependsOn(p, depends);
ts->order[ts->orderCount] = p;
ts->orderCount++;
return 0;
}
int rpmtsAddInstallElement(rpmts ts, Header h,
fnpyKey key, int upgrade, rpmRelocation * relocs)
{
rpm_color_t tscolor = rpmtsColor(ts);
rpm_color_t dscolor;
rpm_color_t hcolor;
rpm_color_t ohcolor;
rpmdbMatchIterator mi;
Header oh;
int isSource;
int duplicate = 0;
rpmtsi pi = NULL; rpmte p;
struct rpmtd_s td;
const char * arch = NULL;
const char * os = NULL;
rpmds oldChk = NULL, newChk = NULL, sameChk = NULL;
rpmds obsoletes;
int xx;
int ec = 0;
int rc;
int oc;
/*
* Check for previously added versions with the same name and arch/os.
* FIXME: only catches previously added, older packages.
*/
if (headerGet(h, RPMTAG_ARCH, &td, HEADERGET_MINMEM))
arch = rpmtdGetString(&td);
if (headerGet(h, RPMTAG_OS, &td, HEADERGET_MINMEM))
os = rpmtdGetString(&td);
hcolor = headerGetColor(h);
/* Check for supported payload format if it's a package */
if (key && headerCheckPayloadFormat(h) != RPMRC_OK) {
ec = 1;
goto exit;
}
if (ts->addedPackages == NULL) {
ts->addedPackages = rpmalCreate(5, tscolor, rpmtsPrefColor(ts));
}
/* XXX Always add source headers. */
isSource = headerIsSource(h);
if (isSource) {
oc = ts->orderCount;
goto addheader;
}
oldChk = rpmdsThis(h, RPMTAG_REQUIRENAME, (RPMSENSE_LESS));
newChk = rpmdsThis(h, RPMTAG_REQUIRENAME, (RPMSENSE_GREATER));
sameChk = rpmdsThis(h, RPMTAG_REQUIRENAME, (RPMSENSE_EQUAL));
/* XXX can't use rpmtsiNext() filter or oc will have wrong value. */
for (pi = rpmtsiInit(ts), oc = 0; (p = rpmtsiNext(pi, 0)) != NULL; oc++) {
rpmds this;
const char *pkgNEVR, *addNEVR;
int skip = 0;
/* XXX Only added packages need be checked for dupes. */
if (rpmteType(p) == TR_REMOVED)
continue;
/* XXX Never check source headers. */
if (rpmteIsSource(p))
continue;
if (tscolor) {
const char * parch;
const char * pos;
if (arch == NULL || (parch = rpmteA(p)) == NULL)
continue;
if (os == NULL || (pos = rpmteO(p)) == NULL)
continue;
if (strcmp(arch, parch) || strcmp(os, pos))
continue;
}
/* OK, binary rpm's with same arch and os. Check NEVR. */
if ((this = rpmteDS(p, RPMTAG_NAME)) == NULL)
continue; /* XXX can't happen */
/*
* Always skip identical NEVR.
* On upgrade, if newer NEVR was previously added,
* then skip adding older.
*/
if (rpmdsCompare(sameChk, this)) {
skip = 1;
addNEVR = rpmdsDNEVR(sameChk);
} else if (upgrade && rpmdsCompare(newChk, this)) {
skip = 1;
addNEVR = rpmdsDNEVR(newChk);
}
if (skip) {
pkgNEVR = rpmdsDNEVR(this);
if (rpmIsVerbose())
rpmlog(RPMLOG_WARNING,
_("package %s was already added, skipping %s\n"),
(pkgNEVR ? pkgNEVR + 2 : "?pkgNEVR?"),
(addNEVR ? addNEVR + 2 : "?addNEVR?"));
ec = 0;
goto exit;
}
/*
* On upgrade, if older NEVR was previously added,
* then replace old with new.
*/
rc = rpmdsCompare(oldChk, this);
if (upgrade && rc != 0) {
pkgNEVR = rpmdsDNEVR(this);
addNEVR = rpmdsDNEVR(newChk);
if (rpmIsVerbose())
rpmlog(RPMLOG_WARNING,
_("package %s was already added, replacing with %s\n"),
(pkgNEVR ? pkgNEVR + 2 : "?pkgNEVR?"),
(addNEVR ? addNEVR + 2 : "?addNEVR?"));
duplicate = 1;
rpmalDel(ts->addedPackages, p);
break;
}
}
pi = rpmtsiFree(pi);
/* If newer NEVR was already added, exit now. */
if (ec)
goto exit;
addheader:
if (oc >= ts->orderAlloced) {
ts->orderAlloced += (oc - ts->orderAlloced) + ts->delta;
ts->order = xrealloc(ts->order, ts->orderAlloced * sizeof(*ts->order));
}
p = rpmteNew(ts, h, TR_ADDED, key, relocs, -1);
if (duplicate && oc < ts->orderCount) {
ts->order[oc] = rpmteFree(ts->order[oc]);
}
ts->order[oc] = p;
if (!duplicate) {
ts->orderCount++;
rpmcliPackagesTotal++;
}
rpmalAdd(ts->addedPackages, p);
if (!duplicate) {
ts->numAddedPackages++;
}
/* XXX rpmgi hack: Save header in transaction element if requested. */
if (upgrade & 0x2)
(void) rpmteSetHeader(p, h);
/* If not upgrading, then we're done. */
if (!(upgrade & 0x1))
goto exit;
/* XXX binary rpms always have RPMTAG_SOURCERPM, source rpms do not */
if (isSource)
goto exit;
/* Do lazy (readonly?) open of rpm database. */
if (rpmtsGetRdb(ts) == NULL && rpmtsGetDBMode(ts) != -1) {
if ((ec = rpmtsOpenDB(ts, rpmtsGetDBMode(ts))) != 0)
goto exit;
}
/* On upgrade, erase older packages of same color (if any). */
mi = rpmtsInitIterator(ts, RPMTAG_NAME, rpmteN(p), 0);
while((oh = rpmdbNextIterator(mi)) != NULL) {
/* Ignore colored packages not in our rainbow. */
ohcolor = headerGetColor(oh);
if (tscolor && hcolor && ohcolor && !(hcolor & ohcolor))
continue;
/* Skip packages that contain identical NEVR. */
if (rpmVersionCompare(h, oh) == 0)
continue;
xx = removePackage(ts, oh, p);
}
mi = rpmdbFreeIterator(mi);
obsoletes = rpmdsLink(rpmteDS(p, RPMTAG_OBSOLETENAME), RPMDBG_M("Obsoletes"));
obsoletes = rpmdsInit(obsoletes);
if (obsoletes != NULL)
while (rpmdsNext(obsoletes) >= 0) {
const char * Name;
if ((Name = rpmdsN(obsoletes)) == NULL)
continue; /* XXX can't happen */
/* Ignore colored obsoletes not in our rainbow. */
#if 0
dscolor = rpmdsColor(obsoletes);
#else
dscolor = hcolor;
#endif
/* XXX obsoletes are never colored, so this is for future devel. */
if (tscolor && dscolor && !(tscolor & dscolor))
continue;
/* XXX avoid self-obsoleting packages. */
if (!strcmp(rpmteN(p), Name))
continue;
if (Name[0] == '/')
mi = rpmtsInitIterator(ts, RPMTAG_BASENAMES, Name, 0);
else
mi = rpmtsInitIterator(ts, RPMTAG_NAME, Name, 0);
xx = rpmdbPruneIterator(mi,
ts->removedPackages, ts->numRemovedPackages, 1);
while((oh = rpmdbNextIterator(mi)) != NULL) {
/* Ignore colored packages not in our rainbow. */
ohcolor = headerGetColor(oh);
/* XXX provides *are* colored, effectively limiting Obsoletes:
to matching only colored Provides: based on pkg coloring. */
if (tscolor && hcolor && ohcolor && !(hcolor & ohcolor))
continue;
/*
* Rpm prior to 3.0.3 does not have versioned obsoletes.
* If no obsoletes version info is available, match all names.
*/
if (rpmdsEVR(obsoletes) == NULL
|| rpmdsAnyMatchesDep(oh, obsoletes, _rpmds_nopromote)) {
char * ohNEVRA = headerGetNEVRA(oh, NULL);
#ifdef DYING /* XXX see http://bugzilla.redhat.com #134497 */
if (rpmVersionCompare(h, oh))
#endif
xx = removePackage(ts, oh, p);
rpmlog(RPMLOG_DEBUG, " Obsoletes: %s\t\terases %s\n",
rpmdsDNEVR(obsoletes)+2, ohNEVRA);
ohNEVRA = _free(ohNEVRA);
}
}
mi = rpmdbFreeIterator(mi);
}
obsoletes = rpmdsFree(obsoletes);
ec = 0;
exit:
oldChk = rpmdsFree(oldChk);
newChk = rpmdsFree(newChk);
sameChk = rpmdsFree(sameChk);
pi = rpmtsiFree(pi);
return ec;
}
int rpmtsAddEraseElement(rpmts ts, Header h, int dboffset)
{
return removePackage(ts, h, NULL);
}
/**
* Check dep for an unsatisfied dependency.
* @param ts transaction set
* @param dep dependency
* @param adding dependency is from added package set?
* @return 0 if satisfied, 1 if not satisfied, 2 if error
*/
static int unsatisfiedDepend(rpmts ts, rpmds dep, int adding)
{
DBT key;
DBT data;
rpmdbMatchIterator mi;
const char * Name;
Header h;
int _cacheThisRC = 1;
int rc;
int xx;
int retrying = 0;
if ((Name = rpmdsN(dep)) == NULL)
return 0; /* XXX can't happen */
/*
* Check if dbiOpen/dbiPut failed (e.g. permissions), we can't cache.
*/
if (_cacheDependsRC) {
dbiIndex dbi;
dbi = dbiOpen(rpmtsGetRdb(ts), RPMDBI_DEPENDS, 0);
if (dbi == NULL)
_cacheDependsRC = 0;
else {
const char * DNEVR;
rc = -1;
if ((DNEVR = rpmdsDNEVR(dep)) != NULL) {
DBC * dbcursor = NULL;
void * datap = NULL;
size_t datalen = 0;
size_t DNEVRlen = strlen(DNEVR);
xx = dbiCopen(dbi, dbi->dbi_txnid, &dbcursor, 0);
memset(&key, 0, sizeof(key));
key.data = (void *) DNEVR;
key.size = DNEVRlen;
memset(&data, 0, sizeof(data));
data.data = datap;
data.size = datalen;
/* FIX: data->data may be NULL */
xx = dbiGet(dbi, dbcursor, &key, &data, DB_SET);
DNEVR = key.data;
DNEVRlen = key.size;
datap = data.data;
datalen = data.size;
if (xx == 0 && datap && datalen == 4)
memcpy(&rc, datap, datalen);
xx = dbiCclose(dbi, dbcursor, 0);
}
if (rc >= 0) {
rpmdsNotify(dep, _("(cached)"), rc);
return rc;
}
}
}
retry:
rc = 0; /* assume dependency is satisfied */
/*
* New features in rpm packaging implicitly add versioned dependencies
* on rpmlib provides. The dependencies look like "rpmlib(YaddaYadda)".
* Check those dependencies now.
*/
if (rpmdsFlags(dep) & RPMSENSE_RPMLIB) {
static int oneshot = -1;
if (oneshot)
oneshot = rpmdsRpmlib(&rpmlibP, NULL);
if (rpmlibP != NULL && rpmdsSearch(rpmlibP, dep) >= 0) {
rpmdsNotify(dep, _("(rpmlib provides)"), rc);
goto exit;
}
goto unsatisfied;
}
/* Search added packages for the dependency. */
if (rpmalSatisfiesDepend(ts->addedPackages, dep) != NULL) {
/*
* XXX Ick, context sensitive answers from dependency cache.
* XXX Always resolve added dependencies within context to disambiguate.
*/
if (_rpmds_nopromote)
_cacheThisRC = 0;
goto exit;
}
/* XXX only the installer does not have the database open here. */
if (rpmtsGetRdb(ts) != NULL) {
if (Name[0] == '/') {
/* depFlags better be 0! */
mi = rpmtsInitIterator(ts, RPMTAG_BASENAMES, Name, 0);
(void) rpmdbPruneIterator(mi,
ts->removedPackages, ts->numRemovedPackages, 1);
while ((h = rpmdbNextIterator(mi)) != NULL) {
rpmdsNotify(dep, _("(db files)"), rc);
mi = rpmdbFreeIterator(mi);
goto exit;
}
mi = rpmdbFreeIterator(mi);
}
mi = rpmtsInitIterator(ts, RPMTAG_PROVIDENAME, Name, 0);
(void) rpmdbPruneIterator(mi,
ts->removedPackages, ts->numRemovedPackages, 1);
while ((h = rpmdbNextIterator(mi)) != NULL) {
if (rpmdsAnyMatchesDep(h, dep, _rpmds_nopromote)) {
rpmdsNotify(dep, _("(db provides)"), rc);
mi = rpmdbFreeIterator(mi);
goto exit;
}
}
mi = rpmdbFreeIterator(mi);
}
/*
* Search for an unsatisfied dependency.
*/
if (adding && !retrying && !(rpmtsFlags(ts) & RPMTRANS_FLAG_NOSUGGEST)) {
if (ts->solve != NULL) {
xx = (*ts->solve) (ts, dep, ts->solveData);
if (xx == 0)
goto exit;
if (xx == -1) {
retrying = 1;
rpmalMakeIndex(ts->addedPackages);
goto retry;
}
}
}
unsatisfied:
rc = 1; /* dependency is unsatisfied */
rpmdsNotify(dep, NULL, rc);
exit:
/*
* If dbiOpen/dbiPut fails (e.g. permissions), we can't cache.
*/
if (_cacheDependsRC && _cacheThisRC) {
dbiIndex dbi;
dbi = dbiOpen(rpmtsGetRdb(ts), RPMDBI_DEPENDS, 0);
if (dbi == NULL) {
_cacheDependsRC = 0;
} else {
const char * DNEVR;
xx = 0;
if ((DNEVR = rpmdsDNEVR(dep)) != NULL) {
DBC * dbcursor = NULL;
size_t DNEVRlen = strlen(DNEVR);
xx = dbiCopen(dbi, dbi->dbi_txnid, &dbcursor, DB_WRITECURSOR);
memset(&key, 0, sizeof(key));
key.data = (void *) DNEVR;
key.size = DNEVRlen;
memset(&data, 0, sizeof(data));
data.data = &rc;
data.size = sizeof(rc);
xx = dbiPut(dbi, dbcursor, &key, &data, 0);
xx = dbiCclose(dbi, dbcursor, DB_WRITECURSOR);
}
if (xx)
_cacheDependsRC = 0;
}
}
return rc;
}
/**
* Check added requires/conflicts against against installed+added packages.
* @param ts transaction set
* @param pkgNEVRA package name-version-release.arch
* @param requires Requires: dependencies (or NULL)
* @param conflicts Conflicts: dependencies (or NULL)
* @param depName dependency name to filter (or NULL)
* @param tscolor color bits for transaction set (0 disables)
* @param adding dependency is from added package set?
* @return 0 no problems found
*/
static int checkPackageDeps(rpmts ts, const char * pkgNEVRA,
rpmds requires, rpmds conflicts,
const char * depName, rpm_color_t tscolor, int adding)
{
rpm_color_t dscolor;
const char * Name;
int rc;
int ourrc = 0;
requires = rpmdsInit(requires);
if (requires != NULL)
while (!ourrc && rpmdsNext(requires) >= 0) {
if ((Name = rpmdsN(requires)) == NULL)
continue; /* XXX can't happen */
/* Filter out requires that came along for the ride. */
if (depName != NULL && strcmp(depName, Name))
continue;
/* Ignore colored requires not in our rainbow. */
dscolor = rpmdsColor(requires);
if (tscolor && dscolor && !(tscolor & dscolor))
continue;
rc = unsatisfiedDepend(ts, requires, adding);
switch (rc) {
case 0: /* requirements are satisfied. */
break;
case 1: /* requirements are not satisfied. */
rpmdsProblem(ts->probs, pkgNEVRA, requires, NULL, adding);
break;
case 2: /* something went wrong! */
default:
ourrc = 1;
break;
}
}
conflicts = rpmdsInit(conflicts);
if (conflicts != NULL)
while (!ourrc && rpmdsNext(conflicts) >= 0) {
if ((Name = rpmdsN(conflicts)) == NULL)
continue; /* XXX can't happen */
/* Filter out conflicts that came along for the ride. */
if (depName != NULL && strcmp(depName, Name))
continue;
/* Ignore colored conflicts not in our rainbow. */
dscolor = rpmdsColor(conflicts);
if (tscolor && dscolor && !(tscolor & dscolor))
continue;
rc = unsatisfiedDepend(ts, conflicts, adding);
/* 1 == unsatisfied, 0 == satsisfied */
switch (rc) {
case 0: /* conflicts exist. */
rpmdsProblem(ts->probs, pkgNEVRA, conflicts, NULL, adding);
break;
case 1: /* conflicts don't exist. */
break;
case 2: /* something went wrong! */
default:
ourrc = 1;
break;
}
}
return ourrc;
}
/**
* Check dependency against installed packages.
* Adding: check name/provides dep against each conflict match,
* Erasing: check name/provides/filename dep against each requiredby match.
* @param ts transaction set
* @param dep dependency name
* @param mi rpm database iterator
* @param adding dependency is from added package set?
* @return 0 no problems found
*/
static int checkPackageSet(rpmts ts, const char * dep,
rpmdbMatchIterator mi, int adding)
{
Header h;
int ec = 0;
(void) rpmdbPruneIterator(mi,
ts->removedPackages, ts->numRemovedPackages, 1);
while ((h = rpmdbNextIterator(mi)) != NULL) {
char * pkgNEVRA;
rpmds requires, conflicts;
int rc;
pkgNEVRA = headerGetNEVRA(h, NULL);
requires = rpmdsNew(h, RPMTAG_REQUIRENAME, 0);
(void) rpmdsSetNoPromote(requires, _rpmds_nopromote);
conflicts = rpmdsNew(h, RPMTAG_CONFLICTNAME, 0);
(void) rpmdsSetNoPromote(conflicts, _rpmds_nopromote);
rc = checkPackageDeps(ts, pkgNEVRA, requires, conflicts, dep, 0, adding);
conflicts = rpmdsFree(conflicts);
requires = rpmdsFree(requires);
pkgNEVRA = _free(pkgNEVRA);
if (rc) {
ec = 1;
break;
}
}
mi = rpmdbFreeIterator(mi);
return ec;
}
/**
* Check to-be-erased dependencies against installed requires.
* @param ts transaction set
* @param dep requires name
* @return 0 no problems found
*/
static int checkDependentPackages(rpmts ts, const char * dep)
{
rpmdbMatchIterator mi;
mi = rpmtsInitIterator(ts, RPMTAG_REQUIRENAME, dep, 0);
return checkPackageSet(ts, dep, mi, 0);
}
/**
* Check to-be-added dependencies against installed conflicts.
* @param ts transaction set
* @param dep conflicts name
* @return 0 no problems found
*/
static int checkDependentConflicts(rpmts ts, const char * dep)
{
int rc = 0;
if (rpmtsGetRdb(ts) != NULL) { /* XXX is this necessary? */
rpmdbMatchIterator mi;
mi = rpmtsInitIterator(ts, RPMTAG_CONFLICTNAME, dep, 0);
rc = checkPackageSet(ts, dep, mi, 1);
}
return rc;
}
int rpmtsCheck(rpmts ts)
{
rpm_color_t tscolor = rpmtsColor(ts);
rpmdbMatchIterator mi = NULL;
rpmtsi pi = NULL; rpmte p;
int closeatexit = 0;
int xx;
int rc;
(void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_CHECK), 0);
/* Do lazy, readonly, open of rpm database. */
if (rpmtsGetRdb(ts) == NULL && rpmtsGetDBMode(ts) != -1) {
if ((rc = rpmtsOpenDB(ts, rpmtsGetDBMode(ts))) != 0)
goto exit;
closeatexit = 1;
}
ts->probs = rpmpsFree(ts->probs);
ts->probs = rpmpsCreate();
rpmalMakeIndex(ts->addedPackages);
/*
* Look at all of the added packages and make sure their dependencies
* are satisfied.
*/
pi = rpmtsiInit(ts);
while ((p = rpmtsiNext(pi, TR_ADDED)) != NULL) {
rpmds provides;
/* FIX: rpmts{A,O} can return null. */
rpmlog(RPMLOG_DEBUG, "========== +++ %s %s/%s 0x%x\n",
rpmteNEVR(p), rpmteA(p), rpmteO(p), rpmteColor(p));
rc = checkPackageDeps(ts, rpmteNEVRA(p),
rpmteDS(p, RPMTAG_REQUIRENAME),
rpmteDS(p, RPMTAG_CONFLICTNAME),
NULL,
tscolor, 1);
if (rc)
goto exit;
rc = 0;
provides = rpmdsInit(rpmteDS(p, RPMTAG_PROVIDENAME));
while (rpmdsNext(provides) >= 0) {
const char * Name;
if ((Name = rpmdsN(provides)) == NULL)
continue; /* XXX can't happen */
/* Adding: check provides key against conflicts matches. */
if (!checkDependentConflicts(ts, Name))
continue;
rc = 1;
break;
}
if (rc)
goto exit;
}
pi = rpmtsiFree(pi);
/*
* Look at the removed packages and make sure they aren't critical.
*/
pi = rpmtsiInit(ts);
while ((p = rpmtsiNext(pi, TR_REMOVED)) != NULL) {
rpmds provides = rpmdsInit(rpmteDS(p, RPMTAG_PROVIDENAME));
rpmfi fi;
/* FIX: rpmts{A,O} can return null. */
rpmlog(RPMLOG_DEBUG, "========== --- %s %s/%s 0x%x\n",
rpmteNEVR(p), rpmteA(p), rpmteO(p), rpmteColor(p));
rc = 0;
while (rpmdsNext(provides) >= 0) {
const char * Name;
if ((Name = rpmdsN(provides)) == NULL)
continue; /* XXX can't happen */
/* Erasing: check provides against requiredby matches. */
if (!checkDependentPackages(ts, Name))
continue;
rc = 1;
break;
}
if (rc)
goto exit;
rc = 0;
fi = rpmteFI(p);
fi = rpmfiInit(fi, 0);
while (rpmfiNext(fi) >= 0) {
const char * fn = rpmfiFN(fi);
/* Erasing: check filename against requiredby matches. */
if (!checkDependentPackages(ts, fn))
continue;
rc = 1;
break;
}
if (rc)
goto exit;
}
pi = rpmtsiFree(pi);
rc = 0;
exit:
mi = rpmdbFreeIterator(mi);
pi = rpmtsiFree(pi);
(void) rpmswExit(rpmtsOp(ts, RPMTS_OP_CHECK), 0);
if (closeatexit)
xx = rpmtsCloseDB(ts);
else if (_cacheDependsRC)
xx = rpmdbCloseDBI(rpmtsGetRdb(ts), RPMDBI_DEPENDS);
return rc;
}
|