-
Notifications
You must be signed in to change notification settings - Fork 158
/
Copy pathrepo_rpmdb.c
2623 lines (2433 loc) · 65.3 KB
/
repo_rpmdb.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-2018, SUSE Inc.
*
* This program is licensed under the BSD license, read LICENSE.BSD
* for further information
*/
/*
* repo_rpmdb
*
* convert rpm db to repo
*
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <limits.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <assert.h>
#include <stdint.h>
#include <errno.h>
#ifdef ENABLE_RPMDB
#include <rpm/rpmio.h>
#include <rpm/rpmpgp.h>
#ifndef RPM5
#include <rpm/header.h>
#endif
#include <rpm/rpmdb.h>
#endif
#include "pool.h"
#include "repo.h"
#include "hash.h"
#include "util.h"
#include "queue.h"
#include "chksum.h"
#include "repo_rpmdb.h"
#include "repo_solv.h"
#ifdef ENABLE_COMPLEX_DEPS
#include "pool_parserpmrichdep.h"
#endif
/* 3: added triggers */
/* 4: fixed triggers */
/* 5: fixed checksum copying */
/* 6: add SOLVABLE_PREREQ_IGNOREINST support */
/* 7: fix bug in ignoreinst logic */
#define RPMDB_COOKIE_VERSION 7
#define TAG_NAME 1000
#define TAG_VERSION 1001
#define TAG_RELEASE 1002
#define TAG_EPOCH 1003
#define TAG_SUMMARY 1004
#define TAG_DESCRIPTION 1005
#define TAG_BUILDTIME 1006
#define TAG_BUILDHOST 1007
#define TAG_INSTALLTIME 1008
#define TAG_SIZE 1009
#define TAG_DISTRIBUTION 1010
#define TAG_VENDOR 1011
#define TAG_LICENSE 1014
#define TAG_PACKAGER 1015
#define TAG_GROUP 1016
#define TAG_URL 1020
#define TAG_ARCH 1022
#define TAG_FILESIZES 1028
#define TAG_FILEMODES 1030
#define TAG_FILEMD5S 1035
#define TAG_FILELINKTOS 1036
#define TAG_FILEFLAGS 1037
#define TAG_SOURCERPM 1044
#define TAG_PROVIDENAME 1047
#define TAG_REQUIREFLAGS 1048
#define TAG_REQUIRENAME 1049
#define TAG_REQUIREVERSION 1050
#define TAG_NOSOURCE 1051
#define TAG_NOPATCH 1052
#define TAG_CONFLICTFLAGS 1053
#define TAG_CONFLICTNAME 1054
#define TAG_CONFLICTVERSION 1055
#define TAG_TRIGGERNAME 1066
#define TAG_TRIGGERVERSION 1067
#define TAG_TRIGGERFLAGS 1068
#define TAG_CHANGELOGTIME 1080
#define TAG_CHANGELOGNAME 1081
#define TAG_CHANGELOGTEXT 1082
#define TAG_OBSOLETENAME 1090
#define TAG_FILEDEVICES 1095
#define TAG_FILEINODES 1096
#define TAG_SOURCEPACKAGE 1106
#define TAG_PROVIDEFLAGS 1112
#define TAG_PROVIDEVERSION 1113
#define TAG_OBSOLETEFLAGS 1114
#define TAG_OBSOLETEVERSION 1115
#define TAG_DIRINDEXES 1116
#define TAG_BASENAMES 1117
#define TAG_DIRNAMES 1118
#define TAG_PAYLOADFORMAT 1124
#define TAG_PATCHESNAME 1133
#define TAG_FILECOLORS 1140
#define TAG_OLDSUGGESTSNAME 1156
#define TAG_OLDSUGGESTSVERSION 1157
#define TAG_OLDSUGGESTSFLAGS 1158
#define TAG_OLDENHANCESNAME 1159
#define TAG_OLDENHANCESVERSION 1160
#define TAG_OLDENHANCESFLAGS 1161
/* rpm5 tags */
#define TAG_DISTEPOCH 1218
/* rpm4 tags */
#define TAG_LONGFILESIZES 5008
#define TAG_LONGSIZE 5009
#define TAG_ORDERNAME 5035
#define TAG_ORDERVERSION 5036
#define TAG_ORDERFLAGS 5037
#define TAG_RECOMMENDNAME 5046
#define TAG_RECOMMENDVERSION 5047
#define TAG_RECOMMENDFLAGS 5048
#define TAG_SUGGESTNAME 5049
#define TAG_SUGGESTVERSION 5050
#define TAG_SUGGESTFLAGS 5051
#define TAG_SUPPLEMENTNAME 5052
#define TAG_SUPPLEMENTVERSION 5053
#define TAG_SUPPLEMENTFLAGS 5054
#define TAG_ENHANCENAME 5055
#define TAG_ENHANCEVERSION 5056
#define TAG_ENHANCEFLAGS 5057
/* signature tags */
#define TAG_SIGBASE 256
#define TAG_SIGMD5 (TAG_SIGBASE + 5)
#define TAG_SHA1HEADER (TAG_SIGBASE + 13)
#define TAG_SHA256HEADER (TAG_SIGBASE + 17)
#define SIGTAG_SIZE 1000
#define SIGTAG_PGP 1002 /* RSA signature */
#define SIGTAG_MD5 1004 /* header+payload md5 checksum */
#define SIGTAG_GPG 1005 /* DSA signature */
#define DEP_LESS (1 << 1)
#define DEP_GREATER (1 << 2)
#define DEP_EQUAL (1 << 3)
#define DEP_STRONG (1 << 27)
#define DEP_PRE_IN ((1 << 6) | (1 << 9) | (1 << 10))
#define DEP_PRE_UN ((1 << 6) | (1 << 11) | (1 << 12))
#define FILEFLAG_GHOST (1 << 6)
/* some limits to guard against corrupt rpms */
/* dsize limits taken from rpm's lib/header.c */
#define MAX_SIG_CNT 0x10000
#define MAX_SIG_DSIZE 0x4000000
#define MAX_HDR_CNT 0x10000
#define MAX_HDR_DSIZE 0x10000000
#ifndef ENABLE_RPMPKG_LIBRPM
typedef struct rpmhead {
int cnt;
unsigned int dcnt;
unsigned char *dp;
unsigned char data[1];
} RpmHead;
static inline void
headinit(RpmHead *h, unsigned int cnt, unsigned int dcnt)
{
h->cnt = (int)cnt;
h->dcnt = dcnt;
h->dp = h->data + 16 * cnt;
h->dp[dcnt] = 0;
}
static inline unsigned char *
headfindtag(RpmHead *h, int tag)
{
unsigned int i;
unsigned char *d, taga[4];
d = h->dp - 16;
taga[0] = tag >> 24;
taga[1] = tag >> 16;
taga[2] = tag >> 8;
taga[3] = tag;
for (i = 0; i < h->cnt; i++, d -= 16)
if (d[3] == taga[3] && d[2] == taga[2] && d[1] == taga[1] && d[0] == taga[0])
return d;
return 0;
}
static int
headexists(RpmHead *h, int tag)
{
return headfindtag(h, tag) ? 1 : 0;
}
static uint32_t *
headint32array(RpmHead *h, int tag, int *cnt)
{
uint32_t *r;
unsigned int i, o;
unsigned char *d = headfindtag(h, tag);
if (!d || d[4] != 0 || d[5] != 0 || d[6] != 0 || d[7] != 4)
return 0;
o = d[8] << 24 | d[9] << 16 | d[10] << 8 | d[11];
i = d[12] << 24 | d[13] << 16 | d[14] << 8 | d[15];
if (o > h->dcnt || i > h->dcnt || o + 4 * i > h->dcnt)
return 0;
d = h->dp + o;
r = solv_calloc(i ? i : 1, sizeof(uint32_t));
if (cnt)
*cnt = i;
for (o = 0; o < i; o++, d += 4)
r[o] = d[0] << 24 | d[1] << 16 | d[2] << 8 | d[3];
return r;
}
/* returns the first entry of an integer array */
static uint32_t
headint32(RpmHead *h, int tag)
{
unsigned int i, o;
unsigned char *d = headfindtag(h, tag);
if (!d || d[4] != 0 || d[5] != 0 || d[6] != 0 || d[7] != 4)
return 0;
o = d[8] << 24 | d[9] << 16 | d[10] << 8 | d[11];
i = d[12] << 24 | d[13] << 16 | d[14] << 8 | d[15];
if (i == 0 || o > h->dcnt || i > h->dcnt || o + 4 * i > h->dcnt)
return 0;
d = h->dp + o;
return d[0] << 24 | d[1] << 16 | d[2] << 8 | d[3];
}
static uint64_t *
headint64array(RpmHead *h, int tag, int *cnt)
{
uint64_t *r;
unsigned int i, o;
unsigned char *d = headfindtag(h, tag);
if (!d || d[4] != 0 || d[5] != 0 || d[6] != 0 || d[7] != 5)
return 0;
o = d[8] << 24 | d[9] << 16 | d[10] << 8 | d[11];
i = d[12] << 24 | d[13] << 16 | d[14] << 8 | d[15];
if (o > h->dcnt || i > h->dcnt || o + 8 * i > h->dcnt)
return 0;
d = h->dp + o;
r = solv_calloc(i ? i : 1, sizeof(uint64_t));
if (cnt)
*cnt = i;
for (o = 0; o < i; o++, d += 8)
{
uint32_t x = d[0] << 24 | d[1] << 16 | d[2] << 8 | d[3];
r[o] = (uint64_t)x << 32 | (uint32_t)(d[4] << 24 | d[5] << 16 | d[6] << 8 | d[7]);
}
return r;
}
/* returns the first entry of an 64bit integer array */
static uint64_t
headint64(RpmHead *h, int tag)
{
uint32_t x;
unsigned int i, o;
unsigned char *d = headfindtag(h, tag);
if (!d || d[4] != 0 || d[5] != 0 || d[6] != 0 || d[7] != 5)
return 0;
o = d[8] << 24 | d[9] << 16 | d[10] << 8 | d[11];
i = d[12] << 24 | d[13] << 16 | d[14] << 8 | d[15];
if (i == 0 || o > h->dcnt || i > h->dcnt || o + 8 * i > h->dcnt)
return 0;
d = h->dp + o;
x = d[0] << 24 | d[1] << 16 | d[2] << 8 | d[3];
return (uint64_t)x << 32 | (uint32_t)(d[4] << 24 | d[5] << 16 | d[6] << 8 | d[7]);
}
static uint16_t *
headint16array(RpmHead *h, int tag, int *cnt)
{
uint16_t *r;
unsigned int i, o;
unsigned char *d = headfindtag(h, tag);
if (!d || d[4] != 0 || d[5] != 0 || d[6] != 0 || d[7] != 3)
return 0;
o = d[8] << 24 | d[9] << 16 | d[10] << 8 | d[11];
i = d[12] << 24 | d[13] << 16 | d[14] << 8 | d[15];
if (o > h->dcnt || i > h->dcnt || o + 2 * i > h->dcnt)
return 0;
d = h->dp + o;
r = solv_calloc(i ? i : 1, sizeof(uint16_t));
if (cnt)
*cnt = i;
for (o = 0; o < i; o++, d += 2)
r[o] = d[0] << 8 | d[1];
return r;
}
static char *
headstring(RpmHead *h, int tag)
{
unsigned int o;
unsigned char *d = headfindtag(h, tag);
/* 6: STRING, 9: I18NSTRING */
if (!d || d[4] != 0 || d[5] != 0 || d[6] != 0 || (d[7] != 6 && d[7] != 9))
return 0;
o = d[8] << 24 | d[9] << 16 | d[10] << 8 | d[11];
if (o >= h->dcnt)
return 0;
return (char *)h->dp + o;
}
static char **
headstringarray(RpmHead *h, int tag, int *cnt)
{
unsigned int i, o;
unsigned char *d = headfindtag(h, tag);
char **r;
if (!d || d[4] != 0 || d[5] != 0 || d[6] != 0 || d[7] != 8)
return 0;
o = d[8] << 24 | d[9] << 16 | d[10] << 8 | d[11];
i = d[12] << 24 | d[13] << 16 | d[14] << 8 | d[15];
if (o > h->dcnt || i > h->dcnt)
return 0;
r = solv_calloc(i ? i : 1, sizeof(char *));
if (cnt)
*cnt = i;
d = h->dp + o;
for (o = 0; o < i; o++)
{
r[o] = (char *)d;
if (o + 1 < i)
d += strlen((char *)d) + 1;
if (d >= h->dp + h->dcnt)
{
solv_free(r);
return 0;
}
}
return r;
}
static unsigned char *
headbinary(RpmHead *h, int tag, unsigned int *sizep)
{
unsigned int i, o;
unsigned char *d = headfindtag(h, tag);
if (!d || d[4] != 0 || d[5] != 0 || d[6] != 0 || d[7] != 7)
return 0;
o = d[8] << 24 | d[9] << 16 | d[10] << 8 | d[11];
i = d[12] << 24 | d[13] << 16 | d[14] << 8 | d[15];
if (o > h->dcnt || i > h->dcnt || o + i > h->dcnt)
return 0;
if (sizep)
*sizep = i;
return h->dp + o;
}
static int
headissourceheuristic(RpmHead *h)
{
unsigned int i, o;
unsigned char *d = headfindtag(h, TAG_DIRNAMES);
if (!d || d[4] != 0 || d[5] != 0 || d[6] != 0 || d[7] != 8)
return 0;
o = d[8] << 24 | d[9] << 16 | d[10] << 8 | d[11];
i = d[12] << 24 | d[13] << 16 | d[14] << 8 | d[15];
return i == 1 && o < h->dcnt && !h->dp[o] ? 1 : 0;
}
static inline void
headfree(RpmHead *h)
{
solv_free(h);
}
#else
typedef struct headerToken_s RpmHead;
static int
headexists(RpmHead *h, int tag)
{
return headerIsEntry(h, tag);
}
static void *headget(RpmHead *h, int tag, int *cnt, int alloc)
{
struct rpmtd_s td;
if (!headerGet(h, tag, &td, alloc ? HEADERGET_ALLOC : HEADERGET_MINMEM))
return 0;
if (cnt)
*cnt = td.count;
return td.data;
}
static uint32_t *
headint32array(RpmHead *h, int tag, int *cnt)
{
return headget(h, tag, cnt, 1);
}
static uint32_t
headint32(RpmHead *h, int tag)
{
uint32_t *arr = headget(h, tag, 0, 0);
return arr ? arr[0] : 0;
}
static uint64_t *
headint64array(RpmHead *h, int tag, int *cnt)
{
return headget(h, tag, cnt, 1);
}
/* returns the first entry of an 64bit integer array */
static uint64_t
headint64(RpmHead *h, int tag)
{
uint64_t *arr = headget(h, tag, 0, 0);
return arr ? arr[0] : 0;
}
static uint16_t *
headint16array(RpmHead *h, int tag, int *cnt)
{
return headget(h, tag, cnt, 1);
}
static char *
headstring(RpmHead *h, int tag)
{
return headget(h, tag, 0, 0);
}
static char **
headstringarray(RpmHead *h, int tag, int *cnt)
{
return headget(h, tag, cnt, 1);
}
static unsigned char *
headbinary(RpmHead *h, int tag, unsigned int *sizep)
{
unsigned char *b = headget(h, tag, (int *)sizep, 0);
if (b && sizep && (tag == TAG_SIGMD5 || tag == SIGTAG_MD5) && *sizep > 16) {
/* due to a bug in rpm the count may be bigger if HEADERIMPORT_FAST is used */
*sizep = 16;
}
return b;
}
static int
headissourceheuristic(RpmHead *h)
{
struct rpmtd_s td;
int issource;
if (!headerGet(h, TAG_DIRNAMES, &td, HEADERGET_MINMEM))
return 0;
issource = td.count == 1 && td.data && ((char **)td.data)[0] && !((char **)td.data)[0][0];
rpmtdFreeData(&td);
return issource;
}
static inline void
headfree(RpmHead *h)
{
headerFree(h);
}
#endif
static char *headtoevr(RpmHead *h)
{
unsigned int epoch;
char *version, *v;
char *release;
char *evr;
char *distepoch;
version = headstring(h, TAG_VERSION);
release = headstring(h, TAG_RELEASE);
epoch = headint32(h, TAG_EPOCH);
if (!version || !release)
return 0;
for (v = version; *v >= '0' && *v <= '9'; v++)
;
if (epoch || (v != version && *v == ':'))
{
char epochbuf[11]; /* 32bit decimal will fit in */
sprintf(epochbuf, "%u", epoch);
evr = solv_malloc(strlen(epochbuf) + 1 + strlen(version) + 1 + strlen(release) + 1);
sprintf(evr, "%s:%s-%s", epochbuf, version, release);
}
else
{
evr = solv_malloc(strlen(version) + 1 + strlen(release) + 1);
sprintf(evr, "%s-%s", version, release);
}
distepoch = headstring(h, TAG_DISTEPOCH);
if (distepoch && *distepoch)
{
int l = strlen(evr);
evr = solv_realloc(evr, l + strlen(distepoch) + 2);
evr[l++] = ':';
strcpy(evr + l, distepoch);
}
return evr;
}
static const char *headtoarch_nodup(RpmHead *h)
{
const char *arch;
if (!headstring(h, TAG_SOURCERPM) && (headexists(h, TAG_SOURCEPACKAGE) || headissourceheuristic(h)))
return headexists(h, TAG_NOSOURCE) || headexists(h, TAG_NOPATCH) ? "nosrc" : "src";
arch = headstring(h, TAG_ARCH);
return arch ? arch : "noarch";
}
static char *headtocanon(RpmHead *h)
{
const char *name, *arch;
char *evr, *r;
name = headstring(h, TAG_NAME);
if (!name)
name = "";
arch = headtoarch_nodup(h);
evr = headtoevr(h);
r = solv_malloc(strlen(name) + 1 + strlen(evr ? evr : "") + 1 + strlen(arch) + 1);
sprintf(r, "%s-%s.%s", name, evr ? evr : "", arch);
solv_free(evr);
return r;
}
static void
setutf8string(Repodata *repodata, Id handle, Id tag, const char *str)
{
if (str[solv_validutf8(str)])
{
char *ustr = solv_latin1toutf8(str); /* not utf8, assume latin1 */
repodata_set_str(repodata, handle, tag, ustr);
solv_free(ustr);
}
else
repodata_set_str(repodata, handle, tag, str);
}
static int
ignq_sortcmp(const void *va, const void *vb, void *dp)
{
int r = *(Id *)va - *(Id *)vb;
if (!r)
r = ((Id *)va)[1] - ((Id *)vb)[1];
return r;
}
/*
* strong: 0: ignore strongness
* 1: filter to strong
* 2: filter to weak
*/
static unsigned int
makedeps(Pool *pool, Repo *repo, RpmHead *rpmhead, int tagn, int tagv, int tagf, int flags, Queue *ignq)
{
char **n, **v;
uint32_t *f;
int i, cc, nc, vc, fc;
int haspre, premask, has_ign;
unsigned int olddeps;
Id *ida;
int strong = 0;
n = headstringarray(rpmhead, tagn, &nc);
if (!n)
{
switch (tagn)
{
case TAG_SUGGESTNAME:
tagn = TAG_OLDSUGGESTSNAME;
tagv = TAG_OLDSUGGESTSVERSION;
tagf = TAG_OLDSUGGESTSFLAGS;
strong = -1;
break;
case TAG_ENHANCENAME:
tagn = TAG_OLDENHANCESNAME;
tagv = TAG_OLDENHANCESVERSION;
tagf = TAG_OLDENHANCESFLAGS;
strong = -1;
break;
case TAG_RECOMMENDNAME:
tagn = TAG_OLDSUGGESTSNAME;
tagv = TAG_OLDSUGGESTSVERSION;
tagf = TAG_OLDSUGGESTSFLAGS;
strong = 1;
break;
case TAG_SUPPLEMENTNAME:
tagn = TAG_OLDENHANCESNAME;
tagv = TAG_OLDENHANCESVERSION;
tagf = TAG_OLDENHANCESFLAGS;
strong = 1;
break;
default:
return 0;
}
n = headstringarray(rpmhead, tagn, &nc);
}
if (!n || !nc)
return 0;
vc = fc = 0;
v = headstringarray(rpmhead, tagv, &vc);
f = headint32array(rpmhead, tagf, &fc);
if (!v || !f || nc != vc || nc != fc)
{
char *pkgname = headtocanon(rpmhead);
pool_error(pool, 0, "bad dependency entries for %s: %d %d %d", pkgname ? pkgname : "<NULL>", nc, vc, fc);
solv_free(pkgname);
solv_free(n);
solv_free(v);
solv_free(f);
return 0;
}
cc = nc;
haspre = 0; /* add no prereq marker */
premask = tagn == TAG_REQUIRENAME ? DEP_PRE_IN | DEP_PRE_UN : 0;
if ((flags & RPM_ADD_NO_RPMLIBREQS) || strong)
{
/* we do filtering */
cc = 0;
for (i = 0; i < nc; i++)
{
if (strong && (f[i] & DEP_STRONG) != (strong < 0 ? 0 : DEP_STRONG))
continue;
if ((flags & RPM_ADD_NO_RPMLIBREQS) != 0)
if (!strncmp(n[i], "rpmlib(", 7))
continue;
if ((f[i] & premask) != 0)
haspre = 1;
cc++;
}
}
else if (premask)
{
/* no filtering, just look for the first prereq */
for (i = 0; i < nc; i++)
if ((f[i] & premask) != 0)
{
haspre = 1;
break;
}
}
if (cc == 0)
{
solv_free(n);
solv_free(v);
solv_free(f);
return 0;
}
cc += haspre; /* add slot for the prereq marker */
if (repo)
{
olddeps = repo_reserve_ids(repo, 0, cc);
ida = repo->idarraydata + olddeps;
}
else
{
olddeps = 0;
queue_prealloc(ignq, cc);
ida = ignq->elements + ignq->count;
}
has_ign = 0;
for (i = 0; ; i++)
{
Id id;
if (i == nc)
{
if (haspre != 1)
break;
haspre = 2; /* pass two: prereqs */
i = 0;
*ida++ = SOLVABLE_PREREQMARKER;
}
if (strong && (f[i] & DEP_STRONG) != (strong < 0 ? 0 : DEP_STRONG))
continue;
if (haspre)
{
if (haspre == 1 && (f[i] & premask) != 0)
continue;
if (haspre == 2 && (f[i] & premask) == 0)
continue;
}
if ((flags & RPM_ADD_NO_RPMLIBREQS) != 0)
if (!strncmp(n[i], "rpmlib(", 7))
continue;
#ifdef ENABLE_COMPLEX_DEPS
if ((f[i] & (DEP_LESS|DEP_EQUAL|DEP_GREATER)) == 0 && n[i][0] == '(')
{
id = pool_parserpmrichdep(pool, n[i]);
if (!id)
{
cc--;
continue;
}
}
else
#endif
{
id = pool_str2id(pool, n[i], 1);
if (f[i] & (DEP_LESS|DEP_GREATER|DEP_EQUAL))
{
Id evr;
int fl = 0;
if ((f[i] & DEP_LESS) != 0)
fl |= REL_LT;
if ((f[i] & DEP_EQUAL) != 0)
fl |= REL_EQ;
if ((f[i] & DEP_GREATER) != 0)
fl |= REL_GT;
if (v[i][0] == '0' && v[i][1] == ':' && v[i][2])
evr = pool_str2id(pool, v[i] + 2, 1);
else
evr = pool_str2id(pool, v[i], 1);
id = pool_rel2id(pool, id, evr, fl, 1);
}
}
*ida++ = id;
if (haspre == 2 && ignq && repo)
{
int is_ign = (f[i] & DEP_PRE_IN) != 0 && (f[i] & DEP_PRE_UN) == 0 ? 1 : 0;
has_ign |= is_ign;
queue_push2(ignq, id, is_ign);
}
}
if (repo)
{
*ida++ = 0;
repo->idarraysize += cc + 1;
}
else
{
ignq->count += cc;
ignq->left -= cc;
}
solv_free(n);
solv_free(v);
solv_free(f);
if (ignq && ignq->count && repo)
{
int j = 0;
if (has_ign && ignq->count == 2)
j = 1;
else if (has_ign)
{
Id id, lastid = 0;
solv_sort(ignq->elements, ignq->count / 2, sizeof(Id) * 2, ignq_sortcmp, 0);
for (i = j = 0; i < ignq->count; i += 2)
{
id = ignq->elements[i];
if (id != lastid && ignq->elements[i + 1] > 0)
ignq->elements[j++] = id;
lastid = id;
}
}
queue_truncate(ignq, j);
}
return olddeps;
}
static Id
repodata_str2dir_rooted(Repodata *data, char *str, int create)
{
char buf[256], *bp;
int l = strlen(str);
Id id;
if (l + 2 <= sizeof(buf))
bp = buf;
else
bp = solv_malloc(l + 2);
bp[0] = '/';
strcpy(bp + 1, str);
id = repodata_str2dir(data, bp, create);
if (bp != buf)
solv_free(bp);
return id;
}
static void
adddudata(Repodata *data, Id handle, RpmHead *rpmhead, char **dn, uint32_t *di, int fc, int dc)
{
Id did;
int i, fszc;
unsigned int *fkb, *fn;
uint64_t *fsz64;
uint32_t *fsz, *fino;
uint16_t *fm;
unsigned int inotest[256], inotestok;
if (!fc)
return;
if ((fsz64 = headint64array(rpmhead, TAG_LONGFILESIZES, &fszc)) != 0)
{
/* convert to kbyte */
fsz = solv_malloc2(fszc, sizeof(*fsz));
for (i = 0; i < fszc; i++)
fsz[i] = fsz64[i] ? fsz64[i] / 1024 + 1 : 0;
solv_free(fsz64);
}
else if ((fsz = headint32array(rpmhead, TAG_FILESIZES, &fszc)) != 0)
{
/* convert to kbyte */
for (i = 0; i < fszc; i++)
if (fsz[i])
fsz[i] = fsz[i] / 1024 + 1;
}
else
return;
if (fc != fszc)
{
solv_free(fsz);
return;
}
/* stupid rpm records sizes of directories, so we have to check the mode */
fm = headint16array(rpmhead, TAG_FILEMODES, &fszc);
if (!fm || fc != fszc)
{
solv_free(fsz);
solv_free(fm);
return;
}
fino = headint32array(rpmhead, TAG_FILEINODES, &fszc);
if (!fino || fc != fszc)
{
solv_free(fsz);
solv_free(fm);
solv_free(fino);
return;
}
/* kill hardlinked entries */
inotestok = 0;
if (fc < sizeof(inotest))
{
/* quick test just hashing the inode numbers */
memset(inotest, 0, sizeof(inotest));
for (i = 0; i < fc; i++)
{
int off, bit;
if (fsz[i] == 0 || !S_ISREG(fm[i]))
continue; /* does not matter */
off = (fino[i] >> 5) & (sizeof(inotest)/sizeof(*inotest) - 1);
bit = 1 << (fino[i] & 31);
if ((inotest[off] & bit) != 0)
break;
inotest[off] |= bit;
}
if (i == fc)
inotestok = 1; /* no conflict found */
}
if (!inotestok)
{
/* hardlinked files are possible, check ino/dev pairs */
unsigned int *fdev = headint32array(rpmhead, TAG_FILEDEVICES, &fszc);
unsigned int *fx, j;
unsigned int mask, hash, hh;
if (!fdev || fc != fszc)
{
solv_free(fsz);
solv_free(fm);
solv_free(fdev);
solv_free(fino);
return;
}
mask = fc;
while ((mask & (mask - 1)) != 0)
mask = mask & (mask - 1);
mask <<= 2;
if (mask > sizeof(inotest)/sizeof(*inotest))
fx = solv_calloc(mask, sizeof(unsigned int));
else
{
fx = inotest;
memset(fx, 0, mask * sizeof(unsigned int));
}
mask--;
for (i = 0; i < fc; i++)
{
if (fsz[i] == 0 || !S_ISREG(fm[i]))
continue;
hash = (fino[i] + fdev[i] * 31) & mask;
hh = 7;
while ((j = fx[hash]) != 0)
{
if (fino[j - 1] == fino[i] && fdev[j - 1] == fdev[i])
{
fsz[i] = 0; /* kill entry */
break;
}
hash = (hash + hh++) & mask;
}
if (!j)
fx[hash] = i + 1;
}
if (fx != inotest)
solv_free(fx);
solv_free(fdev);
}
solv_free(fino);
/* sum up inode count and kbytes for each directory */
fn = solv_calloc(dc, sizeof(unsigned int));
fkb = solv_calloc(dc, sizeof(unsigned int));
for (i = 0; i < fc; i++)
{
if (di[i] >= dc)
continue; /* corrupt entry */
fn[di[i]]++;
if (fsz[i] == 0 || !S_ISREG(fm[i]))
continue;
fkb[di[i]] += fsz[i];
}
solv_free(fsz);
solv_free(fm);
/* commit */
for (i = 0; i < dc; i++)
{
if (!fn[i])
continue;
if (dn[i][0] != '/')
{
Solvable *s = data->repo->pool->solvables + handle;
if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
did = repodata_str2dir(data, "/usr/src", 1);
else
did = repodata_str2dir_rooted(data, dn[i], 1);
}
else
did = repodata_str2dir(data, dn[i], 1);
repodata_add_dirnumnum(data, handle, SOLVABLE_DISKUSAGE, did, fkb[i], fn[i]);
}
solv_free(fn);
solv_free(fkb);
}
static int
is_filtered(const char *dir)
{
if (!dir)
return 1;
/* the dirs always have a trailing / in rpm */
if (strstr(dir, "bin/"))
return 0;
if (!strncmp(dir, "/etc/", 5))
return 0;
if (!strcmp(dir, "/usr/lib/"))
return 2;
return 1;
}
static void
addfilelist(Repodata *data, Id handle, RpmHead *rpmhead, int flags)
{
char **bn;
char **dn;
uint32_t *di;
int bnc, dnc, dic;
int i;
Id did;
uint32_t lastdii = -1;
int lastfiltered = 0;
if (!data)
return;
bn = headstringarray(rpmhead, TAG_BASENAMES, &bnc);
if (!bn)
return;
dn = headstringarray(rpmhead, TAG_DIRNAMES, &dnc);
if (!dn)
{
solv_free(bn);