forked from rpm-software-management/rpm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtransaction.c
1792 lines (1554 loc) · 49.2 KB
/
transaction.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
/** \ingroup rpmts
* \file lib/transaction.c
*/
#include "system.h"
#include <inttypes.h>
#include <libgen.h>
#include <rpm/rpmlib.h> /* rpmMachineScore, rpmReadPackageFile */
#include <rpm/rpmmacro.h> /* XXX for rpmExpand */
#include <rpm/rpmlog.h>
#include <rpm/rpmdb.h>
#include <rpm/rpmds.h>
#include <rpm/rpmfileutil.h>
#include <rpm/rpmstring.h>
#include <rpm/rpmsq.h>
#include <rpm/rpmkeyring.h>
#include "lib/fprint.h"
#include "lib/misc.h"
#include "lib/rpmchroot.h"
#include "lib/rpmlock.h"
#include "lib/rpmds_internal.h"
#include "lib/rpmfi_internal.h" /* only internal apis */
#include "lib/rpmte_internal.h" /* only internal apis */
#include "lib/rpmts_internal.h"
#include "lib/rpmvs.h"
#include "rpmio/rpmhook.h"
#include "lib/rpmtriggers.h"
#include "lib/rpmplugins.h"
/* XXX FIXME: merge with existing (broken?) tests in system.h */
/* portability fiddles */
#if STATFS_IN_SYS_STATVFS
#include <sys/statvfs.h>
#else
# if STATFS_IN_SYS_VFS
# include <sys/vfs.h>
# else
# if STATFS_IN_SYS_MOUNT
# include <sys/mount.h>
# else
# if STATFS_IN_SYS_STATFS
# include <sys/statfs.h>
# endif
# endif
# endif
#endif
#include "debug.h"
struct diskspaceInfo_s {
char * mntPoint; /*!< File system mount point */
dev_t dev; /*!< File system device number. */
int64_t bneeded; /*!< No. of blocks needed. */
int64_t ineeded; /*!< No. of inodes needed. */
int64_t bsize; /*!< File system block size. */
int64_t bavail; /*!< No. of blocks available. */
int64_t iavail; /*!< No. of inodes available. */
int64_t obneeded; /*!< Bookkeeping to avoid duplicate reports */
int64_t oineeded; /*!< Bookkeeping to avoid duplicate reports */
int64_t bdelta; /*!< Delta for temporary space need on updates */
int64_t idelta; /*!< Delta for temporary inode need on updates */
};
/* Adjust for root only reserved space. On linux e2fs, this is 5%. */
#define adj_fs_blocks(_nb) (((_nb) * 21) / 20)
#define BLOCK_ROUND(size, block) (((size) + (block) - 1) / (block))
static char *getMntPoint(const char *dirName, dev_t dev)
{
char mntPoint[PATH_MAX];
char *resolved_path = realpath(dirName, mntPoint);
char *end = NULL;
struct stat sb;
char *res = NULL;
if (!resolved_path) {
strncpy(mntPoint, dirName, PATH_MAX);
mntPoint[PATH_MAX-1] = '\0';
}
while (end != mntPoint) {
end = strrchr(mntPoint, '/');
if (end == mntPoint) { /* reached "/" */
stat("/", &sb);
if (dev != sb.st_dev) {
res = xstrdup(mntPoint);
} else {
res = xstrdup("/");
}
break;
} else if (end) {
*end = '\0';
} else { /* dirName doesn't start with / - should not happen */
res = xstrdup(dirName);
break;
}
stat(mntPoint, &sb);
if (dev != sb.st_dev) {
*end = '/';
res = xstrdup(mntPoint);
break;
}
}
return res;
}
static int rpmtsInitDSI(const rpmts ts)
{
ts->dsi = _free(ts->dsi);
ts->dsi = xcalloc(1, sizeof(*ts->dsi));
return 0;
}
static rpmDiskSpaceInfo rpmtsCreateDSI(const rpmts ts, dev_t dev,
const char * dirName, int count)
{
rpmDiskSpaceInfo dsi;
struct stat sb;
int rc;
#if STATFS_IN_SYS_STATVFS
struct statvfs sfb;
memset(&sfb, 0, sizeof(sfb));
rc = statvfs(dirName, &sfb);
#else
struct statfs sfb;
memset(&sfb, 0, sizeof(sfb));
# if STAT_STATFS4
/* This platform has the 4-argument version of the statfs call. The last two
* should be the size of struct statfs and 0, respectively. The 0 is the
* filesystem type, and is always 0 when statfs is called on a mounted
* filesystem, as we're doing.
*/
rc = statfs(dirName, &sfb, sizeof(sfb), 0);
# else
rc = statfs(dirName, &sfb);
# endif
#endif
if (rc)
return NULL;
rc = stat(dirName, &sb);
if (rc)
return NULL;
if (sb.st_dev != dev)
return NULL;
ts->dsi = xrealloc(ts->dsi, (count + 2) * sizeof(*ts->dsi));
dsi = ts->dsi + count;
memset(dsi, 0, 2 * sizeof(*dsi));
dsi->dev = sb.st_dev;
dsi->bsize = sfb.f_bsize;
if (!dsi->bsize)
dsi->bsize = 512; /* we need a bsize */
dsi->bneeded = 0;
dsi->ineeded = 0;
#ifdef STATFS_HAS_F_BAVAIL
dsi->bavail = (sfb.f_flag & ST_RDONLY) ? 0 : sfb.f_bavail;
#else
/* FIXME: the statfs struct doesn't have a member to tell how many blocks are
* available for non-superusers. f_blocks - f_bfree is probably too big, but
* it's about all we can do.
*/
dsi->bavail = sfb.f_blocks - sfb.f_bfree;
#endif
/* XXX Avoid FAT and other file systems that have not inodes. */
/* XXX assigning negative value to unsigned type */
dsi->iavail = !(sfb.f_ffree == 0 && sfb.f_files == 0)
? sfb.f_ffree : -1;
/* Find mount point belonging to this device number */
dsi->mntPoint = getMntPoint(dirName, dsi->dev);
/* normalize block size to 4096 bytes if it is too big. */
if (dsi->bsize > 4096) {
uint64_t old_size = dsi->bavail * dsi->bsize;
rpmlog(RPMLOG_DEBUG,
"dubious blocksize % " PRId64 " on %s, normalizing to 4096\n",
dsi->bsize, dsi->mntPoint);
dsi->bsize = 4096; /* Assume 4k block size */
dsi->bavail = old_size / dsi->bsize;
}
rpmlog(RPMLOG_DEBUG,
"0x%08x %8" PRId64 " %12" PRId64 " %12" PRId64" %s\n",
(unsigned) dsi->dev, dsi->bsize,
dsi->bavail, dsi->iavail,
dsi->mntPoint);
return dsi;
}
static rpmDiskSpaceInfo rpmtsGetDSI(const rpmts ts, dev_t dev,
const char *dirName) {
rpmDiskSpaceInfo dsi;
dsi = ts->dsi;
if (dsi) {
while (dsi->bsize && dsi->dev != dev)
dsi++;
if (dsi->bsize == 0) {
/* create new entry */
dsi = rpmtsCreateDSI(ts, dev, dirName, dsi - ts->dsi);
}
}
return dsi;
}
static void rpmtsUpdateDSI(const rpmts ts, dev_t dev, const char *dirName,
rpm_loff_t fileSize, rpm_loff_t prevSize, rpm_loff_t fixupSize,
rpmFileAction action)
{
int64_t bneeded;
rpmDiskSpaceInfo dsi = rpmtsGetDSI(ts, dev, dirName);
if (dsi == NULL)
return;
bneeded = BLOCK_ROUND(fileSize, dsi->bsize);
switch (action) {
case FA_BACKUP:
case FA_SAVE:
case FA_ALTNAME:
dsi->ineeded++;
dsi->bneeded += bneeded;
break;
case FA_CREATE:
dsi->bneeded += bneeded;
dsi->ineeded++;
if (prevSize) {
dsi->bdelta += BLOCK_ROUND(prevSize - 1, dsi->bsize);
dsi->idelta++;
}
if (fixupSize) {
dsi->bdelta += BLOCK_ROUND(fixupSize - 1, dsi->bsize);
dsi->idelta++;
}
break;
case FA_ERASE:
dsi->ineeded--;
dsi->bneeded -= bneeded;
break;
default:
break;
}
/* adjust bookkeeping when requirements shrink */
if (dsi->bneeded < dsi->obneeded) dsi->obneeded = dsi->bneeded;
if (dsi->ineeded < dsi->oineeded) dsi->oineeded = dsi->ineeded;
}
static void rpmtsCheckDSIProblems(const rpmts ts, const rpmte te)
{
rpmDiskSpaceInfo dsi = ts->dsi;
if (dsi == NULL || !dsi->bsize)
return;
for (; dsi->bsize; dsi++) {
if (dsi->bavail >= 0 && adj_fs_blocks(dsi->bneeded) > dsi->bavail) {
if (dsi->bneeded > dsi->obneeded) {
rpmteAddProblem(te, RPMPROB_DISKSPACE, NULL, dsi->mntPoint,
(adj_fs_blocks(dsi->bneeded) - dsi->bavail) * dsi->bsize);
dsi->obneeded = dsi->bneeded;
}
}
if (dsi->iavail >= 0 && adj_fs_blocks(dsi->ineeded) > dsi->iavail) {
if (dsi->ineeded > dsi->oineeded) {
rpmteAddProblem(te, RPMPROB_DISKNODES, NULL, dsi->mntPoint,
(adj_fs_blocks(dsi->ineeded) - dsi->iavail));
dsi->oineeded = dsi->ineeded;
}
}
/* Adjust for temporary -> final disk consumption */
dsi->bneeded -= dsi->bdelta;
dsi->bdelta = 0;
dsi->ineeded -= dsi->idelta;
dsi->idelta = 0;
}
}
static void rpmtsFreeDSI(rpmts ts)
{
rpmDiskSpaceInfo dsi;
if (ts == NULL)
return;
dsi = ts->dsi;
while (dsi && dsi->bsize != 0) {
dsi->mntPoint = _free(dsi->mntPoint);
dsi++;
}
ts->dsi = _free(ts->dsi);
}
/* Calculate total number of files involved in transaction */
static uint64_t countFiles(rpmts ts)
{
uint64_t fc = 0;
rpmtsi pi = rpmtsiInit(ts);
rpmte p;
rpmfiles files;
while ((p = rpmtsiNext(pi, 0)) != NULL) {
files = rpmteFiles(p);
fc += rpmfilesFC(files);
rpmfilesFree(files);
}
rpmtsiFree(pi);
return fc;
}
static int handleRemovalConflict(rpmfiles fi, int fx, rpmfiles ofi, int ofx)
{
int rConflicts = 0; /* Removed files don't conflict, normally */
rpmFileTypes ft = rpmfiWhatis(rpmfilesFMode(fi, fx));
rpmFileTypes oft = rpmfiWhatis(rpmfilesFMode(ofi, ofx));
struct stat sb;
char *fn = NULL;
if (oft == XDIR) {
/* We can't handle directory changing to anything else */
if (ft != XDIR)
rConflicts = 1;
} else if (oft == LINK) {
/* We can't correctly handle directory symlink changing to directory */
if (ft == XDIR) {
fn = rpmfilesFN(fi, fx);
if (stat(fn, &sb) == 0 && S_ISDIR(sb.st_mode))
rConflicts = 1;
}
}
/*
* ...but if the conflicting item is either not on disk, or has
* already been changed to the new type, we should be ok afterall.
*/
if (rConflicts) {
if (fn == NULL)
fn = rpmfilesFN(fi, fx);
if (lstat(fn, &sb) || rpmfiWhatis(sb.st_mode) == ft)
rConflicts = 0;
}
free(fn);
return rConflicts;
}
/*
* Elf files can be "colored", and if enabled in the transaction, the
* color can be used to resolve conflicts between elf-64bit and elf-32bit
* files to the hosts preferred type, by default 64bit. The non-preferred
* type is overwritten or never installed at all and thus the conflict
* magically disappears. This is infamously nasty "rpm magic" and entirely
* unnecessary with careful packaging.
*/
static int handleColorConflict(rpmts ts,
rpmfs fs, rpmfiles fi, int fx,
rpmfs ofs, rpmfiles ofi, int ofx)
{
int rConflicts = 1;
rpm_color_t tscolor = rpmtsColor(ts);
if (tscolor != 0) {
rpm_color_t fcolor = rpmfilesFColor(fi, fx) & tscolor;
rpm_color_t ofcolor = rpmfilesFColor(ofi, ofx) & tscolor;
if (fcolor != 0 && ofcolor != 0 && fcolor != ofcolor) {
rpm_color_t prefcolor = rpmtsPrefColor(ts);
if (fcolor & prefcolor) {
if (ofs && !XFA_SKIPPING(rpmfsGetAction(fs, fx)))
rpmfsSetAction(ofs, ofx, FA_SKIPCOLOR);
rpmfsSetAction(fs, fx, FA_CREATE);
rConflicts = 0;
} else if (ofcolor & prefcolor) {
if (ofs && XFA_SKIPPING(rpmfsGetAction(fs, fx)))
rpmfsSetAction(ofs, ofx, FA_CREATE);
rpmfsSetAction(fs, fx, FA_SKIPCOLOR);
rConflicts = 0;
}
}
}
return rConflicts;
}
/**
* handleInstInstalledFiles.
* @param ts transaction set
* @param p current transaction element
* @param fi file info set
* @param fx file index
* @param otherHeader header containing the matching file
* @param otherFi matching file info set
* @param ofx matching file index
* @param beingRemoved file being removed (installed otherwise)
*/
/* XXX only ts->{probs,rpmdb} modified */
static void handleInstInstalledFile(const rpmts ts, rpmte p, rpmfiles fi, int fx,
Header otherHeader, rpmfiles otherFi, int ofx,
int beingRemoved)
{
rpmfs fs = rpmteGetFileStates(p);
int isCfgFile = ((rpmfilesFFlags(otherFi, ofx) | rpmfilesFFlags(fi, fx)) & RPMFILE_CONFIG);
rpm_loff_t otherFileSize;
int nlink;
const int *links;
if (XFA_SKIPPING(rpmfsGetAction(fs, fx)))
return;
if (rpmfilesCompare(otherFi, ofx, fi, fx)) {
int rConflicts = 1;
char rState = RPMFILE_STATE_REPLACED;
/*
* There are some removal conflicts we can't handle. However
* if the package has a %pretrans scriptlet, it might be able to
* fix the conflict. Let it through on test-transaction to allow
* eg yum to get past it, if the conflict is present on the actual
* transaction we'll abort. Behaving differently on test is nasty,
* but its still better than barfing in middle of large transaction.
*/
if (beingRemoved) {
rConflicts = handleRemovalConflict(fi, fx, otherFi, ofx);
if (rConflicts && rpmteHaveTransScript(p, RPMTAG_PRETRANS)) {
if (rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)
rConflicts = 0;
}
}
if (rConflicts) {
/* If enabled, resolve colored conflicts to preferred type */
rConflicts = handleColorConflict(ts, fs, fi, fx,
NULL, otherFi, ofx);
/* If resolved, we need to adjust in-rpmdb state too */
if (rConflicts == 0 && rpmfsGetAction(fs, fx) == FA_CREATE)
rState = RPMFILE_STATE_WRONGCOLOR;
}
/* Somebody used The Force, lets shut up... */
if (rpmtsFilterFlags(ts) & RPMPROB_FILTER_REPLACEOLDFILES)
rConflicts = 0;
if (rConflicts) {
char *altNEVR = headerGetAsString(otherHeader, RPMTAG_NEVRA);
char *fn = rpmfilesFN(fi, fx);
rpmteAddProblem(p, RPMPROB_FILE_CONFLICT, altNEVR, fn,
headerGetInstance(otherHeader));
free(fn);
free(altNEVR);
}
/* Save file identifier to mark as state REPLACED. */
if ( !(isCfgFile || XFA_SKIPPING(rpmfsGetAction(fs, fx))) ) {
if (!beingRemoved)
rpmfsAddReplaced(rpmteGetFileStates(p), fx, rState,
headerGetInstance(otherHeader), ofx);
}
}
/* Determine config file disposition, skipping missing files (if any). */
if (isCfgFile) {
int skipMissing = ((rpmtsFlags(ts) & RPMTRANS_FLAG_ALLFILES) ? 0 : 1);
rpmFileAction action;
action = rpmfilesDecideFate(otherFi, ofx, fi, fx, skipMissing);
rpmfsSetAction(fs, fx, action);
}
/* Skip already existing files - if 'minimize_writes' is set. */
if ((!isCfgFile) && (rpmfsGetAction(fs, fx) == FA_UNKNOWN) && ts->min_writes) {
if (rpmfileContentsEqual(otherFi, ofx, fi, fx)) {
rpmfsSetAction(fs, fx, FA_TOUCH);
}
}
otherFileSize = rpmfilesFSize(otherFi, ofx);
/* Only account for the last file of a hardlink set */
nlink = rpmfilesFLinks(otherFi, ofx, &links);
if (nlink > 1 && links[nlink - 1] != ofx)
otherFileSize = 0;
/* Add one to make sure the size is not zero */
rpmfilesSetFReplacedSize(fi, fx, otherFileSize + 1);
}
/**
* Update disk space needs on each partition for this package's files.
*/
/* XXX only ts->{probs,di} modified */
static void handleOverlappedFiles(rpmts ts, fingerPrintCache fpc, rpmte p, rpmfiles fi)
{
rpm_loff_t fixupSize = 0;
int i, j;
rpmfs fs = rpmteGetFileStates(p);
rpmfs otherFs;
rpm_count_t fc = rpmfilesFC(fi);
int reportConflicts = !(rpmtsFilterFlags(ts) & RPMPROB_FILTER_REPLACENEWFILES);
fingerPrint * fpList = rpmfilesFps(fi);
for (i = 0; i < fc; i++) {
struct fingerPrint_s * fiFps;
int otherPkgNum, otherFileNum;
rpmfiles otherFi;
rpmte otherTe;
rpmfileAttrs FFlags;
struct rpmffi_s * recs;
int numRecs;
rpm_loff_t fileSize;
int nlink;
const int *links;
if (XFA_SKIPPING(rpmfsGetAction(fs, i)))
continue;
FFlags = rpmfilesFFlags(fi, i);
fixupSize = 0;
/*
* Retrieve all records that apply to this file. Note that the
* file info records were built in the same order as the packages
* will be installed and removed so the records for an overlapped
* files will be sorted in exactly the same order.
*/
fiFps = fpCacheGetByFp(fpc, fpList, i, &recs, &numRecs);
/*
* If this package is being added, look only at other packages
* being added -- removed packages dance to a different tune.
*
* If both this and the other package are being added, overlapped
* files must be identical (or marked as a conflict). The
* disposition of already installed config files leads to
* a small amount of extra complexity.
*
* If this package is being removed, then there are two cases that
* need to be worried about:
* If the other package is being added, then skip any overlapped files
* so that this package removal doesn't nuke the overlapped files
* that were just installed.
* If both this and the other package are being removed, then each
* file removal from preceding packages needs to be skipped so that
* the file removal occurs only on the last occurrence of an overlapped
* file in the transaction set.
*
*/
/*
* Locate this overlapped file in the set of added/removed packages,
* including the package owning it: a package can have self-conflicting
* files when directory symlinks are present. Don't compare a file
* with itself though...
*/
for (j = 0; j < numRecs && !(recs[j].p == p && recs[j].fileno == i); j++)
{};
/* Find what the previous disposition of this file was. */
otherFileNum = -1; /* keep gcc quiet */
otherFi = NULL;
otherTe = NULL;
otherFs = NULL;
for (otherPkgNum = j - 1; otherPkgNum >= 0; otherPkgNum--) {
otherTe = recs[otherPkgNum].p;
otherFileNum = recs[otherPkgNum].fileno;
otherFs = rpmteGetFileStates(otherTe);
/* Added packages need only look at other added packages. */
if (rpmteType(p) == TR_ADDED && rpmteType(otherTe) != TR_ADDED)
continue;
/* XXX Happens iff fingerprint for incomplete package install. */
if (rpmfsGetAction(otherFs, otherFileNum) != FA_UNKNOWN) {
otherFi = rpmteFiles(otherTe);
break;
}
}
switch (rpmteType(p)) {
case TR_ADDED:
if (otherPkgNum < 0) {
/* XXX is this test still necessary? */
rpmFileAction action;
if (rpmfsGetAction(fs, i) != FA_UNKNOWN)
break;
if (rpmfilesConfigConflict(fi, i)) {
/* Here is a non-overlapped pre-existing config file. */
action = (FFlags & RPMFILE_NOREPLACE) ?
FA_ALTNAME : FA_BACKUP;
} else {
action = FA_CREATE;
}
rpmfsSetAction(fs, i, action);
break;
}
assert(otherFi != NULL);
/* Mark added overlapped non-identical files as a conflict. */
if (rpmfilesCompare(otherFi, otherFileNum, fi, i)) {
int rConflicts;
/* If enabled, resolve colored conflicts to preferred type */
rConflicts = handleColorConflict(ts, fs, fi, i,
otherFs, otherFi, otherFileNum);
if (rConflicts && reportConflicts) {
char *fn = rpmfilesFN(fi, i);
rpmteAddProblem(p, RPMPROB_NEW_FILE_CONFLICT,
rpmteNEVRA(otherTe), fn, 0);
free(fn);
}
} else {
/* Skip create on all but the first instance of a shared file */
rpmFileAction oaction = rpmfsGetAction(otherFs, otherFileNum);
if (oaction != FA_UNKNOWN && !XFA_SKIPPING(oaction)) {
rpmfileAttrs oflags;
/* ...but ghosts aren't really created so... */
oflags = rpmfilesFFlags(otherFi, otherFileNum);
if (!(oflags & RPMFILE_GHOST)) {
rpmfsSetAction(fs, i, FA_SKIP);
}
/* if the other file is color skipped then skip this file too */
} else if (oaction == FA_SKIPCOLOR) {
rpmfsSetAction(fs, i, FA_SKIPCOLOR);
}
}
/* Skipped files dont need fixup size or backups, %config or not */
if (XFA_SKIPPING(rpmfsGetAction(fs, i)))
break;
/* Try to get the disk accounting correct even if a conflict. */
/* Add one to make sure the size is not zero */
fixupSize = rpmfilesFSize(otherFi, otherFileNum) + 1;
if (rpmfilesConfigConflict(fi, i)) {
/* Here is an overlapped pre-existing config file. */
rpmFileAction action;
action = (FFlags & RPMFILE_NOREPLACE) ? FA_ALTNAME : FA_SKIP;
rpmfsSetAction(fs, i, action);
} else {
/* If not decided yet, create it */
if (rpmfsGetAction(fs, i) == FA_UNKNOWN)
rpmfsSetAction(fs, i, FA_CREATE);
}
break;
case TR_REMOVED:
if (otherPkgNum >= 0) {
assert(otherFi != NULL);
/* Here is an overlapped added file we don't want to nuke. */
if (rpmfsGetAction(otherFs, otherFileNum) != FA_ERASE) {
/* On updates, don't remove files. */
rpmfsSetAction(fs, i, FA_SKIP);
break;
}
/* Here is an overlapped removed file: skip in previous. */
rpmfsSetAction(otherFs, otherFileNum, FA_SKIP);
}
if (XFA_SKIPPING(rpmfsGetAction(fs, i)))
break;
if (rpmfilesFState(fi, i) != RPMFILE_STATE_NORMAL) {
rpmfsSetAction(fs, i, FA_SKIP);
break;
}
/* Pre-existing modified config files need to be saved. */
if (rpmfilesConfigConflict(fi, i)) {
rpmfsSetAction(fs, i, FA_SAVE);
break;
}
/* Otherwise, we can just erase. */
rpmfsSetAction(fs, i, FA_ERASE);
break;
default:
break;
}
rpmfilesFree(otherFi);
fileSize = rpmfilesFSize(fi, i);
nlink = rpmfilesFLinks(fi, i, &links);
if (nlink > 1 && links[nlink - 1] != i) {
/* Only account for the last file of a hardlink set */
fileSize = 0;
fixupSize = fixupSize ? 1 : 0;
}
/* Update disk space info for a file. */
rpmtsUpdateDSI(ts, fpEntryDev(fpc, fiFps), fpEntryDir(fpc, fiFps),
fileSize, rpmfilesFReplacedSize(fi, i),
fixupSize, rpmfsGetAction(fs, i));
}
}
/**
* Ensure that current package is newer than installed package.
* @param tspool transaction string pool
* @param p current transaction element
* @param h installed header
*/
static void ensureOlder(rpmstrPool tspool, const rpmte p, const Header h)
{
rpmsenseFlags reqFlags = (RPMSENSE_LESS | RPMSENSE_EQUAL);
rpmds req;
req = rpmdsSinglePool(tspool, RPMTAG_REQUIRENAME,
rpmteN(p), rpmteEVR(p), reqFlags);
if (rpmdsMatches(tspool, h, -1, req, 1, _rpmds_nopromote) == 0) {
char * altNEVR = headerGetAsString(h, RPMTAG_NEVRA);
rpmteAddProblem(p, RPMPROB_OLDPACKAGE, altNEVR, NULL,
headerGetInstance(h));
free(altNEVR);
}
rpmdsFree(req);
}
/**
* Check if the curent file in the file iterator is in the
* netshardpath and though should be excluded.
* @param ts transaction set
* @param fi file info set
* @returns 1 if path is net shared path, otherwise 0
*/
static int matchNetsharedpath(const rpmts ts, rpmfi fi)
{
char ** nsp;
const char * dn, * bn;
size_t dnlen, bnlen;
char * s;
bn = rpmfiBN(fi);
bnlen = strlen(bn);
dn = rpmfiDN(fi);
dnlen = strlen(dn);
for (nsp = ts->netsharedPaths; nsp && *nsp; nsp++) {
size_t len;
len = strlen(*nsp);
if (dnlen >= len) {
if (!rstreqn(dn, *nsp, len))
continue;
/* Only directories or complete file paths can be net shared */
if (!(dn[len] == '/' || dn[len] == '\0'))
continue;
} else {
if (len < (dnlen + bnlen))
continue;
if (!rstreqn(dn, *nsp, dnlen))
continue;
/* Insure that only the netsharedpath basename is compared. */
if ((s = strchr((*nsp) + dnlen, '/')) != NULL && s[1] != '\0')
continue;
if (!rstreqn(bn, (*nsp) + dnlen, bnlen))
continue;
len = dnlen + bnlen;
/* Only directories or complete file paths can be net shared */
if (!((*nsp)[len] == '/' || (*nsp)[len] == '\0'))
continue;
}
break;
}
return (nsp != NULL && *nsp != NULL);
}
static void skipEraseFiles(const rpmts ts, rpmfiles files, rpmfs fs)
{
int i;
/*
* Skip net shared paths.
* Net shared paths are not relative to the current root (though
* they do need to take package relocations into account).
*/
if (ts->netsharedPaths) {
rpmfi fi = rpmfilesIter(files, RPMFI_ITER_FWD);
while ((i = rpmfiNext(fi)) >= 0)
{
if (matchNetsharedpath(ts, fi))
rpmfsSetAction(fs, i, FA_SKIPNETSHARED);
}
rpmfiFree(fi);
}
}
/**
* Skip any files that do not match install policies.
* @param ts transaction set
* @param files file info set
* @param fs file states
*/
static void skipInstallFiles(const rpmts ts, rpmfiles files, rpmfs fs)
{
rpm_color_t tscolor = rpmtsColor(ts);
rpm_color_t FColor;
int noConfigs = (rpmtsFlags(ts) & RPMTRANS_FLAG_NOCONFIGS);
int noDocs = (rpmtsFlags(ts) & RPMTRANS_FLAG_NODOCS);
int * drc;
char * dff;
int dc;
int i, j, ix;
rpmfi fi = rpmfilesIter(files, RPMFI_ITER_FWD);
if (!noDocs)
noDocs = rpmExpandNumeric("%{_excludedocs}");
/* Compute directory refcount, skip directory if now empty. */
dc = rpmfiDC(fi);
drc = xcalloc(dc, sizeof(*drc));
dff = xcalloc(dc, sizeof(*dff));
fi = rpmfiInit(fi, 0);
while ((i = rpmfiNext(fi)) >= 0) {
const char *flangs;
ix = rpmfiDX(fi);
drc[ix]++;
/* Don't bother with skipped files */
/* XXX FIXME: --excludepath on %license should not be permitted */
if (XFA_SKIPPING(rpmfsGetAction(fs, i))) {
drc[ix]--; dff[ix] = 1;
continue;
}
/* Ignore colored files not in our rainbow. */
FColor = rpmfiFColor(fi);
if (tscolor && FColor && !(tscolor & FColor)) {
drc[ix]--; dff[ix] = 1;
rpmfsSetAction(fs, i, FA_SKIPCOLOR);
continue;
}
/*
* Skip net shared paths.
* Net shared paths are not relative to the current root (though
* they do need to take package relocations into account).
*/
if (ts->netsharedPaths) {
if (matchNetsharedpath(ts, fi)) {
drc[ix]--; dff[ix] = 1;
rpmfsSetAction(fs, i, FA_SKIPNETSHARED);
continue;
}
}
/*
* In general, excluding license files is not permitted. In case
* of SKIPNETSHARED and SKIPCOLOR the file is expected to be
* there via other means however so that is ok.
*/
if (rpmfiFFlags(fi) & RPMFILE_LICENSE)
continue;
/*
* Skip i18n language specific files.
*/
flangs = (ts->installLangs != NULL) ? rpmfiFLangs(fi) : NULL;
if (flangs != NULL && *flangs != '\0') {
const char *l, *le;
char **lang;
for (lang = ts->installLangs; *lang != NULL; lang++) {
for (l = flangs; *l != '\0'; l = le) {
for (le = l; *le != '\0' && *le != '|'; le++)
{};
if ((le-l) > 0 && rstreqn(*lang, l, (le-l)))
break;
if (*le == '|') le++; /* skip over | */
}
if (*l != '\0')
break;
}
if (*lang == NULL) {
drc[ix]--; dff[ix] = 1;
rpmfsSetAction(fs, i, FA_SKIPNSTATE);
continue;
}
}
/*
* Skip config files if requested.
*/
if (noConfigs && (rpmfiFFlags(fi) & RPMFILE_CONFIG)) {
drc[ix]--; dff[ix] = 1;
rpmfsSetAction(fs, i, FA_SKIPNSTATE);
continue;
}
/*
* Skip documentation if requested.
*/
if (noDocs && (rpmfiFFlags(fi) & RPMFILE_DOC)) {
drc[ix]--; dff[ix] = 1;
rpmfsSetAction(fs, i, FA_SKIPNSTATE);
continue;
}
}
/* Skip (now empty) directories that had skipped files. */
/* Iterate over dirs in reversed order to solve subdirs at first */
for (j = dc - 1; j >= 0; j--) {
const char * dn, * bn;
size_t dnlen, bnlen;
if (drc[j]) continue; /* dir still has files. */
if (!dff[j]) continue; /* dir was not emptied here. */
/* Find parent directory and basename. */
dn = rpmfilesDN(files, j); dnlen = strlen(dn) - 1;
bn = dn + dnlen; bnlen = 0;
while (bn > dn && bn[-1] != '/') {
bnlen++;
dnlen--;
bn--;
}
/* If explicitly included in the package, skip the directory. */
fi = rpmfiInit(fi, 0);
while ((i = rpmfiNext(fi)) >= 0) {
const char * fdn, * fbn;
rpm_mode_t fFMode;
if (XFA_SKIPPING(rpmfsGetAction(fs, i)))
continue;
fFMode = rpmfiFMode(fi);
if (rpmfiWhatis(fFMode) != XDIR)
continue;
fdn = rpmfiDN(fi);
if (strlen(fdn) != dnlen)
continue;
if (!rstreqn(fdn, dn, dnlen))
continue;
fbn = rpmfiBN(fi);
if (strlen(fbn) != bnlen)
continue;
if (!rstreqn(fbn, bn, bnlen))
continue;
rpmlog(RPMLOG_DEBUG, "excluding directory %s\n", dn);
rpmfsSetAction(fs, i, FA_SKIPNSTATE);
ix = rpmfiDX(fi);
/* Decrease count of files for parent directory */
drc[ix]--;
/* Mark directory because something was removed from them */
dff[ix] = 1;
break;
}
}
free(drc);
free(dff);
rpmfiFree(fi);
}
#undef HASHTYPE
#undef HTKEYTYPE
#undef HTDATATYPE
#define HASHTYPE rpmStringSet
#define HTKEYTYPE rpmsid
#include "lib/rpmhash.H"
#include "lib/rpmhash.C"
static unsigned int sidHash(rpmsid sid)
{
return sid;
}
static int sidCmp(rpmsid a, rpmsid b)
{
return (a != b);
}
/* Get a rpmdbMatchIterator containing all files in
* the rpmdb that share the basename with one from
* the transaction.
* @param ts transaction set
* @return rpmdbMatchIterator sorted
by (package, fileNum)
*/
static
rpmdbMatchIterator rpmFindBaseNamesInDB(rpmts ts, uint64_t fileCount)
{
tsMembers tsmem = rpmtsMembers(ts);
rpmstrPool tspool = rpmtsPool(ts);