2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
11 * convert rpm db to repo
15 #include <sys/types.h>
30 #include <rpm/rpmio.h>
31 #include <rpm/rpmpgp.h>
39 #include "repo_rpmdb.h"
41 #define RPMDB_COOKIE_VERSION 2
44 #define TAG_VERSION 1001
45 #define TAG_RELEASE 1002
46 #define TAG_EPOCH 1003
47 #define TAG_SUMMARY 1004
48 #define TAG_DESCRIPTION 1005
49 #define TAG_BUILDTIME 1006
50 #define TAG_BUILDHOST 1007
51 #define TAG_INSTALLTIME 1008
53 #define TAG_DISTRIBUTION 1010
54 #define TAG_VENDOR 1011
55 #define TAG_LICENSE 1014
56 #define TAG_PACKAGER 1015
57 #define TAG_GROUP 1016
60 #define TAG_FILESIZES 1028
61 #define TAG_FILEMODES 1030
62 #define TAG_FILEMD5S 1035
63 #define TAG_FILELINKTOS 1036
64 #define TAG_SOURCERPM 1044
65 #define TAG_PROVIDENAME 1047
66 #define TAG_REQUIREFLAGS 1048
67 #define TAG_REQUIRENAME 1049
68 #define TAG_REQUIREVERSION 1050
69 #define TAG_NOSOURCE 1051
70 #define TAG_NOPATCH 1052
71 #define TAG_CONFLICTFLAGS 1053
72 #define TAG_CONFLICTNAME 1054
73 #define TAG_CONFLICTVERSION 1055
74 #define TAG_OBSOLETENAME 1090
75 #define TAG_FILEDEVICES 1095
76 #define TAG_FILEINODES 1096
77 #define TAG_PROVIDEFLAGS 1112
78 #define TAG_PROVIDEVERSION 1113
79 #define TAG_OBSOLETEFLAGS 1114
80 #define TAG_OBSOLETEVERSION 1115
81 #define TAG_DIRINDEXES 1116
82 #define TAG_BASENAMES 1117
83 #define TAG_DIRNAMES 1118
84 #define TAG_PAYLOADFORMAT 1124
85 #define TAG_PATCHESNAME 1133
86 #define TAG_FILECOLORS 1140
87 #define TAG_SUGGESTSNAME 1156
88 #define TAG_SUGGESTSVERSION 1157
89 #define TAG_SUGGESTSFLAGS 1158
90 #define TAG_ENHANCESNAME 1159
91 #define TAG_ENHANCESVERSION 1160
92 #define TAG_ENHANCESFLAGS 1161
94 #define SIGTAG_SIZE 1000
95 #define SIGTAG_PGP 1002 /* RSA signature */
96 #define SIGTAG_MD5 1004 /* header+payload md5 checksum */
97 #define SIGTAG_GPG 1005 /* DSA signature */
99 #define DEP_LESS (1 << 1)
100 #define DEP_GREATER (1 << 2)
101 #define DEP_EQUAL (1 << 3)
102 #define DEP_STRONG (1 << 27)
103 #define DEP_PRE ((1 << 6) | (1 << 9) | (1 << 10) | (1 << 11) | (1 << 12))
111 typedef struct rpmhead {
115 unsigned char data[1];
119 static inline unsigned char *
120 headfindtag(RpmHead *h, int tag)
123 unsigned char *d, taga[4];
129 for (i = 0; i < h->cnt; i++, d -= 16)
130 if (d[3] == taga[3] && d[2] == taga[2] && d[1] == taga[1] && d[0] == taga[0])
136 headexists(RpmHead *h, int tag)
138 return headfindtag(h, tag) ? 1 : 0;
141 static unsigned int *
142 headint32array(RpmHead *h, int tag, int *cnt)
144 unsigned int i, o, *r;
145 unsigned char *d = headfindtag(h, tag);
147 if (!d || d[4] != 0 || d[5] != 0 || d[6] != 0 || d[7] != 4)
149 o = d[8] << 24 | d[9] << 16 | d[10] << 8 | d[11];
150 i = d[12] << 24 | d[13] << 16 | d[14] << 8 | d[15];
151 if (o + 4 * i > h->dcnt)
154 r = sat_calloc(i ? i : 1, sizeof(unsigned int));
157 for (o = 0; o < i; o++, d += 4)
158 r[o] = d[0] << 24 | d[1] << 16 | d[2] << 8 | d[3];
162 /* returns the first entry of an integer array */
164 headint32(RpmHead *h, int tag)
167 unsigned char *d = headfindtag(h, tag);
169 if (!d || d[4] != 0 || d[5] != 0 || d[6] != 0 || d[7] != 4)
171 o = d[8] << 24 | d[9] << 16 | d[10] << 8 | d[11];
172 i = d[12] << 24 | d[13] << 16 | d[14] << 8 | d[15];
173 if (i == 0 || o + 4 * i > h->dcnt)
176 return d[0] << 24 | d[1] << 16 | d[2] << 8 | d[3];
179 static unsigned int *
180 headint16array(RpmHead *h, int tag, int *cnt)
182 unsigned int i, o, *r;
183 unsigned char *d = headfindtag(h, tag);
185 if (!d || d[4] != 0 || d[5] != 0 || d[6] != 0 || d[7] != 3)
187 o = d[8] << 24 | d[9] << 16 | d[10] << 8 | d[11];
188 i = d[12] << 24 | d[13] << 16 | d[14] << 8 | d[15];
189 if (o + 4 * i > h->dcnt)
192 r = sat_calloc(i ? i : 1, sizeof(unsigned int));
195 for (o = 0; o < i; o++, d += 2)
196 r[o] = d[0] << 8 | d[1];
201 headstring(RpmHead *h, int tag)
204 unsigned char *d = headfindtag(h, tag);
205 /* 6: STRING, 9: I18NSTRING */
206 if (!d || d[4] != 0 || d[5] != 0 || d[6] != 0 || (d[7] != 6 && d[7] != 9))
208 o = d[8] << 24 | d[9] << 16 | d[10] << 8 | d[11];
211 return (char *)h->dp + o;
215 headstringarray(RpmHead *h, int tag, int *cnt)
218 unsigned char *d = headfindtag(h, tag);
221 if (!d || d[4] != 0 || d[5] != 0 || d[6] != 0 || d[7] != 8)
223 o = d[8] << 24 | d[9] << 16 | d[10] << 8 | d[11];
224 i = d[12] << 24 | d[13] << 16 | d[14] << 8 | d[15];
225 r = sat_calloc(i ? i : 1, sizeof(char *));
229 for (o = 0; o < i; o++)
233 d += strlen((char *)d) + 1;
234 if (d >= h->dp + h->dcnt)
243 static unsigned char *
244 headbinary(RpmHead *h, int tag, unsigned int *sizep)
247 unsigned char *d = headfindtag(h, tag);
248 if (!d || d[4] != 0 || d[5] != 0 || d[6] != 0 || d[7] != 7)
250 o = d[8] << 24 | d[9] << 16 | d[10] << 8 | d[11];
251 i = d[12] << 24 | d[13] << 16 | d[14] << 8 | d[15];
252 if (o > h->dcnt || o + i < o || o + i > h->dcnt)
259 static char *headtoevr(RpmHead *h)
266 version = headstring(h, TAG_VERSION);
267 release = headstring(h, TAG_RELEASE);
268 epoch = headint32(h, TAG_EPOCH);
269 if (!version || !release)
271 fprintf(stderr, "headtoevr: bad rpm header\n");
274 for (v = version; *v >= 0 && *v <= '9'; v++)
276 if (epoch || (v != version && *v == ':'))
278 char epochbuf[11]; /* 32bit decimal will fit in */
279 sprintf(epochbuf, "%u", epoch);
280 evr = sat_malloc(strlen(epochbuf) + 1 + strlen(version) + 1 + strlen(release) + 1);
281 sprintf(evr, "%s:%s-%s", epochbuf, version, release);
285 evr = sat_malloc(strlen(version) + 1 + strlen(release) + 1);
286 sprintf(evr, "%s-%s", version, release);
293 setutf8string(Repodata *repodata, Id handle, Id tag, const char *str)
295 const unsigned char *cp;
298 unsigned char *buf = 0, *bp;
300 /* check if it's already utf8, code taken from screen ;-) */
301 cp = (const unsigned char *)str;
302 while ((c = *cp++) != 0)
306 if ((c & 0xc0) != 0x80)
307 break; /* encoding error */
308 c = (c & 0x3f) | (state << 6);
309 if (!(state & 0x40000000))
311 /* check for overlong sequences */
312 if ((c & 0x820823e0) == 0x80000000)
314 else if ((c & 0x020821f0) == 0x02000000)
316 else if ((c & 0x000820f8) == 0x00080000)
318 else if ((c & 0x0000207c) == 0x00002000)
328 c = (c & 0x01) | 0xbffffffc; /* 5 bytes to follow */
330 c = (c & 0x03) | 0xbfffff00; /* 4 */
332 c = (c & 0x07) | 0xbfffc000; /* 3 */
334 c = (c & 0x0f) | 0xbff00000; /* 2 */
336 c = (c & 0x1f) | 0xfc000000; /* 1 */
340 state = (c & 0x80000000) ? c : 0;
344 /* not utf8, assume latin1 */
345 buf = sat_malloc(2 * strlen(str) + 1);
346 cp = (const unsigned char *)str;
349 while ((c = *cp++) != 0)
362 repodata_set_str(repodata, handle, tag, str);
368 #define MAKEDEPS_FILTER_WEAK (1 << 0)
369 #define MAKEDEPS_FILTER_STRONG (1 << 1)
370 #define MAKEDEPS_NO_RPMLIB (1 << 2)
373 * strong: 0: ignore strongness
374 * 1: filter to strong
378 makedeps(Pool *pool, Repo *repo, RpmHead *rpmhead, int tagn, int tagv, int tagf, int flags)
382 int i, cc, nc, vc, fc;
384 unsigned int olddeps;
388 strong = flags & (MAKEDEPS_FILTER_STRONG|MAKEDEPS_FILTER_WEAK);
389 n = headstringarray(rpmhead, tagn, &nc);
392 v = headstringarray(rpmhead, tagv, &vc);
398 f = headint32array(rpmhead, tagf, &fc);
405 if (nc != vc || nc != fc)
407 fprintf(stderr, "bad dependency entries\n");
412 haspre = 0; /* add no prereq marker */
415 /* we do filtering */
417 for (i = 0; i < nc; i++)
419 if (strong && (f[i] & DEP_STRONG) != (strong == MAKEDEPS_FILTER_WEAK ? 0 : DEP_STRONG))
421 if ((flags & MAKEDEPS_NO_RPMLIB) != 0)
422 if (!strncmp(n[i], "rpmlib(", 7))
424 if ((f[i] & DEP_PRE) != 0)
429 else if (tagn == TAG_REQUIRENAME)
431 /* no filtering, just look for the first prereq */
432 for (i = 0; i < nc; i++)
433 if ((f[i] & DEP_PRE) != 0)
447 olddeps = repo_reserve_ids(repo, 0, cc);
448 ida = repo->idarraydata + olddeps;
455 haspre = 2; /* pass two: prereqs */
457 *ida++ = SOLVABLE_PREREQMARKER;
459 if (strong && (f[i] & DEP_STRONG) != (strong == MAKEDEPS_FILTER_WEAK ? 0 : DEP_STRONG))
461 if (haspre == 1 && (f[i] & DEP_PRE) != 0)
463 if (haspre == 2 && (f[i] & DEP_PRE) == 0)
465 if ((flags & MAKEDEPS_NO_RPMLIB) != 0)
466 if (!strncmp(n[i], "rpmlib(", 7))
468 if (f[i] & (DEP_LESS|DEP_GREATER|DEP_EQUAL))
472 if ((f[i] & DEP_LESS) != 0)
474 if ((f[i] & DEP_EQUAL) != 0)
476 if ((f[i] & DEP_GREATER) != 0)
478 name = str2id(pool, n[i], 1);
479 if (v[i][0] == '0' && v[i][1] == ':' && v[i][2])
480 evr = str2id(pool, v[i] + 2, 1);
482 evr = str2id(pool, v[i], 1);
483 *ida++ = rel2id(pool, name, evr, flags, 1);
486 *ida++ = str2id(pool, n[i], 1);
489 repo->idarraysize += cc + 1;
497 #ifdef USE_FILEFILTER
499 #define FILEFILTER_EXACT 0
500 #define FILEFILTER_STARTS 1
501 #define FILEFILTER_CONTAINS 2
509 static struct filefilter filefilters[] = {
510 { FILEFILTER_CONTAINS, "/bin/", 0},
511 { FILEFILTER_CONTAINS, "/sbin/", 0},
512 { FILEFILTER_CONTAINS, "/lib/", 0},
513 { FILEFILTER_CONTAINS, "/lib64/", 0},
514 { FILEFILTER_CONTAINS, "/etc/", 0},
515 { FILEFILTER_STARTS, "/usr/games/", 0},
516 { FILEFILTER_EXACT, "/usr/share/dict/", "words"},
517 { FILEFILTER_STARTS, "/usr/share/", "magic.mime"},
518 { FILEFILTER_STARTS, "/opt/gnome/games/", 0},
524 adddudata(Pool *pool, Repo *repo, Repodata *data, Solvable *s, RpmHead *rpmhead, char **dn, unsigned int *di, int fc, int dic)
528 unsigned int *fkb, *fn, *fsz, *fm, *fino;
529 unsigned int inotest[256], inotestok;
533 fsz = headint32array(rpmhead, TAG_FILESIZES, &fszc);
534 if (!fsz || fc != fszc)
539 /* stupid rpm recodrs sizes of directories, so we have to check the mode */
540 fm = headint16array(rpmhead, TAG_FILEMODES, &fszc);
541 if (!fm || fc != fszc)
547 fino = headint32array(rpmhead, TAG_FILEINODES, &fszc);
548 if (!fino || fc != fszc)
556 if (fc < sizeof(inotest))
558 memset(inotest, 0, sizeof(inotest));
559 for (i = 0; i < fc; i++)
562 if (fsz[i] == 0 || !S_ISREG(fm[i]))
564 off = (fino[i] >> 5) & (sizeof(inotest)/sizeof(*inotest) - 1);
565 bit = 1 << (fino[i] & 31);
566 if ((inotest[off] & bit) != 0)
575 unsigned int *fdev = headint32array(rpmhead, TAG_FILEDEVICES, &fszc);
577 unsigned int mask, hash, hh;
578 if (!fdev || fc != fszc)
587 while ((mask & (mask - 1)) != 0)
588 mask = mask & (mask - 1);
590 if (mask > sizeof(inotest)/sizeof(*inotest))
591 fx = sat_calloc(mask, sizeof(unsigned int));
595 memset(fx, 0, mask * sizeof(unsigned int));
598 for (i = 0; i < fc; i++)
600 if (fsz[i] == 0 || !S_ISREG(fm[i]))
602 hash = (fino[i] + fdev[i] * 31) & mask;
604 while ((j = fx[hash]) != 0)
606 if (fino[j - 1] == fino[i] && fdev[j - 1] == fdev[i])
608 fsz[i] = 0; /* kill entry */
611 hash = (hash + hh++) & mask;
621 fn = sat_calloc(dic, sizeof(unsigned int));
622 fkb = sat_calloc(dic, sizeof(unsigned int));
623 for (i = 0; i < fc; i++)
625 if (fsz[i] == 0 || !S_ISREG(fm[i]))
630 fkb[di[i]] += fsz[i] / 1024 + 1;
635 handle = s - pool->solvables;
636 for (i = 0; i < fc; i++)
640 if (!*dn[i] && (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC))
641 did = repodata_str2dir(data, "/usr/src", 1);
643 did = repodata_str2dir(data, dn[i], 1);
644 repodata_add_dirnumnum(data, handle, SOLVABLE_DISKUSAGE, did, fkb[i], fn[i]);
650 /* assumes last processed array is provides! */
652 addfileprovides(Pool *pool, Repo *repo, Repodata *data, Solvable *s, RpmHead *rpmhead, unsigned int olddeps)
659 #ifdef USE_FILEFILTER
661 struct filefilter *ff;
670 bn = headstringarray(rpmhead, TAG_BASENAMES, &bnc);
673 dn = headstringarray(rpmhead, TAG_DIRNAMES, &dnc);
679 di = headint32array(rpmhead, TAG_DIRINDEXES, &dic);
688 fprintf(stderr, "bad filelist\n");
693 adddudata(pool, repo, data, s, rpmhead, dn, di, bnc, dic);
695 for (i = 0; i < bnc; i++)
697 #ifdef USE_FILEFILTER
699 for (j = 0; j < sizeof(filefilters)/sizeof(*filefilters); j++, ff++)
703 switch (ff->dirmatch)
705 case FILEFILTER_STARTS:
706 if (strncmp(dn[di[i]], ff->dir, strlen(ff->dir)))
709 case FILEFILTER_CONTAINS:
710 if (!strstr(dn[di[i]], ff->dir))
713 case FILEFILTER_EXACT:
715 if (strcmp(dn[di[i]], ff->dir))
722 if (strcmp(bn[i], ff->base))
727 if (j == sizeof(filefilters)/sizeof(*filefilters))
731 j = strlen(bn[i]) + strlen(dn[di[i]]) + 1;
735 fn = sat_realloc(fn, fna);
737 strcpy(fn, dn[di[i]]);
739 olddeps = repo_addid_dep(repo, olddeps, str2id(pool, fn, 1), SOLVABLE_FILEMARKER);
744 handle = s - pool->solvables;
745 did = repodata_str2dir(data, dn[di[i]], 1);
747 did = repodata_str2dir(data, "/", 1);
748 repodata_add_dirstr(data, handle, SOLVABLE_FILELIST, did, bn[i]);
762 addsourcerpm(Pool *pool, Repodata *data, Id handle, char *sourcerpm, char *name, char *evr)
764 const char *p, *sevr, *sarch;
766 p = strrchr(sourcerpm, '.');
767 if (!p || strcmp(p, ".rpm") != 0)
770 while (p > sourcerpm && *p != '.')
772 if (*p != '.' || p == sourcerpm)
775 while (p > sourcerpm && *p != '-')
777 if (*p != '-' || p == sourcerpm)
780 while (p > sourcerpm && *p != '-')
782 if (*p != '-' || p == sourcerpm)
785 if (!strcmp(sarch, "src.rpm"))
786 repodata_set_constantid(data, handle, SOLVABLE_SOURCEARCH, ARCH_SRC);
787 else if (!strcmp(sarch, "nosrc.rpm"))
788 repodata_set_constantid(data, handle, SOLVABLE_SOURCEARCH, ARCH_NOSRC);
790 repodata_set_constantid(data, handle, SOLVABLE_SOURCEARCH, strn2id(pool, sarch, strlen(sarch) - 4, 1));
791 if (evr && !strncmp(sevr, evr, sarch - sevr - 1) && evr[sarch - sevr - 1] == 0)
792 repodata_set_void(data, handle, SOLVABLE_SOURCEEVR);
794 repodata_set_id(data, handle, SOLVABLE_SOURCEEVR, strn2id(pool, sevr, sarch - sevr - 1, 1));
795 if (name && !strncmp(sourcerpm, name, sevr - sourcerpm - 1) && name[sevr - sourcerpm - 1] == 0)
796 repodata_set_void(data, handle, SOLVABLE_SOURCENAME);
798 repodata_set_id(data, handle, SOLVABLE_SOURCENAME, strn2id(pool, sourcerpm, sevr - sourcerpm - 1, 1));
802 rpm2solv(Pool *pool, Repo *repo, Repodata *data, Solvable *s, RpmHead *rpmhead, int flags)
808 name = headstring(rpmhead, TAG_NAME);
809 if (!strcmp(name, "gpg-pubkey"))
811 s->name = str2id(pool, name, 1);
814 fprintf(stderr, "package has no name\n");
817 sourcerpm = headstring(rpmhead, TAG_SOURCERPM);
819 s->arch = str2id(pool, headstring(rpmhead, TAG_ARCH), 1);
822 if (headexists(rpmhead, TAG_NOSOURCE) || headexists(rpmhead, TAG_NOPATCH))
823 s->arch = ARCH_NOSRC;
828 s->arch = ARCH_NOARCH;
829 evr = headtoevr(rpmhead);
830 s->evr = str2id(pool, evr, 1);
831 s->vendor = str2id(pool, headstring(rpmhead, TAG_VENDOR), 1);
833 s->provides = makedeps(pool, repo, rpmhead, TAG_PROVIDENAME, TAG_PROVIDEVERSION, TAG_PROVIDEFLAGS, 0);
834 if ((flags & RPM_ADD_NO_FILELIST) == 0)
835 s->provides = addfileprovides(pool, repo, data, s, rpmhead, s->provides);
836 if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
837 s->provides = repo_addid_dep(repo, s->provides, rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
838 s->requires = makedeps(pool, repo, rpmhead, TAG_REQUIRENAME, TAG_REQUIREVERSION, TAG_REQUIREFLAGS, (flags & RPM_ADD_NO_RPMLIBREQS) ? MAKEDEPS_NO_RPMLIB : 0);
839 s->conflicts = makedeps(pool, repo, rpmhead, TAG_CONFLICTNAME, TAG_CONFLICTVERSION, TAG_CONFLICTFLAGS, 0);
840 s->obsoletes = makedeps(pool, repo, rpmhead, TAG_OBSOLETENAME, TAG_OBSOLETEVERSION, TAG_OBSOLETEFLAGS, 0);
842 s->recommends = makedeps(pool, repo, rpmhead, TAG_SUGGESTSNAME, TAG_SUGGESTSVERSION, TAG_SUGGESTSFLAGS, MAKEDEPS_FILTER_STRONG);
843 s->suggests = makedeps(pool, repo, rpmhead, TAG_SUGGESTSNAME, TAG_SUGGESTSVERSION, TAG_SUGGESTSFLAGS, MAKEDEPS_FILTER_WEAK);
844 s->supplements = makedeps(pool, repo, rpmhead, TAG_ENHANCESNAME, TAG_ENHANCESVERSION, TAG_ENHANCESFLAGS, MAKEDEPS_FILTER_STRONG);
845 s->enhances = makedeps(pool, repo, rpmhead, TAG_ENHANCESNAME, TAG_ENHANCESVERSION, TAG_ENHANCESFLAGS, MAKEDEPS_FILTER_WEAK);
846 s->supplements = repo_fix_supplements(repo, s->provides, s->supplements, 0);
847 s->conflicts = repo_fix_conflicts(repo, s->conflicts);
855 handle = s - pool->solvables;
856 str = headstring(rpmhead, TAG_SUMMARY);
858 setutf8string(data, handle, SOLVABLE_SUMMARY, str);
859 str = headstring(rpmhead, TAG_DESCRIPTION);
863 for (aut = str; (aut = strchr(aut, '\n')) != 0; aut++)
864 if (!strncmp(aut, "\nAuthors:\n--------\n", 19))
868 /* oh my, found SUSE special author section */
873 while (l > 0 && str[l - 1] == '\n')
876 setutf8string(data, handle, SOLVABLE_DESCRIPTION, str);
878 aut = str; /* copy over */
879 while (*p == ' ' || *p == '\n')
892 while (aut != str && aut[-1] == '\n')
896 setutf8string(data, handle, SOLVABLE_AUTHORS, str);
900 setutf8string(data, handle, SOLVABLE_DESCRIPTION, str);
902 str = headstring(rpmhead, TAG_GROUP);
904 repodata_set_poolstr(data, handle, SOLVABLE_GROUP, str);
905 str = headstring(rpmhead, TAG_LICENSE);
907 repodata_set_poolstr(data, handle, SOLVABLE_LICENSE, str);
908 str = headstring(rpmhead, TAG_URL);
910 repodata_set_str(data, handle, SOLVABLE_URL, str);
911 str = headstring(rpmhead, TAG_DISTRIBUTION);
913 repodata_set_poolstr(data, handle, SOLVABLE_DISTRIBUTION, str);
914 str = headstring(rpmhead, TAG_PACKAGER);
916 repodata_set_poolstr(data, handle, SOLVABLE_PACKAGER, str);
917 u32 = headint32(rpmhead, TAG_BUILDTIME);
919 repodata_set_num(data, handle, SOLVABLE_BUILDTIME, u32);
920 u32 = headint32(rpmhead, TAG_INSTALLTIME);
922 repodata_set_num(data, handle, SOLVABLE_INSTALLTIME, u32);
923 u32 = headint32(rpmhead, TAG_SIZE);
925 repodata_set_num(data, handle, SOLVABLE_INSTALLSIZE, (u32 + 1023) / 1024);
927 addsourcerpm(pool, data, handle, sourcerpm, name, evr);
934 copyreldep(Pool *pool, Pool *frompool, Id id)
936 Reldep *rd = GETRELDEP(frompool, id);
937 Id name = rd->name, evr = rd->evr;
939 name = copyreldep(pool, frompool, name);
941 name = str2id(pool, id2str(frompool, name), 1);
943 evr = copyreldep(pool, frompool, evr);
945 evr = str2id(pool, id2str(frompool, evr), 1);
946 return rel2id(pool, name, evr, rd->flags, 1);
950 copydeps(Pool *pool, Repo *repo, Offset fromoff, Repo *fromrepo)
955 Pool *frompool = fromrepo->pool;
959 from = fromrepo->idarraydata + fromoff;
960 for (ida = from, cc = 0; *ida; ida++, cc++)
964 ido = repo_reserve_ids(repo, 0, cc);
965 ida = repo->idarraydata + ido;
966 if (frompool && pool != frompool)
972 id = copyreldep(pool, frompool, id);
974 id = str2id(pool, id2str(frompool, id), 1);
980 memcpy(ida, from, (cc + 1) * sizeof(Id));
981 repo->idarraysize += cc + 1;
985 #define COPYDIR_DIRCACHE_SIZE 512
987 static Id copydir_complex(Pool *pool, Repodata *data, Stringpool *fromspool, Repodata *fromdata, Id did, Id *cache);
990 copydir(Pool *pool, Repodata *data, Stringpool *fromspool, Repodata *fromdata, Id did, Id *cache)
992 if (cache && cache[did & 255] == did)
993 return cache[(did & 255) + 256];
994 return copydir_complex(pool, data, fromspool, fromdata, did, cache);
998 copydir_complex(Pool *pool, Repodata *data, Stringpool *fromspool, Repodata *fromdata, Id did, Id *cache)
1000 Id parent = dirpool_parent(&fromdata->dirpool, did);
1001 Id compid = dirpool_compid(&fromdata->dirpool, did);
1003 parent = copydir(pool, data, fromspool, fromdata, parent, cache);
1004 if (fromspool != &pool->ss)
1005 compid = str2id(pool, stringpool_id2str(fromspool, compid), 1);
1006 compid = dirpool_add_dir(&data->dirpool, parent, compid, 1);
1009 cache[did & 255] = did;
1010 cache[(did & 255) + 256] = compid;
1015 struct solvable_copy_cbdata {
1022 solvable_copy_cb(void *vcbdata, Solvable *r, Repodata *fromdata, Repokey *key, KeyValue *kv)
1024 struct solvable_copy_cbdata *cbdata = vcbdata;
1026 Repodata *data = cbdata->data;
1027 Id handle = cbdata->handle;
1028 Pool *pool = data->repo->pool, *frompool = fromdata->repo->pool;
1029 Stringpool *fromspool = fromdata->localpool ? &fromdata->spool : &frompool->ss;
1031 keyname = key->name;
1032 if (keyname >= ID_NUM_INTERNAL)
1033 keyname = str2id(pool, id2str(frompool, keyname), 1);
1036 case REPOKEY_TYPE_ID:
1037 case REPOKEY_TYPE_CONSTANTID:
1039 assert(!data->localpool); /* implement me! */
1040 if (pool != frompool || fromdata->localpool)
1043 id = copyreldep(pool, frompool, id);
1045 id = str2id(pool, stringpool_id2str(fromspool, id), 1);
1047 if (key->type == REPOKEY_TYPE_ID)
1048 repodata_set_id(data, handle, keyname, id);
1050 repodata_set_constantid(data, handle, keyname, id);
1052 case REPOKEY_TYPE_STR:
1053 repodata_set_str(data, handle, keyname, kv->str);
1055 case REPOKEY_TYPE_VOID:
1056 repodata_set_void(data, handle, keyname);
1058 case REPOKEY_TYPE_NUM:
1059 repodata_set_num(data, handle, keyname, kv->num);
1061 case REPOKEY_TYPE_CONSTANT:
1062 repodata_set_constant(data, handle, keyname, kv->num);
1064 case REPOKEY_TYPE_DIRNUMNUMARRAY:
1066 assert(!data->localpool); /* implement me! */
1067 id = copydir(pool, data, fromspool, fromdata, id, cbdata->dircache);
1068 repodata_add_dirnumnum(data, handle, keyname, id, kv->num, kv->num2);
1070 case REPOKEY_TYPE_DIRSTRARRAY:
1072 assert(!data->localpool); /* implement me! */
1073 id = copydir(pool, data, fromspool, fromdata, id, cbdata->dircache);
1074 repodata_add_dirstr(data, handle, keyname, id, kv->str);
1083 solvable_copy(Solvable *s, Solvable *r, Repodata *data, Id *dircache)
1085 Repo *repo = s->repo;
1086 Repo *fromrepo = r->repo;
1087 Pool *pool = repo->pool;
1088 struct solvable_copy_cbdata cbdata;
1090 /* copy solvable data */
1091 if (pool == fromrepo->pool)
1096 s->vendor = r->vendor;
1101 s->name = str2id(pool, id2str(fromrepo->pool, r->name), 1);
1103 s->evr = str2id(pool, id2str(fromrepo->pool, r->evr), 1);
1105 s->arch = str2id(pool, id2str(fromrepo->pool, r->arch), 1);
1107 s->vendor = str2id(pool, id2str(fromrepo->pool, r->vendor), 1);
1109 s->provides = copydeps(pool, repo, r->provides, fromrepo);
1110 s->requires = copydeps(pool, repo, r->requires, fromrepo);
1111 s->conflicts = copydeps(pool, repo, r->conflicts, fromrepo);
1112 s->obsoletes = copydeps(pool, repo, r->obsoletes, fromrepo);
1113 s->recommends = copydeps(pool, repo, r->recommends, fromrepo);
1114 s->suggests = copydeps(pool, repo, r->suggests, fromrepo);
1115 s->supplements = copydeps(pool, repo, r->supplements, fromrepo);
1116 s->enhances = copydeps(pool, repo, r->enhances, fromrepo);
1118 /* copy all attributes */
1122 cbdata.handle = s - pool->solvables;
1123 cbdata.dircache = dircache;
1124 repo_search(fromrepo, (r - fromrepo->pool->solvables), 0, 0, SEARCH_NO_STORAGE_SOLVABLE, solvable_copy_cb, &cbdata);
1127 /* used to sort entries returned in some database order */
1129 rpmids_sort_cmp(const void *va, const void *vb, void *dp)
1131 struct rpmid const *a = va, *b = vb;
1133 r = strcmp(a->name, b->name);
1136 return a->dbid - b->dbid;
1140 pkgids_sort_cmp(const void *va, const void *vb, void *dp)
1143 Pool *pool = repo->pool;
1144 Solvable *a = pool->solvables + *(Id *)va;
1145 Solvable *b = pool->solvables + *(Id *)vb;
1148 if (a->name != b->name)
1149 return strcmp(id2str(pool, a->name), id2str(pool, b->name));
1150 rpmdbid = repo->rpmdbid;
1151 return rpmdbid[(a - pool->solvables) - repo->start] - rpmdbid[(b - pool->solvables) - repo->start];
1155 swap_solvables(Repo *repo, Repodata *data, Id pa, Id pb)
1157 Pool *pool = repo->pool;
1160 tmp = pool->solvables[pa];
1161 pool->solvables[pa] = pool->solvables[pb];
1162 pool->solvables[pb] = tmp;
1165 Id tmpid = repo->rpmdbid[pa - repo->start];
1166 repo->rpmdbid[pa - repo->start] = repo->rpmdbid[pb - repo->start];
1167 repo->rpmdbid[pb - repo->start] = tmpid;
1169 /* only works if nothing is already internalized! */
1170 if (data && data->attrs)
1172 Id *tmpattrs = data->attrs[pa - data->start];
1173 data->attrs[pa - data->start] = data->attrs[pb - data->start];
1174 data->attrs[pb - data->start] = tmpattrs;
1179 mkrpmdbcookie(struct stat *st, unsigned char *cookie)
1181 memset(cookie, 0, 32);
1182 cookie[3] = RPMDB_COOKIE_VERSION;
1183 memcpy(cookie + 16, &st->st_ino, sizeof(st->st_ino));
1184 memcpy(cookie + 24, &st->st_dev, sizeof(st->st_dev));
1188 count_headers(const char *rootdir, DB_ENV *dbenv)
1190 char dbpath[PATH_MAX];
1191 struct stat statbuf;
1199 snprintf(dbpath, PATH_MAX, "%s/var/lib/rpm/Name", rootdir);
1200 if (stat(dbpath, &statbuf))
1202 memset(&dbkey, 0, sizeof(dbkey));
1203 memset(&dbdata, 0, sizeof(dbdata));
1204 if (db_create(&db, dbenv, 0))
1206 perror("db_create");
1209 if (db->open(db, 0, "Name", 0, DB_UNKNOWN, DB_RDONLY, 0664))
1211 perror("db->open Name index");
1214 if (db->get_byteswapped(db, &byteswapped))
1216 perror("db->get_byteswapped");
1219 if (db->cursor(db, NULL, &dbc, 0))
1221 perror("db->cursor");
1224 while (dbc->c_get(dbc, &dbkey, &dbdata, DB_NEXT) == 0)
1225 count += dbdata.size >> 3;
1232 * read rpm db as repo
1237 repo_add_rpmdb(Repo *repo, Repo *ref, const char *rootdir, int flags)
1239 Pool *pool = repo->pool;
1240 unsigned char buf[16];
1245 unsigned char *dp, *dbidp;
1247 struct rpmid *rpmids, *rp;
1253 unsigned int refmask, h;
1254 char dbpath[PATH_MAX];
1258 struct stat packagesstat;
1259 unsigned char newcookie[32];
1260 const unsigned char *oldcookie = 0;
1261 Id oldcookietype = 0;
1263 int count = 0, done = 0;
1266 now = sat_timems(0);
1267 memset(&dbkey, 0, sizeof(dbkey));
1268 memset(&dbdata, 0, sizeof(dbdata));
1273 if (!(flags & REPO_REUSE_REPODATA))
1274 data = repo_add_repodata(repo, 0);
1276 data = repo_last_repodata(repo);
1278 if (ref && !(ref->nsolvables && ref->rpmdbid))
1281 if (db_env_create(&dbenv, 0))
1283 perror("db_env_create");
1286 snprintf(dbpath, PATH_MAX, "%s/var/lib/rpm", rootdir);
1287 /* should look in /usr/lib/rpm/macros instead, but we want speed... */
1289 if (dbenv->open(dbenv, dbpath, DB_CREATE|DB_INIT_CDB|DB_INIT_MPOOL, 0))
1291 if (dbenv->open(dbenv, dbpath, DB_CREATE|DB_PRIVATE|DB_INIT_MPOOL, 0))
1294 perror("dbenv open");
1298 /* XXX: should get ro lock of Packages database! */
1299 snprintf(dbpath, PATH_MAX, "%s/var/lib/rpm/Packages", rootdir);
1300 if (stat(dbpath, &packagesstat))
1305 mkrpmdbcookie(&packagesstat, newcookie);
1306 repodata_set_bin_checksum(data, SOLVID_META, REPOSITORY_RPMDBCOOKIE, REPOKEY_TYPE_SHA256, newcookie);
1309 oldcookie = repo_lookup_bin_checksum(ref, SOLVID_META, REPOSITORY_RPMDBCOOKIE, &oldcookietype);
1310 if (!ref || !oldcookie || oldcookietype != REPOKEY_TYPE_SHA256 || memcmp(oldcookie, newcookie, 32) != 0)
1313 int solvstart = 0, solvend = 0;
1315 if ((flags & RPMDB_REPORT_PROGRESS) != 0)
1316 count = count_headers(rootdir, dbenv);
1317 if (db_create(&db, dbenv, 0))
1319 perror("db_create");
1322 if (db->open(db, 0, "Packages", 0, DB_UNKNOWN, DB_RDONLY, 0664))
1324 perror("db->open Packages index");
1327 if (db->get_byteswapped(db, &byteswapped))
1329 perror("db->get_byteswapped");
1332 if (db->cursor(db, NULL, &dbc, 0))
1334 perror("db->cursor");
1337 dbidp = (unsigned char *)&dbid;
1342 while (dbc->c_get(dbc, &dbkey, &dbdata, DB_NEXT) == 0)
1346 s = pool_id2solvable(pool, repo_add_solvable(repo));
1348 solvstart = s - pool->solvables;
1349 solvend = s - pool->solvables + 1;
1352 repo->rpmdbid = repo_sidedata_create(repo, sizeof(Id));
1353 if (dbkey.size != 4)
1355 fprintf(stderr, "corrupt Packages database (key size)\n");
1367 memcpy(dbidp, dp, 4);
1368 if (dbid == 0) /* the join key */
1370 if (dbdata.size < 8)
1372 fprintf(stderr, "corrupt rpm database (size %u)\n", dbdata.size);
1375 if (dbdata.size > rpmheadsize)
1377 rpmheadsize = dbdata.size + 128;
1378 rpmhead = sat_realloc(rpmhead, sizeof(*rpmhead) + rpmheadsize);
1380 memcpy(buf, dbdata.data, 8);
1381 rpmhead->cnt = buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3];
1382 rpmhead->dcnt = buf[4] << 24 | buf[5] << 16 | buf[6] << 8 | buf[7];
1383 if (8 + rpmhead->cnt * 16 + rpmhead->dcnt > dbdata.size)
1385 fprintf(stderr, "corrupt rpm database (data size)\n");
1388 memcpy(rpmhead->data, (unsigned char *)dbdata.data + 8, rpmhead->cnt * 16 + rpmhead->dcnt);
1389 rpmhead->dp = rpmhead->data + rpmhead->cnt * 16;
1390 repo->rpmdbid[(s - pool->solvables) - repo->start] = dbid;
1391 if (rpm2solv(pool, repo, data, s, rpmhead, flags))
1398 /* We can reuse this solvable, but make sure it's still
1399 associated with this repo. */
1400 memset(s, 0, sizeof(*s));
1403 if ((flags & RPMDB_REPORT_PROGRESS) != 0)
1407 if (done < count && (done - 1) * 100 / count != done * 100 / count)
1408 pool_debug(pool, SAT_ERROR, "%%%% %d\n", done * 100 / count);
1413 /* oops, could not reuse. free it instead */
1414 repo_free_solvable_block(repo, s - pool->solvables, 1, 1);
1421 /* now sort all solvables in the new solvstart..solvend block */
1422 if (solvend - solvstart > 1)
1424 pkgids = sat_malloc2(solvend - solvstart, sizeof(Id));
1425 for (i = solvstart; i < solvend; i++)
1426 pkgids[i - solvstart] = i;
1427 sat_sort(pkgids, solvend - solvstart, sizeof(Id), pkgids_sort_cmp, repo);
1429 for (i = solvstart; i < solvend; i++)
1431 int j = pkgids[i - solvstart];
1433 j = pkgids[i - solvstart] = pkgids[j - solvstart];
1435 swap_solvables(repo, data, i, j);
1442 Id dircache[COPYDIR_DIRCACHE_SIZE]; /* see copydir */
1444 memset(dircache, 0, sizeof(dircache));
1445 if (db_create(&db, dbenv, 0))
1447 perror("db_create");
1450 if (db->open(db, 0, "Name", 0, DB_UNKNOWN, DB_RDONLY, 0664))
1452 perror("db->open Name index");
1455 if (db->get_byteswapped(db, &byteswapped))
1457 perror("db->get_byteswapped");
1460 if (db->cursor(db, NULL, &dbc, 0))
1462 perror("db->cursor");
1465 dbidp = (unsigned char *)&dbid;
1468 while (dbc->c_get(dbc, &dbkey, &dbdata, DB_NEXT) == 0)
1470 if (dbkey.size == 10 && !memcmp(dbkey.data, "gpg-pubkey", 10))
1484 memcpy(dbidp, dp, 4);
1485 rpmids = sat_extend(rpmids, nrpmids, 1, sizeof(*rpmids), 255);
1486 rpmids[nrpmids].dbid = dbid;
1487 rpmids[nrpmids].name = sat_malloc((int)dbkey.size + 1);
1488 memcpy(rpmids[nrpmids].name, dbkey.data, (int)dbkey.size);
1489 rpmids[nrpmids].name[(int)dbkey.size] = 0;
1500 sat_sort(rpmids, nrpmids, sizeof(*rpmids), rpmids_sort_cmp, 0);
1502 dbidp = (unsigned char *)&dbid;
1506 /* create hash from dbid to ref */
1507 refmask = mkmask(ref->nsolvables);
1508 refhash = sat_calloc(refmask + 1, sizeof(Id));
1509 for (i = 0; i < ref->end - ref->start; i++)
1511 if (!ref->rpmdbid[i])
1513 h = ref->rpmdbid[i] & refmask;
1515 h = (h + 317) & refmask;
1516 refhash[h] = i + 1; /* make it non-zero */
1519 /* count the misses, they will cost us time */
1520 if ((flags & RPMDB_REPORT_PROGRESS) != 0)
1522 for (i = 0, rp = rpmids; i < nrpmids; i++, rp++)
1528 while ((id = refhash[h]))
1530 if (ref->rpmdbid[id - 1] == dbid)
1532 h = (h + 317) & refmask;
1541 s = pool_id2solvable(pool, repo_add_solvable_block(repo, nrpmids));
1543 repo->rpmdbid = repo_sidedata_create(repo, sizeof(Id));
1545 for (i = 0, rp = rpmids; i < nrpmids; i++, rp++, s++)
1548 repo->rpmdbid[(s - pool->solvables) - repo->start] = dbid;
1552 while ((id = refhash[h]))
1554 if (ref->rpmdbid[id - 1] == dbid)
1556 h = (h + 317) & refmask;
1560 Solvable *r = ref->pool->solvables + ref->start + (id - 1);
1563 solvable_copy(s, r, data, dircache);
1570 if (db_create(&db, dbenv, 0))
1572 perror("db_create");
1575 if (db->open(db, 0, "Packages", 0, DB_UNKNOWN, DB_RDONLY, 0664))
1577 perror("db->open var/lib/rpm/Packages");
1580 if (db->get_byteswapped(db, &byteswapped))
1582 perror("db->get_byteswapped");
1594 memcpy(buf, dbidp, 4);
1599 if (db->get(db, NULL, &dbkey, &dbdata, 0))
1602 fprintf(stderr, "corrupt rpm database, key %d not found\n", dbid);
1603 fprintf(stderr, "please run 'rpm --rebuilddb' to recreate the database index files\n");
1606 if (dbdata.size < 8)
1608 fprintf(stderr, "corrupt rpm database (size)\n");
1611 if (dbdata.size > rpmheadsize)
1613 rpmheadsize = dbdata.size + 128;
1614 rpmhead = sat_realloc(rpmhead, sizeof(*rpmhead) + rpmheadsize);
1616 memcpy(buf, dbdata.data, 8);
1617 rpmhead->cnt = buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3];
1618 rpmhead->dcnt = buf[4] << 24 | buf[5] << 16 | buf[6] << 8 | buf[7];
1619 if (8 + rpmhead->cnt * 16 + rpmhead->dcnt > dbdata.size)
1621 fprintf(stderr, "corrupt rpm database (data size)\n");
1624 memcpy(rpmhead->data, (unsigned char *)dbdata.data + 8, rpmhead->cnt * 16 + rpmhead->dcnt);
1625 rpmhead->dp = rpmhead->data + rpmhead->cnt * 16;
1627 rpm2solv(pool, repo, data, s, rpmhead, flags);
1628 if ((flags & RPMDB_REPORT_PROGRESS) != 0)
1632 if (done < count && (done - 1) * 100 / count != done * 100 / count)
1633 pool_debug(pool, SAT_ERROR, "%%%% %d\n", done * 100 / count);
1641 for (i = 0; i < nrpmids; i++)
1642 sat_free(rpmids[i].name);
1648 dbenv->close(dbenv, 0);
1651 if (!(flags & REPO_NO_INTERNALIZE))
1652 repodata_internalize(data);
1653 if ((flags & RPMDB_REPORT_PROGRESS) != 0)
1654 pool_debug(pool, SAT_ERROR, "%%%% 100\n");
1655 POOL_DEBUG(SAT_DEBUG_STATS, "repo_add_rpmdb took %d ms\n", sat_timems(now));
1656 POOL_DEBUG(SAT_DEBUG_STATS, "repo size: %d solvables\n", repo->nsolvables);
1657 POOL_DEBUG(SAT_DEBUG_STATS, "repo memory used: %d K incore, %d K idarray\n", data->incoredatalen/1024, repo->idarraysize / (int)(1024/sizeof(Id)));
1661 static inline unsigned int
1662 getu32(unsigned char *dp)
1664 return dp[0] << 24 | dp[1] << 16 | dp[2] << 8 | dp[3];
1669 repo_add_rpms(Repo *repo, const char **rpms, int nrpms, int flags)
1671 int i, sigdsize, sigcnt, l;
1672 Pool *pool = repo->pool;
1674 RpmHead *rpmhead = 0;
1675 int rpmheadsize = 0;
1676 char *payloadformat;
1678 unsigned char lead[4096];
1679 int headerstart, headerend;
1682 unsigned char pkgid[16];
1687 if (!(flags & REPO_REUSE_REPODATA))
1688 data = repo_add_repodata(repo, 0);
1690 data = repo_last_repodata(repo);
1692 if ((flags & RPM_ADD_WITH_SHA256SUM) != 0)
1693 chksumtype = REPOKEY_TYPE_SHA256;
1694 else if ((flags & RPM_ADD_WITH_SHA1SUM) != 0)
1695 chksumtype = REPOKEY_TYPE_SHA1;
1696 for (i = 0; i < nrpms; i++)
1698 if ((fp = fopen(rpms[i], "r")) == 0)
1703 if (fstat(fileno(fp), &stb))
1709 chksumh = sat_chksum_free(chksumh, 0);
1711 chksumh = sat_chksum_create(chksumtype);
1712 if (fread(lead, 96 + 16, 1, fp) != 1 || getu32(lead) != 0xedabeedb)
1714 fprintf(stderr, "%s: not a rpm\n", rpms[i]);
1719 sat_chksum_add(chksumh, lead, 96 + 16);
1720 if (lead[78] != 0 || lead[79] != 5)
1722 fprintf(stderr, "%s: not a V5 header\n", rpms[i]);
1726 if (getu32(lead + 96) != 0x8eade801)
1728 fprintf(stderr, "%s: bad signature header\n", rpms[i]);
1732 sigcnt = getu32(lead + 96 + 8);
1733 sigdsize = getu32(lead + 96 + 12);
1734 if (sigcnt >= 0x4000000 || sigdsize >= 0x40000000)
1736 fprintf(stderr, "%s: bad signature header\n", rpms[i]);
1740 sigdsize += sigcnt * 16;
1741 sigdsize = (sigdsize + 7) & ~7;
1742 headerstart = 96 + 16 + sigdsize;
1744 if ((flags & RPM_ADD_WITH_PKGID) != 0)
1746 unsigned char *chksum;
1747 unsigned int chksumsize;
1748 /* extract pkgid from the signature header */
1749 if (sigdsize > rpmheadsize)
1751 rpmheadsize = sigdsize + 128;
1752 rpmhead = sat_realloc(rpmhead, sizeof(*rpmhead) + rpmheadsize);
1754 if (fread(rpmhead->data, sigdsize, 1, fp) != 1)
1756 fprintf(stderr, "%s: unexpected EOF\n", rpms[i]);
1761 sat_chksum_add(chksumh, rpmhead->data, sigdsize);
1762 rpmhead->cnt = sigcnt;
1763 rpmhead->dcnt = sigdsize - sigcnt * 16;
1764 rpmhead->dp = rpmhead->data + rpmhead->cnt * 16;
1765 chksum = headbinary(rpmhead, SIGTAG_MD5, &chksumsize);
1766 if (chksum && chksumsize == 16)
1769 memcpy(pkgid, chksum, 16);
1774 /* just skip the signature header */
1777 l = sigdsize > 4096 ? 4096 : sigdsize;
1778 if (fread(lead, l, 1, fp) != 1)
1780 fprintf(stderr, "%s: unexpected EOF\n", rpms[i]);
1785 sat_chksum_add(chksumh, lead, l);
1789 if (fread(lead, 16, 1, fp) != 1)
1791 fprintf(stderr, "%s: unexpected EOF\n", rpms[i]);
1796 sat_chksum_add(chksumh, lead, 16);
1797 if (getu32(lead) != 0x8eade801)
1799 fprintf(stderr, "%s: bad header\n", rpms[i]);
1803 sigcnt = getu32(lead + 8);
1804 sigdsize = getu32(lead + 12);
1805 if (sigcnt >= 0x4000000 || sigdsize >= 0x40000000)
1807 fprintf(stderr, "%s: bad header\n", rpms[i]);
1811 l = sigdsize + sigcnt * 16;
1812 headerend = headerstart + 16 + l;
1813 if (l > rpmheadsize)
1815 rpmheadsize = l + 128;
1816 rpmhead = sat_realloc(rpmhead, sizeof(*rpmhead) + rpmheadsize);
1818 if (fread(rpmhead->data, l, 1, fp) != 1)
1820 fprintf(stderr, "%s: unexpected EOF\n", rpms[i]);
1825 sat_chksum_add(chksumh, rpmhead->data, l);
1826 rpmhead->cnt = sigcnt;
1827 rpmhead->dcnt = sigdsize;
1828 rpmhead->dp = rpmhead->data + rpmhead->cnt * 16;
1829 if (headexists(rpmhead, TAG_PATCHESNAME))
1831 /* this is a patch rpm, ignore */
1835 payloadformat = headstring(rpmhead, TAG_PAYLOADFORMAT);
1836 if (payloadformat && !strcmp(payloadformat, "drpm"))
1838 /* this is a delta rpm */
1843 while ((l = fread(lead, 1, sizeof(lead), fp)) > 0)
1844 sat_chksum_add(chksumh, lead, l);
1846 s = pool_id2solvable(pool, repo_add_solvable(repo));
1847 rpm2solv(pool, repo, data, s, rpmhead, flags);
1850 Id handle = s - pool->solvables;
1851 repodata_set_location(data, handle, 0, 0, rpms[i]);
1852 if (S_ISREG(stb.st_mode))
1853 repodata_set_num(data, handle, SOLVABLE_DOWNLOADSIZE, (unsigned int)((stb.st_size + 1023) / 1024));
1854 repodata_set_num(data, handle, SOLVABLE_HEADEREND, headerend);
1856 repodata_set_bin_checksum(data, handle, SOLVABLE_PKGID, REPOKEY_TYPE_MD5, pkgid);
1858 repodata_set_bin_checksum(data, handle, SOLVABLE_CHECKSUM, chksumtype, sat_chksum_get(chksumh, 0));
1862 chksumh = sat_chksum_free(chksumh, 0);
1865 if (!(flags & REPO_NO_INTERNALIZE))
1866 repodata_internalize(data);
1870 linkhash(const char *lt, char *hash)
1873 const unsigned char *str = (const unsigned char *)lt;
1877 while ((c = *str++) != 0)
1879 sprintf(hash, "%08x", r);
1880 sprintf(hash + 8, "%08x", l);
1881 sprintf(hash + 16, "%08x", 0);
1882 sprintf(hash + 24, "%08x", 0);
1886 rpm_iterate_filelist(void *rpmhandle, int flags, void (*cb)(void *, const char *, int, const char *), void *cbdata)
1888 RpmHead *rpmhead = rpmhandle;
1893 unsigned int *di, diidx;
1894 unsigned int lastdir;
1897 int cnt, dcnt, cnt2;
1901 char md5[33], *md5p = 0;
1903 dn = headstringarray(rpmhead, TAG_DIRNAMES, &dcnt);
1906 if ((flags & RPM_ITERATE_FILELIST_ONLYDIRS) != 0)
1908 for (i = 0; i < dcnt; i++)
1909 (*cb)(cbdata, dn[i], 0, (char *)0);
1913 bn = headstringarray(rpmhead, TAG_BASENAMES, &cnt);
1919 di = headint32array(rpmhead, TAG_DIRINDEXES, &cnt2);
1920 if (!di || cnt != cnt2)
1927 fm = headint16array(rpmhead, TAG_FILEMODES, &cnt2);
1928 if (!fm || cnt != cnt2)
1936 if ((flags & RPM_ITERATE_FILELIST_WITHMD5) != 0)
1938 md = headstringarray(rpmhead, TAG_FILEMD5S, &cnt2);
1939 if (!md || cnt != cnt2)
1951 for (i = 0; i < cnt; i++)
1956 l1 = lastdir == diidx ? lastdirl : strlen(dn[diidx]);
1959 l = l1 + strlen(bn[i]) + 1;
1963 space = sat_realloc(space, spacen);
1965 if (lastdir != diidx)
1967 strcpy(space, dn[diidx]);
1971 strcpy(space + l1, bn[i]);
1980 lt = headstringarray(rpmhead, TAG_FILELINKTOS, &cnt2);
1986 linkhash(lt[i], md5);
1993 (*cb)(cbdata, space, fm[i], md5p);
2005 struct rpm_by_state {
2020 #define ENTRIES_BLOCK 255
2021 #define NAMEDATA_BLOCK 1023
2024 opendbenv(struct rpm_by_state *state, const char *rootdir)
2026 char dbpath[PATH_MAX];
2030 if (db_env_create(&state->dbenv, 0))
2032 perror("db_env_create");
2035 snprintf(dbpath, PATH_MAX, "%s/var/lib/rpm", rootdir ? rootdir : "");
2037 if (state->dbenv->open(state->dbenv, dbpath, DB_CREATE|DB_INIT_CDB|DB_INIT_MPOOL, 0))
2039 if (state->dbenv->open(state->dbenv, dbpath, DB_CREATE|DB_PRIVATE|DB_INIT_MPOOL, 0))
2042 perror("dbenv open");
2043 state->dbenv->close(state->dbenv, 0);
2049 #define FLAGS_GET_PUBKEYS 1
2052 getinstalledrpmdbids(struct rpm_by_state *state, int *nentriesp, char **namedatap, int flags)
2066 struct rpmdbentry *entries = 0;
2072 dbenv = state->dbenv;
2073 if (db_create(&db, dbenv, 0))
2075 perror("db_create");
2078 if (db->open(db, 0, "Name", 0, DB_UNKNOWN, DB_RDONLY, 0664))
2080 perror("db->open Name index");
2084 if (db->get_byteswapped(db, &byteswapped))
2086 perror("db->get_byteswapped");
2090 if (db->cursor(db, NULL, &dbc, 0))
2092 perror("db->cursor");
2096 memset(&dbkey, 0, sizeof(dbkey));
2097 memset(&dbdata, 0, sizeof(dbdata));
2098 while (dbc->c_get(dbc, &dbkey, &dbdata, DB_NEXT) == 0)
2100 if ((flags & FLAGS_GET_PUBKEYS))
2102 if (dbkey.size != 10 || memcmp(dbkey.data, "gpg-pubkey", 10))
2107 if (dbkey.size == 10 && !memcmp(dbkey.data, "gpg-pubkey", 10))
2116 ((char *)&rpmdbid)[0] = dp[3];
2117 ((char *)&rpmdbid)[1] = dp[2];
2118 ((char *)&rpmdbid)[2] = dp[1];
2119 ((char *)&rpmdbid)[3] = dp[0];
2122 memcpy((char *)&rpmdbid, dp, 4);
2123 entries = sat_extend(entries, nentries, 1, sizeof(*entries), ENTRIES_BLOCK);
2124 entries[nentries].rpmdbid = rpmdbid;
2125 entries[nentries].nameoff = namedatal;
2127 namedata = sat_extend(namedata, namedatal, dbkey.size + 1, 1, NAMEDATA_BLOCK);
2128 memcpy(namedata + namedatal, dbkey.data, dbkey.size);
2129 namedata[namedatal + dbkey.size] = 0;
2130 namedatal += dbkey.size + 1;
2137 *nentriesp = nentries;
2138 *namedatap = namedata;
2143 rpm_installedrpmdbids(const char *rootdir, Queue *rpmdbidq)
2145 struct rpm_by_state state;
2146 struct rpmdbentry *entries;
2151 queue_empty(rpmdbidq);
2152 memset(&state, 0, sizeof(state));
2153 if (!opendbenv(&state, rootdir))
2155 entries = getinstalledrpmdbids(&state, &nentries, &namedata, 0);
2157 for (i = 0; i < nentries; i++)
2158 queue_push(rpmdbidq, entries[i].rpmdbid);
2161 rpm_byrpmdbid(0, 0, (void **)&state);
2166 rpm_byrpmdbid(Id rpmdbid, const char *rootdir, void **statep)
2168 struct rpm_by_state *state = *statep;
2169 unsigned char buf[16];
2180 state->db->close(state->db, 0);
2182 state->dbenv->close(state->dbenv, 0);
2183 sat_free(state->rpmhead);
2185 *statep = (void *)0;
2191 state = sat_calloc(1, sizeof(*state));
2194 if (!state->dbopened)
2196 state->dbopened = 1;
2197 if (!opendbenv(state, rootdir))
2199 if (db_create(&state->db, state->dbenv, 0))
2201 perror("db_create");
2203 state->dbenv->close(state->dbenv, 0);
2207 if (state->db->open(state->db, 0, "Packages", 0, DB_UNKNOWN, DB_RDONLY, 0664))
2209 perror("db->open var/lib/rpm/Packages");
2210 state->db->close(state->db, 0);
2212 state->dbenv->close(state->dbenv, 0);
2216 if (state->db->get_byteswapped(state->db, &state->byteswapped))
2218 perror("db->get_byteswapped");
2219 state->db->close(state->db, 0);
2221 state->dbenv->close(state->dbenv, 0);
2226 memcpy(buf, &rpmdbid, 4);
2227 if (state->byteswapped)
2230 bx = buf[0]; buf[0] = buf[3]; buf[3] = bx;
2231 bx = buf[1]; buf[1] = buf[2]; buf[2] = bx;
2233 memset(&dbkey, 0, sizeof(dbkey));
2234 memset(&dbdata, 0, sizeof(dbdata));
2239 if (state->db->get(state->db, NULL, &dbkey, &dbdata, 0))
2244 if (dbdata.size < 8)
2246 fprintf(stderr, "corrupt rpm database (size)\n");
2249 if (dbdata.size > state->rpmheadsize)
2251 state->rpmheadsize = dbdata.size + 128;
2252 state->rpmhead = sat_realloc(state->rpmhead, sizeof(*rpmhead) + state->rpmheadsize);
2254 rpmhead = state->rpmhead;
2255 memcpy(buf, dbdata.data, 8);
2256 rpmhead->cnt = buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3];
2257 rpmhead->dcnt = buf[4] << 24 | buf[5] << 16 | buf[6] << 8 | buf[7];
2258 if (8 + rpmhead->cnt * 16 + rpmhead->dcnt > dbdata.size)
2260 fprintf(stderr, "corrupt rpm database (data size)\n");
2263 memcpy(rpmhead->data, (unsigned char *)dbdata.data + 8, rpmhead->cnt * 16 + rpmhead->dcnt);
2264 rpmhead->dp = rpmhead->data + rpmhead->cnt * 16;
2269 rpm_byfp(FILE *fp, const char *name, void **statep)
2271 struct rpm_by_state *state = *statep;
2272 int headerstart, headerend;
2274 int sigdsize, sigcnt, l;
2275 unsigned char lead[4096];
2278 return rpm_byrpmdbid(0, 0, statep);
2281 state = sat_calloc(1, sizeof(*state));
2284 if (fread(lead, 96 + 16, 1, fp) != 1 || getu32(lead) != 0xedabeedb)
2286 fprintf(stderr, "%s: not a rpm\n", name);
2289 if (lead[78] != 0 || lead[79] != 5)
2291 fprintf(stderr, "%s: not a V5 header\n", name);
2294 if (getu32(lead + 96) != 0x8eade801)
2296 fprintf(stderr, "%s: bad signature header\n", name);
2299 sigcnt = getu32(lead + 96 + 8);
2300 sigdsize = getu32(lead + 96 + 12);
2301 if (sigcnt >= 0x4000000 || sigdsize >= 0x40000000)
2303 fprintf(stderr, "%s: bad signature header\n", name);
2306 sigdsize += sigcnt * 16;
2307 sigdsize = (sigdsize + 7) & ~7;
2308 headerstart = 96 + 16 + sigdsize;
2311 l = sigdsize > 4096 ? 4096 : sigdsize;
2312 if (fread(lead, l, 1, fp) != 1)
2314 fprintf(stderr, "%s: unexpected EOF\n", name);
2319 if (fread(lead, 16, 1, fp) != 1)
2321 fprintf(stderr, "%s: unexpected EOF\n", name);
2324 if (getu32(lead) != 0x8eade801)
2326 fprintf(stderr, "%s: bad header\n", name);
2330 sigcnt = getu32(lead + 8);
2331 sigdsize = getu32(lead + 12);
2332 if (sigcnt >= 0x4000000 || sigdsize >= 0x40000000)
2334 fprintf(stderr, "%s: bad header\n", name);
2338 l = sigdsize + sigcnt * 16;
2339 headerend = headerstart + 16 + l;
2340 if (l > state->rpmheadsize)
2342 state->rpmheadsize = l + 128;
2343 state->rpmhead = sat_realloc(state->rpmhead, sizeof(*state->rpmhead) + state->rpmheadsize);
2345 rpmhead = state->rpmhead;
2346 if (fread(rpmhead->data, l, 1, fp) != 1)
2348 fprintf(stderr, "%s: unexpected EOF\n", name);
2352 rpmhead->cnt = sigcnt;
2353 rpmhead->dcnt = sigdsize;
2354 rpmhead->dp = rpmhead->data + rpmhead->cnt * 16;
2360 r64dec1(char *p, unsigned int *vp, int *eofp)
2365 for (i = 0; i < 4; )
2370 if (x >= 'A' && x <= 'Z')
2372 else if (x >= 'a' && x <= 'z')
2374 else if (x >= '0' && x <= '9')
2401 crc24(unsigned char *p, int len)
2403 unsigned int crc = 0xb704ceL;
2408 crc ^= (*p++) << 16;
2409 for (i = 0; i < 8; i++)
2410 if ((crc <<= 1) & 0x1000000)
2413 return crc & 0xffffffL;
2416 static unsigned char *
2417 unarmor(char *pubkey, int *pktlp)
2421 unsigned char *buf, *bp;
2425 while (strncmp(pubkey, "-----BEGIN PGP PUBLIC KEY BLOCK-----", 36) != 0)
2427 pubkey = strchr(pubkey, '\n');
2432 pubkey = strchr(pubkey, '\n');
2435 /* skip header lines */
2438 while (*pubkey == ' ' || *pubkey == '\t')
2440 if (*pubkey == '\n')
2442 pubkey = strchr(pubkey, '\n');
2447 p = strchr(pubkey, '=');
2451 bp = buf = sat_malloc(l * 3 / 4 + 4);
2455 pubkey = r64dec1(pubkey, &v, &eof);
2465 while (*pubkey == ' ' || *pubkey == '\t' || *pubkey == '\n' || *pubkey == '\r')
2468 if (*pubkey != '=' || (pubkey = r64dec1(pubkey + 1, &v, &eof)) == 0)
2473 if (v != crc24(buf, bp - buf))
2478 while (*pubkey == ' ' || *pubkey == '\t' || *pubkey == '\n' || *pubkey == '\r')
2480 if (strncmp(pubkey, "-----END PGP PUBLIC KEY BLOCK-----", 34) != 0)
2490 parsekeydata(Solvable *s, Repodata *data, unsigned char *p, int pl)
2493 unsigned char keyid[8];
2494 unsigned int kcr = 0, maxex = 0;
2495 unsigned char *pubkey = 0;
2497 unsigned char *userid = 0;
2500 for (; pl; p += l, pl -= l)
2504 if (!(x & 128) || pl <= 0)
2509 tag = (x & 0x3c) >> 2;
2531 else if (x >= 192 && x < 224)
2535 l = ((x - 192) << 8) + *p++ + 192;
2542 l = p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3];
2553 pubkey = sat_realloc(pubkey, l);
2555 memcpy(pubkey, p, l);
2562 kcr = p[1] << 24 | p[2] << 16 | p[3] << 8 | p[4];
2566 ex = kcr + 24*3600 * (p[5] << 8 | p[6]);
2570 memset(keyid, 0, 8);
2571 if (p[7] == 1) /* RSA */
2574 unsigned char fp[16];
2578 ql = ((p[8] << 8 | p[9]) + 7) / 8;
2579 memcpy(keyid, p + 10 + ql - 8, 8);
2580 h = sat_chksum_create(REPOKEY_TYPE_MD5);
2581 sat_chksum_add(h, p + 10, ql);
2583 ql = ((q[0] << 8 | q[1]) + 7) / 8;
2584 sat_chksum_add(h, q + 2, ql);
2585 sat_chksum_free(h, fp);
2586 for (i = 0; i < 16; i++)
2587 sprintf(fpx + i * 2, "%02x", fp[i]);
2588 setutf8string(data, s - s->repo->pool->solvables, PUBKEY_FINGERPRINT, fpx);
2595 unsigned char hdr[3];
2596 unsigned char fp[20];
2599 kcr = p[1] << 24 | p[2] << 16 | p[3] << 8 | p[4];
2603 h = sat_chksum_create(REPOKEY_TYPE_SHA1);
2604 sat_chksum_add(h, hdr, 3);
2605 sat_chksum_add(h, p, l);
2606 sat_chksum_free(h, fp);
2607 for (i = 0; i < 20; i++)
2608 sprintf(fpx + i * 2, "%02x", fp[i]);
2609 setutf8string(data, s - s->repo->pool->solvables, PUBKEY_FINGERPRINT, fpx);
2610 memcpy(keyid, fp + 12, 8);
2615 if (p[0] == 3 && p[1] == 5)
2620 // printf("V3 signature packet\n");
2621 if (p[2] != 0x10 && p[2] != 0x11 && p[2] != 0x12 && p[2] != 0x13 && p[2] != 0x1f)
2623 if (!memcmp(keyid, p + 6, 8))
2625 // printf("SELF SIG\n");
2629 // printf("OTHER SIG\n");
2633 htype = REPOKEY_TYPE_MD5;
2634 else if (p[16] == 2)
2635 htype = REPOKEY_TYPE_SHA1;
2636 else if (p[16] == 8)
2637 htype = REPOKEY_TYPE_SHA256;
2640 void *h = sat_chksum_create(htype);
2641 unsigned char b[3], *cs;
2644 b[1] = pubkeyl >> 8;
2646 sat_chksum_add(h, b, 3);
2647 sat_chksum_add(h, pubkey, pubkeyl);
2648 if (p[2] >= 0x10 && p[2] <= 0x13)
2649 sat_chksum_add(h, userid, useridl);
2650 sat_chksum_add(h, p + 2, 5);
2651 cs = sat_chksum_get(h, 0);
2652 sat_chksum_free(h, 0);
2658 int j, ql, haveissuer;
2660 unsigned int ex = 0, scr = 0;
2661 unsigned char issuer[8];
2663 // printf("V4 signature packet\n");
2664 if (p[1] != 0x10 && p[1] != 0x11 && p[1] != 0x12 && p[1] != 0x13 && p[1] != 0x1f)
2669 for (j = 0; q && j < 2; j++)
2671 ql = q[0] << 8 | q[1];
2687 sl = q[0] << 24 | q[1] << 16 | q[2] << 8 | q[3];
2698 sl = ((x - 192) << 8) + *q++ + 192;
2707 // printf("%d SIGSUB %d %d\n", j, x, sl);
2708 if (x == 16 && sl == 9 && !haveissuer)
2710 memcpy(issuer, q + 1, 8);
2713 if (x == 2 && j == 0)
2714 scr = q[1] << 24 | q[2] << 16 | q[3] << 8 | q[4];
2715 if (x == 9 && j == 0)
2716 ex = q[1] << 24 | q[2] << 16 | q[3] << 8 | q[4];
2728 htype = REPOKEY_TYPE_MD5;
2730 htype = REPOKEY_TYPE_SHA1;
2732 htype = REPOKEY_TYPE_SHA256;
2733 if (htype && pubkeyl)
2735 void *h = sat_chksum_create(htype);
2736 unsigned char b[6], *cs;
2740 b[1] = pubkeyl >> 8;
2742 sat_chksum_add(h, b, 3);
2743 sat_chksum_add(h, pubkey, pubkeyl);
2744 if (p[1] >= 0x10 && p[1] <= 0x13)
2747 b[1] = useridl >> 24;
2748 b[2] = useridl >> 16;
2749 b[3] = useridl >> 8;
2751 sat_chksum_add(h, b, 5);
2752 sat_chksum_add(h, userid, useridl);
2754 hl = 6 + (p[4] << 8 | p[5]);
2755 sat_chksum_add(h, p, hl);
2762 sat_chksum_add(h, b, 6);
2763 cs = sat_chksum_get(h, 0);
2764 sat_chksum_free(h, 0);
2767 if (!memcmp(keyid, issuer, 8))
2769 // printf("SELF SIG cr %d ex %d\n", cr, ex);
2775 // printf("OTHER SIG cr %d ex %d\n", cr, ex);
2782 userid = sat_realloc(userid, l);
2784 memcpy(userid, p, l);
2789 repodata_set_num(data, s - s->repo->pool->solvables, PUBKEY_EXPIRES, maxex);
2794 /* this is private to rpm, but rpm lacks an interface to retrieve
2795 * the values. Sigh. */
2796 struct pgpDigParams_s {
2797 const char * userid;
2799 const char * params[4];
2801 byte version; /*!< version number. */
2802 byte time[4]; /*!< time that the key was created. */
2803 byte pubkey_algo; /*!< public key algorithm. */
2813 struct pgpDigParams_s signature;
2814 struct pgpDigParams_s pubkey;
2818 pubkey2solvable(Solvable *s, Repodata *data, char *pubkey)
2820 Pool *pool = s->repo->pool;
2821 unsigned char *pkts;
2826 char evrbuf[8 + 1 + 8 + 1];
2828 pkts = unarmor(pubkey, &pktsl);
2831 setutf8string(data, s - s->repo->pool->solvables, SOLVABLE_DESCRIPTION, pubkey);
2832 parsekeydata(s, data, pkts, pktsl);
2834 (void) pgpPrtPkts(pkts, pktsl, dig, 0);
2835 btime = dig->pubkey.time[0] << 24 | dig->pubkey.time[1] << 16 | dig->pubkey.time[2] << 8 | dig->pubkey.signid[3];
2836 sprintf(evrbuf, "%02x%02x%02x%02x-%02x%02x%02x%02x", dig->pubkey.signid[4], dig->pubkey.signid[5], dig->pubkey.signid[6], dig->pubkey.signid[7], dig->pubkey.time[0], dig->pubkey.time[1], dig->pubkey.time[2], dig->pubkey.time[3]);
2837 repodata_set_num(data, s - s->repo->pool->solvables, SOLVABLE_BUILDTIME, btime);
2838 s->name = str2id(pool, "gpg-pubkey", 1);
2839 s->evr = str2id(pool, evrbuf, 1);
2841 for (i = 0; i < 8; i++)
2842 sprintf(keyid + 2 * i, "%02x", dig->pubkey.signid[i]);
2843 repodata_set_str(data, s - s->repo->pool->solvables, PUBKEY_KEYID, keyid);
2844 if (dig->pubkey.userid)
2845 setutf8string(data, s - s->repo->pool->solvables, SOLVABLE_SUMMARY, dig->pubkey.userid);
2847 sat_free((void *)pkts);
2852 repo_add_rpmdb_pubkeys(Repo *repo, const char *rootdir, int flags)
2854 Pool *pool = repo->pool;
2855 struct rpm_by_state state;
2856 struct rpmdbentry *entries;
2858 char *namedata, *str;
2863 if (!(flags & REPO_REUSE_REPODATA))
2864 data = repo_add_repodata(repo, 0);
2866 data = repo_last_repodata(repo);
2868 memset(&state, 0, sizeof(state));
2869 if (!opendbenv(&state, rootdir))
2871 entries = getinstalledrpmdbids(&state, &nentries, &namedata, FLAGS_GET_PUBKEYS);
2872 for (i = 0 ; i < nentries; i++)
2874 RpmHead *rpmhead = rpm_byrpmdbid(entries[i].rpmdbid, rootdir, (void **)&state);
2877 str = headstring(rpmhead, TAG_DESCRIPTION);
2880 s = pool_id2solvable(pool, repo_add_solvable(repo));
2881 pubkey2solvable(s, data, str);
2882 u32 = headint32(rpmhead, TAG_INSTALLTIME);
2884 repodata_set_num(data, s - pool->solvables, SOLVABLE_INSTALLTIME, u32);
2886 repo->rpmdbid = repo_sidedata_create(repo, sizeof(Id));
2887 repo->rpmdbid[s - pool->solvables - repo->start] = entries[i].rpmdbid;
2889 rpm_byrpmdbid(0, 0, (void **)&state);
2890 if (!(flags & REPO_NO_INTERNALIZE))
2891 repodata_internalize(data);
2895 repo_add_pubkeys(Repo *repo, const char **keys, int nkeys, int flags)
2897 Pool *pool = repo->pool;
2904 if (!(flags & REPO_REUSE_REPODATA))
2905 data = repo_add_repodata(repo, 0);
2907 data = repo_last_repodata(repo);
2910 for (i = 0; i < nkeys; i++)
2912 if ((fp = fopen(keys[i], "r")) == 0)
2919 if (bufl - l < 4096)
2921 buf = sat_realloc(buf, bufl + 4096);
2924 ll = fread(buf, 1, bufl - l, fp);
2930 s = pool_id2solvable(pool, repo_add_solvable(repo));
2931 pubkey2solvable(s, data, buf);