2 * Copyright (c) 2007-2012, 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>
27 #include <rpm/rpmio.h>
28 #include <rpm/rpmpgp.h>
30 #include <rpm/header.h>
32 #include <rpm/rpmdb.h>
35 # if defined(SUSE) || defined(HAVE_RPM_DB_H)
48 #include "repo_rpmdb.h"
49 #include "repo_solv.h"
51 /* 3: added triggers */
52 /* 4: fixed triggers */
53 /* 5: fixed checksum copying */
54 #define RPMDB_COOKIE_VERSION 5
57 #define TAG_VERSION 1001
58 #define TAG_RELEASE 1002
59 #define TAG_EPOCH 1003
60 #define TAG_SUMMARY 1004
61 #define TAG_DESCRIPTION 1005
62 #define TAG_BUILDTIME 1006
63 #define TAG_BUILDHOST 1007
64 #define TAG_INSTALLTIME 1008
66 #define TAG_DISTRIBUTION 1010
67 #define TAG_VENDOR 1011
68 #define TAG_LICENSE 1014
69 #define TAG_PACKAGER 1015
70 #define TAG_GROUP 1016
73 #define TAG_FILESIZES 1028
74 #define TAG_FILEMODES 1030
75 #define TAG_FILEMD5S 1035
76 #define TAG_FILELINKTOS 1036
77 #define TAG_FILEFLAGS 1037
78 #define TAG_SOURCERPM 1044
79 #define TAG_PROVIDENAME 1047
80 #define TAG_REQUIREFLAGS 1048
81 #define TAG_REQUIRENAME 1049
82 #define TAG_REQUIREVERSION 1050
83 #define TAG_NOSOURCE 1051
84 #define TAG_NOPATCH 1052
85 #define TAG_CONFLICTFLAGS 1053
86 #define TAG_CONFLICTNAME 1054
87 #define TAG_CONFLICTVERSION 1055
88 #define TAG_TRIGGERNAME 1066
89 #define TAG_TRIGGERVERSION 1067
90 #define TAG_TRIGGERFLAGS 1068
91 #define TAG_CHANGELOGTIME 1080
92 #define TAG_CHANGELOGNAME 1081
93 #define TAG_CHANGELOGTEXT 1082
94 #define TAG_OBSOLETENAME 1090
95 #define TAG_FILEDEVICES 1095
96 #define TAG_FILEINODES 1096
97 #define TAG_SOURCEPACKAGE 1106
98 #define TAG_PROVIDEFLAGS 1112
99 #define TAG_PROVIDEVERSION 1113
100 #define TAG_OBSOLETEFLAGS 1114
101 #define TAG_OBSOLETEVERSION 1115
102 #define TAG_DIRINDEXES 1116
103 #define TAG_BASENAMES 1117
104 #define TAG_DIRNAMES 1118
105 #define TAG_PAYLOADFORMAT 1124
106 #define TAG_PATCHESNAME 1133
107 #define TAG_FILECOLORS 1140
108 #define TAG_SUGGESTSNAME 1156
109 #define TAG_SUGGESTSVERSION 1157
110 #define TAG_SUGGESTSFLAGS 1158
111 #define TAG_ENHANCESNAME 1159
112 #define TAG_ENHANCESVERSION 1160
113 #define TAG_ENHANCESFLAGS 1161
116 #define TAG_DISTEPOCH 1218
119 #define TAG_LONGFILESIZES 5008
120 #define TAG_LONGSIZE 5009
123 #define TAG_SIGBASE 256
124 #define TAG_SIGMD5 (TAG_SIGBASE + 5)
125 #define TAG_SHA1HEADER (TAG_SIGBASE + 13)
127 #define SIGTAG_SIZE 1000
128 #define SIGTAG_PGP 1002 /* RSA signature */
129 #define SIGTAG_MD5 1004 /* header+payload md5 checksum */
130 #define SIGTAG_GPG 1005 /* DSA signature */
132 #define DEP_LESS (1 << 1)
133 #define DEP_GREATER (1 << 2)
134 #define DEP_EQUAL (1 << 3)
135 #define DEP_STRONG (1 << 27)
136 #define DEP_PRE_IN ((1 << 6) | (1 << 9) | (1 << 10))
137 #define DEP_PRE_UN ((1 << 6) | (1 << 11) | (1 << 12))
139 #define FILEFLAG_GHOST (1 << 6)
143 # define RPM_INDEX_SIZE 4
145 # define RPM_INDEX_SIZE 8
149 typedef struct rpmhead {
153 int forcebinary; /* sigh, see rh#478907 */
154 unsigned char data[1];
158 static inline unsigned char *
159 headfindtag(RpmHead *h, int tag)
162 unsigned char *d, taga[4];
168 for (i = 0; i < h->cnt; i++, d -= 16)
169 if (d[3] == taga[3] && d[2] == taga[2] && d[1] == taga[1] && d[0] == taga[0])
175 headexists(RpmHead *h, int tag)
177 return headfindtag(h, tag) ? 1 : 0;
180 static unsigned int *
181 headint32array(RpmHead *h, int tag, int *cnt)
183 unsigned int i, o, *r;
184 unsigned char *d = headfindtag(h, tag);
186 if (!d || d[4] != 0 || d[5] != 0 || d[6] != 0 || d[7] != 4)
188 o = d[8] << 24 | d[9] << 16 | d[10] << 8 | d[11];
189 i = d[12] << 24 | d[13] << 16 | d[14] << 8 | d[15];
190 if (o + 4 * i > h->dcnt)
193 r = solv_calloc(i ? i : 1, sizeof(unsigned int));
196 for (o = 0; o < i; o++, d += 4)
197 r[o] = d[0] << 24 | d[1] << 16 | d[2] << 8 | d[3];
201 /* returns the first entry of an integer array */
203 headint32(RpmHead *h, int tag)
206 unsigned char *d = headfindtag(h, tag);
208 if (!d || d[4] != 0 || d[5] != 0 || d[6] != 0 || d[7] != 4)
210 o = d[8] << 24 | d[9] << 16 | d[10] << 8 | d[11];
211 i = d[12] << 24 | d[13] << 16 | d[14] << 8 | d[15];
212 if (i == 0 || o + 4 * i > h->dcnt)
215 return d[0] << 24 | d[1] << 16 | d[2] << 8 | d[3];
218 static unsigned long long *
219 headint64array(RpmHead *h, int tag, int *cnt)
222 unsigned long long *r;
223 unsigned char *d = headfindtag(h, tag);
225 if (!d || d[4] != 0 || d[5] != 0 || d[6] != 0 || d[7] != 5)
227 o = d[8] << 24 | d[9] << 16 | d[10] << 8 | d[11];
228 i = d[12] << 24 | d[13] << 16 | d[14] << 8 | d[15];
229 if (o + 8 * i > h->dcnt)
232 r = solv_calloc(i ? i : 1, sizeof(unsigned long long));
235 for (o = 0; o < i; o++, d += 8)
237 unsigned int x = d[0] << 24 | d[1] << 16 | d[2] << 8 | d[3];
238 r[o] = (unsigned long long)x << 32 | (d[4] << 24 | d[5] << 16 | d[6] << 8 | d[7]);
243 /* returns the first entry of an 64bit integer array */
244 static unsigned long long
245 headint64(RpmHead *h, int tag)
248 unsigned char *d = headfindtag(h, tag);
249 if (!d || d[4] != 0 || d[5] != 0 || d[6] != 0 || d[7] != 5)
251 o = d[8] << 24 | d[9] << 16 | d[10] << 8 | d[11];
252 i = d[12] << 24 | d[13] << 16 | d[14] << 8 | d[15];
253 if (i == 0 || o + 8 * i > h->dcnt)
256 i = d[0] << 24 | d[1] << 16 | d[2] << 8 | d[3];
257 return (unsigned long long)i << 32 | (d[4] << 24 | d[5] << 16 | d[6] << 8 | d[7]);
260 static unsigned int *
261 headint16array(RpmHead *h, int tag, int *cnt)
263 unsigned int i, o, *r;
264 unsigned char *d = headfindtag(h, tag);
266 if (!d || d[4] != 0 || d[5] != 0 || d[6] != 0 || d[7] != 3)
268 o = d[8] << 24 | d[9] << 16 | d[10] << 8 | d[11];
269 i = d[12] << 24 | d[13] << 16 | d[14] << 8 | d[15];
270 if (o + 4 * i > h->dcnt)
273 r = solv_calloc(i ? i : 1, sizeof(unsigned int));
276 for (o = 0; o < i; o++, d += 2)
277 r[o] = d[0] << 8 | d[1];
282 headstring(RpmHead *h, int tag)
285 unsigned char *d = headfindtag(h, tag);
286 /* 6: STRING, 9: I18NSTRING */
287 if (!d || d[4] != 0 || d[5] != 0 || d[6] != 0 || (d[7] != 6 && d[7] != 9))
289 o = d[8] << 24 | d[9] << 16 | d[10] << 8 | d[11];
292 return (char *)h->dp + o;
296 headstringarray(RpmHead *h, int tag, int *cnt)
299 unsigned char *d = headfindtag(h, tag);
302 if (!d || d[4] != 0 || d[5] != 0 || d[6] != 0 || d[7] != 8)
304 o = d[8] << 24 | d[9] << 16 | d[10] << 8 | d[11];
305 i = d[12] << 24 | d[13] << 16 | d[14] << 8 | d[15];
306 r = solv_calloc(i ? i : 1, sizeof(char *));
310 for (o = 0; o < i; o++)
314 d += strlen((char *)d) + 1;
315 if (d >= h->dp + h->dcnt)
324 static unsigned char *
325 headbinary(RpmHead *h, int tag, unsigned int *sizep)
328 unsigned char *d = headfindtag(h, tag);
329 if (!d || d[4] != 0 || d[5] != 0 || d[6] != 0 || d[7] != 7)
331 o = d[8] << 24 | d[9] << 16 | d[10] << 8 | d[11];
332 i = d[12] << 24 | d[13] << 16 | d[14] << 8 | d[15];
333 if (o > h->dcnt || o + i < o || o + i > h->dcnt)
340 static char *headtoevr(RpmHead *h)
348 version = headstring(h, TAG_VERSION);
349 release = headstring(h, TAG_RELEASE);
350 epoch = headint32(h, TAG_EPOCH);
351 if (!version || !release)
353 fprintf(stderr, "headtoevr: bad rpm header\n");
356 for (v = version; *v >= '0' && *v <= '9'; v++)
358 if (epoch || (v != version && *v == ':'))
360 char epochbuf[11]; /* 32bit decimal will fit in */
361 sprintf(epochbuf, "%u", epoch);
362 evr = solv_malloc(strlen(epochbuf) + 1 + strlen(version) + 1 + strlen(release) + 1);
363 sprintf(evr, "%s:%s-%s", epochbuf, version, release);
367 evr = solv_malloc(strlen(version) + 1 + strlen(release) + 1);
368 sprintf(evr, "%s-%s", version, release);
370 distepoch = headstring(h, TAG_DISTEPOCH);
371 if (distepoch && *distepoch)
374 evr = solv_realloc(evr, l + strlen(distepoch) + 2);
376 strcpy(evr + l, distepoch);
383 setutf8string(Repodata *repodata, Id handle, Id tag, const char *str)
385 if (str[solv_validutf8(str)])
387 char *ustr = solv_latin1toutf8(str); /* not utf8, assume latin1 */
388 repodata_set_str(repodata, handle, tag, ustr);
392 repodata_set_str(repodata, handle, tag, str);
396 #define MAKEDEPS_FILTER_WEAK (1 << 0)
397 #define MAKEDEPS_FILTER_STRONG (1 << 1)
398 #define MAKEDEPS_NO_RPMLIB (1 << 2)
401 * strong: 0: ignore strongness
402 * 1: filter to strong
406 makedeps(Pool *pool, Repo *repo, RpmHead *rpmhead, int tagn, int tagv, int tagf, int flags)
410 int i, cc, nc, vc, fc;
412 unsigned int olddeps;
416 strong = flags & (MAKEDEPS_FILTER_STRONG|MAKEDEPS_FILTER_WEAK);
417 n = headstringarray(rpmhead, tagn, &nc);
421 v = headstringarray(rpmhead, tagv, &vc);
422 f = headint32array(rpmhead, tagf, &fc);
423 if (!v || !f || nc != vc || nc != fc)
425 char *pkgname = rpm_query(rpmhead, 0);
426 pool_error(pool, 0, "bad dependency entries for %s: %d %d %d", pkgname ? pkgname : "<NULL>", nc, vc, fc);
435 haspre = 0; /* add no prereq marker */
436 premask = DEP_PRE_IN | DEP_PRE_UN;
439 /* we do filtering */
441 for (i = 0; i < nc; i++)
443 if (strong && (f[i] & DEP_STRONG) != (strong == MAKEDEPS_FILTER_WEAK ? 0 : DEP_STRONG))
445 if ((flags & MAKEDEPS_NO_RPMLIB) != 0)
446 if (!strncmp(n[i], "rpmlib(", 7))
448 if ((f[i] & premask) != 0)
453 else if (tagn == TAG_REQUIRENAME)
455 /* no filtering, just look for the first prereq */
456 for (i = 0; i < nc; i++)
457 if ((f[i] & premask) != 0)
470 cc += haspre; /* add slot for the prereq marker */
471 olddeps = repo_reserve_ids(repo, 0, cc);
472 ida = repo->idarraydata + olddeps;
479 haspre = 2; /* pass two: prereqs */
481 *ida++ = SOLVABLE_PREREQMARKER;
483 if (strong && (f[i] & DEP_STRONG) != (strong == MAKEDEPS_FILTER_WEAK ? 0 : DEP_STRONG))
485 if (haspre == 1 && (f[i] & premask) != 0)
487 if (haspre == 2 && (f[i] & premask) == 0)
489 if ((flags & MAKEDEPS_NO_RPMLIB) != 0)
490 if (!strncmp(n[i], "rpmlib(", 7))
492 if (f[i] & (DEP_LESS|DEP_GREATER|DEP_EQUAL))
496 if ((f[i] & DEP_LESS) != 0)
498 if ((f[i] & DEP_EQUAL) != 0)
500 if ((f[i] & DEP_GREATER) != 0)
502 name = pool_str2id(pool, n[i], 1);
503 if (v[i][0] == '0' && v[i][1] == ':' && v[i][2])
504 evr = pool_str2id(pool, v[i] + 2, 1);
506 evr = pool_str2id(pool, v[i], 1);
507 *ida++ = pool_rel2id(pool, name, evr, flags, 1);
510 *ida++ = pool_str2id(pool, n[i], 1);
513 repo->idarraysize += cc + 1;
522 adddudata(Repodata *data, Id handle, RpmHead *rpmhead, char **dn, unsigned int *di, int fc, int dc)
526 unsigned int *fkb, *fn, *fsz, *fm, *fino;
527 unsigned long long *fsz64;
528 unsigned int inotest[256], inotestok;
532 if ((fsz64 = headint64array(rpmhead, TAG_LONGFILESIZES, &fszc)) != 0)
534 /* convert to kbyte */
535 fsz = solv_malloc2(fszc, sizeof(*fsz));
536 for (i = 0; i < fszc; i++)
537 fsz[i] = fsz64[i] ? fsz64[i] / 1024 + 1 : 0;
540 else if ((fsz = headint32array(rpmhead, TAG_FILESIZES, &fszc)) != 0)
542 /* convert to kbyte */
543 for (i = 0; i < fszc; i++)
545 fsz[i] = fsz[i] / 1024 + 1;
555 /* stupid rpm records sizes of directories, so we have to check the mode */
556 fm = headint16array(rpmhead, TAG_FILEMODES, &fszc);
557 if (!fm || fc != fszc)
563 fino = headint32array(rpmhead, TAG_FILEINODES, &fszc);
564 if (!fino || fc != fszc)
572 /* kill hardlinked entries */
574 if (fc < sizeof(inotest))
576 /* quick test just hashing the inode numbers */
577 memset(inotest, 0, sizeof(inotest));
578 for (i = 0; i < fc; i++)
581 if (fsz[i] == 0 || !S_ISREG(fm[i]))
582 continue; /* does not matter */
583 off = (fino[i] >> 5) & (sizeof(inotest)/sizeof(*inotest) - 1);
584 bit = 1 << (fino[i] & 31);
585 if ((inotest[off] & bit) != 0)
590 inotestok = 1; /* no conflict found */
594 /* hardlinked files are possible, check ino/dev pairs */
595 unsigned int *fdev = headint32array(rpmhead, TAG_FILEDEVICES, &fszc);
597 unsigned int mask, hash, hh;
598 if (!fdev || fc != fszc)
607 while ((mask & (mask - 1)) != 0)
608 mask = mask & (mask - 1);
610 if (mask > sizeof(inotest)/sizeof(*inotest))
611 fx = solv_calloc(mask, sizeof(unsigned int));
615 memset(fx, 0, mask * sizeof(unsigned int));
618 for (i = 0; i < fc; i++)
620 if (fsz[i] == 0 || !S_ISREG(fm[i]))
622 hash = (fino[i] + fdev[i] * 31) & mask;
624 while ((j = fx[hash]) != 0)
626 if (fino[j - 1] == fino[i] && fdev[j - 1] == fdev[i])
628 fsz[i] = 0; /* kill entry */
631 hash = (hash + hh++) & mask;
642 /* sum up inode count and kbytes for each directory */
643 fn = solv_calloc(dc, sizeof(unsigned int));
644 fkb = solv_calloc(dc, sizeof(unsigned int));
645 for (i = 0; i < fc; i++)
648 continue; /* corrupt entry */
650 if (fsz[i] == 0 || !S_ISREG(fm[i]))
652 fkb[di[i]] += fsz[i];
657 for (i = 0; i < dc; i++)
663 Solvable *s = data->repo->pool->solvables + handle;
664 if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
665 did = repodata_str2dir(data, "/usr/src", 1);
667 continue; /* work around rpm bug */
670 did = repodata_str2dir(data, dn[i], 1);
671 repodata_add_dirnumnum(data, handle, SOLVABLE_DISKUSAGE, did, fkb[i], fn[i]);
678 addfilelist(Repodata *data, Id handle, RpmHead *rpmhead)
686 unsigned int lastdii = -1;
690 bn = headstringarray(rpmhead, TAG_BASENAMES, &bnc);
693 dn = headstringarray(rpmhead, TAG_DIRNAMES, &dnc);
699 di = headint32array(rpmhead, TAG_DIRINDEXES, &dic);
708 pool_error(data->repo->pool, 0, "bad filelist");
712 adddudata(data, handle, rpmhead, dn, di, bnc, dnc);
714 for (i = 0; i < bnc; i++)
719 if (di[i] == lastdii)
724 continue; /* corrupt entry */
725 did = repodata_str2dir(data, dn[di[i]], 1);
727 did = repodata_str2dir(data, "/", 1);
731 if (b && *b == '/') /* work around rpm bug */
733 repodata_add_dirstr(data, handle, SOLVABLE_FILELIST, did, b);
741 addchangelog(Repodata *data, Id handle, RpmHead *rpmhead)
746 int i, cnc, cxc, ctc;
749 ct = headint32array(rpmhead, TAG_CHANGELOGTIME, &ctc);
750 cx = headstringarray(rpmhead, TAG_CHANGELOGTEXT, &cxc);
751 cn = headstringarray(rpmhead, TAG_CHANGELOGNAME, &cnc);
752 if (!ct || !cx || !cn || !ctc || ctc != cxc || ctc != cnc)
760 for (i = 0; i < ctc; i++)
762 Id h = repodata_new_handle(data);
764 repodata_set_num(data, h, SOLVABLE_CHANGELOG_TIME, ct[i]);
766 setutf8string(data, h, SOLVABLE_CHANGELOG_AUTHOR, cn[i]);
768 setutf8string(data, h, SOLVABLE_CHANGELOG_TEXT, cx[i]);
771 for (i = 0; i < hq.count; i++)
772 repodata_add_flexarray(data, handle, SOLVABLE_CHANGELOG, hq.elements[i]);
780 set_description_author(Repodata *data, Id handle, char *str)
783 for (aut = str; (aut = strchr(aut, '\n')) != 0; aut++)
784 if (!strncmp(aut, "\nAuthors:\n--------\n", 19))
788 /* oh my, found SUSE special author section */
790 str = solv_strdup(str);
793 while (l > 0 && str[l - 1] == '\n')
796 setutf8string(data, handle, SOLVABLE_DESCRIPTION, str);
798 aut = str; /* copy over */
799 while (*p == ' ' || *p == '\n')
812 while (aut != str && aut[-1] == '\n')
816 setutf8string(data, handle, SOLVABLE_AUTHORS, str);
820 setutf8string(data, handle, SOLVABLE_DESCRIPTION, str);
824 rpm2solv(Pool *pool, Repo *repo, Repodata *data, Solvable *s, RpmHead *rpmhead, int flags)
830 name = headstring(rpmhead, TAG_NAME);
833 pool_error(pool, 0, "package has no name");
836 if (!strcmp(name, "gpg-pubkey"))
838 s->name = pool_str2id(pool, name, 1);
839 sourcerpm = headstring(rpmhead, TAG_SOURCERPM);
840 if (sourcerpm || (rpmhead->forcebinary && !headexists(rpmhead, TAG_SOURCEPACKAGE)))
841 s->arch = pool_str2id(pool, headstring(rpmhead, TAG_ARCH), 1);
844 if (headexists(rpmhead, TAG_NOSOURCE) || headexists(rpmhead, TAG_NOPATCH))
845 s->arch = ARCH_NOSRC;
850 s->arch = ARCH_NOARCH;
851 evr = headtoevr(rpmhead);
852 s->evr = pool_str2id(pool, evr, 1);
853 s->vendor = pool_str2id(pool, headstring(rpmhead, TAG_VENDOR), 1);
855 s->provides = makedeps(pool, repo, rpmhead, TAG_PROVIDENAME, TAG_PROVIDEVERSION, TAG_PROVIDEFLAGS, 0);
856 if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
857 s->provides = repo_addid_dep(repo, s->provides, pool_rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
858 s->requires = makedeps(pool, repo, rpmhead, TAG_REQUIRENAME, TAG_REQUIREVERSION, TAG_REQUIREFLAGS, (flags & RPM_ADD_NO_RPMLIBREQS) ? MAKEDEPS_NO_RPMLIB : 0);
859 s->conflicts = makedeps(pool, repo, rpmhead, TAG_CONFLICTNAME, TAG_CONFLICTVERSION, TAG_CONFLICTFLAGS, 0);
860 s->obsoletes = makedeps(pool, repo, rpmhead, TAG_OBSOLETENAME, TAG_OBSOLETEVERSION, TAG_OBSOLETEFLAGS, 0);
862 s->recommends = makedeps(pool, repo, rpmhead, TAG_SUGGESTSNAME, TAG_SUGGESTSVERSION, TAG_SUGGESTSFLAGS, MAKEDEPS_FILTER_STRONG);
863 s->suggests = makedeps(pool, repo, rpmhead, TAG_SUGGESTSNAME, TAG_SUGGESTSVERSION, TAG_SUGGESTSFLAGS, MAKEDEPS_FILTER_WEAK);
864 s->supplements = makedeps(pool, repo, rpmhead, TAG_ENHANCESNAME, TAG_ENHANCESVERSION, TAG_ENHANCESFLAGS, MAKEDEPS_FILTER_STRONG);
865 s->enhances = makedeps(pool, repo, rpmhead, TAG_ENHANCESNAME, TAG_ENHANCESVERSION, TAG_ENHANCESFLAGS, MAKEDEPS_FILTER_WEAK);
866 s->supplements = repo_fix_supplements(repo, s->provides, s->supplements, 0);
867 s->conflicts = repo_fix_conflicts(repo, s->conflicts);
874 unsigned long long u64;
876 handle = s - pool->solvables;
877 str = headstring(rpmhead, TAG_SUMMARY);
879 setutf8string(data, handle, SOLVABLE_SUMMARY, str);
880 str = headstring(rpmhead, TAG_DESCRIPTION);
882 set_description_author(data, handle, str);
883 str = headstring(rpmhead, TAG_GROUP);
885 repodata_set_poolstr(data, handle, SOLVABLE_GROUP, str);
886 str = headstring(rpmhead, TAG_LICENSE);
888 repodata_set_poolstr(data, handle, SOLVABLE_LICENSE, str);
889 str = headstring(rpmhead, TAG_URL);
891 repodata_set_str(data, handle, SOLVABLE_URL, str);
892 str = headstring(rpmhead, TAG_DISTRIBUTION);
894 repodata_set_poolstr(data, handle, SOLVABLE_DISTRIBUTION, str);
895 str = headstring(rpmhead, TAG_PACKAGER);
897 repodata_set_poolstr(data, handle, SOLVABLE_PACKAGER, str);
898 if ((flags & RPM_ADD_WITH_PKGID) != 0)
900 unsigned char *chksum;
901 unsigned int chksumsize;
902 chksum = headbinary(rpmhead, TAG_SIGMD5, &chksumsize);
903 if (chksum && chksumsize == 16)
904 repodata_set_bin_checksum(data, handle, SOLVABLE_PKGID, REPOKEY_TYPE_MD5, chksum);
906 if ((flags & RPM_ADD_WITH_HDRID) != 0)
908 str = headstring(rpmhead, TAG_SHA1HEADER);
909 if (str && strlen(str) == 40)
910 repodata_set_checksum(data, handle, SOLVABLE_HDRID, REPOKEY_TYPE_SHA1, str);
911 else if (str && strlen(str) == 64)
912 repodata_set_checksum(data, handle, SOLVABLE_HDRID, REPOKEY_TYPE_SHA256, str);
914 u32 = headint32(rpmhead, TAG_BUILDTIME);
916 repodata_set_num(data, handle, SOLVABLE_BUILDTIME, u32);
917 u32 = headint32(rpmhead, TAG_INSTALLTIME);
919 repodata_set_num(data, handle, SOLVABLE_INSTALLTIME, u32);
920 u64 = headint64(rpmhead, TAG_LONGSIZE);
922 repodata_set_num(data, handle, SOLVABLE_INSTALLSIZE, u64);
925 u32 = headint32(rpmhead, TAG_SIZE);
927 repodata_set_num(data, handle, SOLVABLE_INSTALLSIZE, u32);
930 repodata_set_sourcepkg(data, handle, sourcerpm);
931 if ((flags & RPM_ADD_TRIGGERS) != 0)
934 unsigned int ida = makedeps(pool, repo, rpmhead, TAG_TRIGGERNAME, TAG_TRIGGERVERSION, TAG_TRIGGERFLAGS, 0);
937 for (; (id = repo->idarraydata[ida]) != 0; ida++)
939 /* we currently do not support rel ids in incore data, so
940 * strip off versioning information */
943 Reldep *rd = GETRELDEP(pool, id);
948 repodata_add_idarray(data, handle, SOLVABLE_TRIGGERS, id);
952 if ((flags & RPM_ADD_NO_FILELIST) == 0)
953 addfilelist(data, handle, rpmhead);
954 if ((flags & RPM_ADD_WITH_CHANGELOG) != 0)
955 addchangelog(data, handle, rpmhead);
962 /******************************************************************/
963 /* Rpm Database stuff
970 RpmHead *rpmhead; /* header storage space */
974 DB_ENV *dbenv; /* database environment */
975 DB *db; /* packages database */
976 int byteswapped; /* endianess of packages database */
984 #define ENTRIES_BLOCK 255
985 #define NAMEDATA_BLOCK 1023
988 static inline Id db2rpmdbid(unsigned char *db, int byteswapped)
991 return db[0] << 24 | db[1] << 16 | db[2] << 8 | db[3];
993 # if defined(WORDS_BIGENDIAN)
998 return db[0] << 24 | db[1] << 16 | db[2] << 8 | db[3];
1000 return db[3] << 24 | db[2] << 16 | db[1] << 8 | db[0];
1004 static inline void rpmdbid2db(unsigned char *db, Id id, int byteswapped)
1007 db[0] = id >> 24, db[1] = id >> 16, db[2] = id >> 8, db[3] = id;
1009 # if defined(WORDS_BIGENDIAN)
1014 db[0] = id >> 24, db[1] = id >> 16, db[2] = id >> 8, db[3] = id;
1016 db[3] = id >> 24, db[2] = id >> 16, db[1] = id >> 8, db[0] = id;
1022 serialize_dbenv_ops(struct rpmdbstate *state)
1024 char lpath[PATH_MAX];
1025 mode_t oldmask = umask(022);
1029 snprintf(lpath, PATH_MAX, "%s/var/lib/rpm/.dbenv.lock", state->rootdir ? state->rootdir : "");
1030 fd = open(lpath, (O_RDWR|O_CREAT), 0644);
1034 memset(&fl, 0, sizeof(fl));
1035 fl.l_type = F_WRLCK;
1036 fl.l_whence = SEEK_SET;
1039 if (fcntl(fd, F_SETLKW, &fl) != -1)
1049 /* should look in /usr/lib/rpm/macros instead, but we want speed... */
1051 opendbenv(struct rpmdbstate *state)
1053 const char *rootdir = state->rootdir;
1054 char dbpath[PATH_MAX];
1058 if (db_env_create(&dbenv, 0))
1059 return pool_error(state->pool, 0, "db_env_create: %s", strerror(errno));
1060 #if defined(FEDORA) && (DB_VERSION_MAJOR >= 5 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 5))
1061 dbenv->set_thread_count(dbenv, 8);
1063 snprintf(dbpath, PATH_MAX, "%s/var/lib/rpm", rootdir ? rootdir : "");
1064 if (access(dbpath, W_OK) == -1)
1066 r = dbenv->open(dbenv, dbpath, DB_CREATE|DB_PRIVATE|DB_INIT_MPOOL, 0);
1071 int serialize_fd = serialize_dbenv_ops(state);
1072 r = dbenv->open(dbenv, dbpath, DB_CREATE|DB_INIT_CDB|DB_INIT_MPOOL, 0644);
1073 if (serialize_fd >= 0)
1074 close(serialize_fd);
1076 r = dbenv->open(dbenv, dbpath, DB_CREATE|DB_PRIVATE|DB_INIT_MPOOL, 0);
1081 pool_error(state->pool, 0, "dbenv->open: %s", strerror(errno));
1082 dbenv->close(dbenv, 0);
1085 state->dbenv = dbenv;
1090 closedbenv(struct rpmdbstate *state)
1093 uint32_t eflags = 0;
1099 (void)state->dbenv->get_open_flags(state->dbenv, &eflags);
1100 if (!(eflags & DB_PRIVATE))
1102 int serialize_fd = serialize_dbenv_ops(state);
1103 state->dbenv->close(state->dbenv, 0);
1104 if (serialize_fd >= 0)
1105 close(serialize_fd);
1108 state->dbenv->close(state->dbenv, 0);
1110 state->dbenv->close(state->dbenv, 0);
1116 openpkgdb(struct rpmdbstate *state)
1118 if (state->dbopened)
1119 return state->dbopened > 0 ? 1 : 0;
1120 state->dbopened = -1;
1121 if (!state->dbenv && !opendbenv(state))
1123 if (db_create(&state->db, state->dbenv, 0))
1125 pool_error(state->pool, 0, "db_create: %s", strerror(errno));
1130 if (state->db->open(state->db, 0, "Packages", 0, DB_UNKNOWN, DB_RDONLY, 0664))
1132 pool_error(state->pool, 0, "db->open Packages: %s", strerror(errno));
1133 state->db->close(state->db, 0);
1138 if (state->db->get_byteswapped(state->db, &state->byteswapped))
1140 pool_error(state->pool, 0, "db->get_byteswapped: %s", strerror(errno));
1141 state->db->close(state->db, 0);
1146 state->dbopened = 1;
1150 /* get the rpmdbids of all installed packages from the Name index database.
1151 * This is much faster then querying the big Packages database */
1152 static struct rpmdbentry *
1153 getinstalledrpmdbids(struct rpmdbstate *state, const char *index, const char *match, int *nentriesp, char **namedatap)
1167 struct rpmdbentry *entries = 0;
1174 if (!state->dbenv && !opendbenv(state))
1176 dbenv = state->dbenv;
1177 if (db_create(&db, dbenv, 0))
1179 pool_error(state->pool, 0, "db_create: %s", strerror(errno));
1182 if (db->open(db, 0, index, 0, DB_UNKNOWN, DB_RDONLY, 0664))
1184 pool_error(state->pool, 0, "db->open %s: %s", index, strerror(errno));
1188 if (db->get_byteswapped(db, &byteswapped))
1190 pool_error(state->pool, 0, "db->get_byteswapped: %s", strerror(errno));
1194 if (db->cursor(db, NULL, &dbc, 0))
1196 pool_error(state->pool, 0, "db->cursor: %s", strerror(errno));
1200 memset(&dbkey, 0, sizeof(dbkey));
1201 memset(&dbdata, 0, sizeof(dbdata));
1204 dbkey.data = (void *)match;
1205 dbkey.size = strlen(match);
1207 while (dbc->c_get(dbc, &dbkey, &dbdata, match ? DB_SET : DB_NEXT) == 0)
1209 if (!match && dbkey.size == 10 && !memcmp(dbkey.data, "gpg-pubkey", 10))
1213 nameoff = namedatal;
1216 namedata = solv_extend(namedata, namedatal, dbkey.size + 1, 1, NAMEDATA_BLOCK);
1217 memcpy(namedata + namedatal, dbkey.data, dbkey.size);
1218 namedata[namedatal + dbkey.size] = 0;
1219 namedatal += dbkey.size + 1;
1221 while(dl >= RPM_INDEX_SIZE)
1223 entries = solv_extend(entries, nentries, 1, sizeof(*entries), ENTRIES_BLOCK);
1224 entries[nentries].rpmdbid = db2rpmdbid(dp, byteswapped);
1225 entries[nentries].nameoff = nameoff;
1227 dp += RPM_INDEX_SIZE;
1228 dl -= RPM_INDEX_SIZE;
1235 /* make sure that enteries is != 0 if there was no error */
1237 entries = solv_extend(entries, 1, 1, sizeof(*entries), ENTRIES_BLOCK);
1238 *nentriesp = nentries;
1240 *namedatap = namedata;
1244 /* retrive header by rpmdbid */
1246 getrpmdbid(struct rpmdbstate *state, Id rpmdbid)
1248 unsigned char buf[16];
1255 pool_error(state->pool, 0, "illegal rpmdbid");
1258 if (state->dbopened != 1 && !openpkgdb(state))
1260 rpmdbid2db(buf, rpmdbid, state->byteswapped);
1261 memset(&dbkey, 0, sizeof(dbkey));
1262 memset(&dbdata, 0, sizeof(dbdata));
1267 if (state->db->get(state->db, NULL, &dbkey, &dbdata, 0))
1269 if (dbdata.size < 8)
1271 pool_error(state->pool, 0, "corrupt rpm database (size)");
1274 if (dbdata.size > state->rpmheadsize)
1276 state->rpmheadsize = dbdata.size + 128;
1277 state->rpmhead = solv_realloc(state->rpmhead, sizeof(*rpmhead) + state->rpmheadsize);
1279 rpmhead = state->rpmhead;
1280 memcpy(buf, dbdata.data, 8);
1281 rpmhead->forcebinary = 1;
1282 rpmhead->cnt = buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3];
1283 rpmhead->dcnt = buf[4] << 24 | buf[5] << 16 | buf[6] << 8 | buf[7];
1284 if (8 + rpmhead->cnt * 16 + rpmhead->dcnt > dbdata.size)
1286 pool_error(state->pool, 0, "corrupt rpm database (data size)");
1289 memcpy(rpmhead->data, (unsigned char *)dbdata.data + 8, rpmhead->cnt * 16 + rpmhead->dcnt);
1290 rpmhead->dp = rpmhead->data + rpmhead->cnt * 16;
1294 /* retrive header by berkeleydb cursor */
1296 getrpmcursor(struct rpmdbstate *state, DBC *dbc)
1298 unsigned char buf[16];
1304 memset(&dbkey, 0, sizeof(dbkey));
1305 memset(&dbdata, 0, sizeof(dbdata));
1306 while (dbc->c_get(dbc, &dbkey, &dbdata, DB_NEXT) == 0)
1308 if (dbkey.size != 4)
1309 return pool_error(state->pool, -1, "corrupt Packages database (key size)");
1310 dbid = db2rpmdbid(dbkey.data, state->byteswapped);
1311 if (dbid == 0) /* the join key */
1313 if (dbdata.size < 8)
1314 return pool_error(state->pool, -1, "corrupt rpm database (size %u)\n", dbdata.size);
1315 if (dbdata.size > state->rpmheadsize)
1317 state->rpmheadsize = dbdata.size + 128;
1318 state->rpmhead = solv_realloc(state->rpmhead, sizeof(*state->rpmhead) + state->rpmheadsize);
1320 rpmhead = state->rpmhead;
1321 memcpy(buf, dbdata.data, 8);
1322 rpmhead->forcebinary = 1;
1323 rpmhead->cnt = buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3];
1324 rpmhead->dcnt = buf[4] << 24 | buf[5] << 16 | buf[6] << 8 | buf[7];
1325 if (8 + rpmhead->cnt * 16 + rpmhead->dcnt > dbdata.size)
1326 return pool_error(state->pool, -1, "corrupt rpm database (data size)\n");
1327 memcpy(rpmhead->data, (unsigned char *)dbdata.data + 8, rpmhead->cnt * 16 + rpmhead->dcnt);
1328 rpmhead->dp = rpmhead->data + rpmhead->cnt * 16;
1335 freestate(struct rpmdbstate *state)
1341 solv_free(state->rootdir);
1343 state->db->close(state->db, 0);
1346 solv_free(state->rpmhead);
1350 rpm_state_create(Pool *pool, const char *rootdir)
1352 struct rpmdbstate *state;
1353 state = solv_calloc(1, sizeof(*state));
1356 state->rootdir = solv_strdup(rootdir);
1361 rpm_state_free(void *state)
1364 return solv_free(state);
1368 count_headers(Pool *pool, const char *rootdir, DB_ENV *dbenv)
1370 char dbpath[PATH_MAX];
1371 struct stat statbuf;
1378 snprintf(dbpath, PATH_MAX, "%s/var/lib/rpm/Name", rootdir ? rootdir : "");
1379 if (stat(dbpath, &statbuf))
1381 memset(&dbkey, 0, sizeof(dbkey));
1382 memset(&dbdata, 0, sizeof(dbdata));
1383 if (db_create(&db, dbenv, 0))
1385 pool_error(pool, 0, "db_create: %s", strerror(errno));
1388 if (db->open(db, 0, "Name", 0, DB_UNKNOWN, DB_RDONLY, 0664))
1390 pool_error(pool, 0, "db->open Name: %s", strerror(errno));
1394 if (db->cursor(db, NULL, &dbc, 0))
1397 pool_error(pool, 0, "db->cursor: %s", strerror(errno));
1400 while (dbc->c_get(dbc, &dbkey, &dbdata, DB_NEXT) == 0)
1401 count += dbdata.size / RPM_INDEX_SIZE;
1407 /******************************************************************/
1410 copydeps(Pool *pool, Repo *repo, Offset fromoff, Repo *fromrepo)
1418 from = fromrepo->idarraydata + fromoff;
1419 for (ida = from, cc = 0; *ida; ida++, cc++)
1423 ido = repo_reserve_ids(repo, 0, cc);
1424 ida = repo->idarraydata + ido;
1425 memcpy(ida, from, (cc + 1) * sizeof(Id));
1426 repo->idarraysize += cc + 1;
1430 #define COPYDIR_DIRCACHE_SIZE 512
1432 static Id copydir_complex(Pool *pool, Repodata *data, Repodata *fromdata, Id did, Id *cache);
1435 copydir(Pool *pool, Repodata *data, Repodata *fromdata, Id did, Id *cache)
1437 if (cache && cache[did & 255] == did)
1438 return cache[(did & 255) + 256];
1439 return copydir_complex(pool, data, fromdata, did, cache);
1443 copydir_complex(Pool *pool, Repodata *data, Repodata *fromdata, Id did, Id *cache)
1445 Id parent = dirpool_parent(&fromdata->dirpool, did);
1446 Id compid = dirpool_compid(&fromdata->dirpool, did);
1448 parent = copydir(pool, data, fromdata, parent, cache);
1449 if (data->localpool || fromdata->localpool)
1450 compid = repodata_translate_id(data, fromdata, compid, 1);
1451 compid = dirpool_add_dir(&data->dirpool, parent, compid, 1);
1454 cache[did & 255] = did;
1455 cache[(did & 255) + 256] = compid;
1460 struct solvable_copy_cbdata {
1468 solvable_copy_cb(void *vcbdata, Solvable *r, Repodata *fromdata, Repokey *key, KeyValue *kv)
1470 struct solvable_copy_cbdata *cbdata = vcbdata;
1472 Repodata *data = cbdata->data;
1473 Id handle = cbdata->handle;
1474 Pool *pool = data->repo->pool;
1476 keyname = key->name;
1479 case REPOKEY_TYPE_ID:
1480 case REPOKEY_TYPE_CONSTANTID:
1481 case REPOKEY_TYPE_IDARRAY: /* used for triggers */
1483 if (data->localpool || fromdata->localpool)
1484 id = repodata_translate_id(data, fromdata, id, 1);
1485 if (key->type == REPOKEY_TYPE_ID)
1486 repodata_set_id(data, handle, keyname, id);
1487 else if (key->type == REPOKEY_TYPE_CONSTANTID)
1488 repodata_set_constantid(data, handle, keyname, id);
1490 repodata_add_idarray(data, handle, keyname, id);
1492 case REPOKEY_TYPE_STR:
1493 repodata_set_str(data, handle, keyname, kv->str);
1495 case REPOKEY_TYPE_VOID:
1496 repodata_set_void(data, handle, keyname);
1498 case REPOKEY_TYPE_NUM:
1499 repodata_set_num(data, handle, keyname, SOLV_KV_NUM64(kv));
1501 case REPOKEY_TYPE_CONSTANT:
1502 repodata_set_constant(data, handle, keyname, kv->num);
1504 case REPOKEY_TYPE_DIRNUMNUMARRAY:
1506 id = copydir(pool, data, fromdata, id, cbdata->dircache);
1507 repodata_add_dirnumnum(data, handle, keyname, id, kv->num, kv->num2);
1509 case REPOKEY_TYPE_DIRSTRARRAY:
1511 id = copydir(pool, data, fromdata, id, cbdata->dircache);
1512 repodata_add_dirstr(data, handle, keyname, id, kv->str);
1514 case REPOKEY_TYPE_FLEXARRAY:
1517 assert(cbdata->subhandle);
1518 cbdata->handle = cbdata->subhandle;
1519 cbdata->subhandle = 0;
1524 assert(!cbdata->subhandle);
1525 cbdata->subhandle = cbdata->handle;
1527 cbdata->handle = repodata_new_handle(data);
1528 repodata_add_flexarray(data, cbdata->subhandle, keyname, cbdata->handle);
1530 case REPOKEY_TYPE_MD5:
1531 case REPOKEY_TYPE_SHA1:
1532 case REPOKEY_TYPE_SHA256:
1533 repodata_set_bin_checksum(data, handle, keyname, key->type, (const unsigned char *)kv->str);
1542 solvable_copy(Solvable *s, Solvable *r, Repodata *data, Id *dircache)
1545 Repo *repo = s->repo;
1546 Pool *pool = repo->pool;
1547 Repo *fromrepo = r->repo;
1548 struct solvable_copy_cbdata cbdata;
1550 /* copy solvable data */
1554 s->vendor = r->vendor;
1555 s->provides = copydeps(pool, repo, r->provides, fromrepo);
1556 s->requires = copydeps(pool, repo, r->requires, fromrepo);
1557 s->conflicts = copydeps(pool, repo, r->conflicts, fromrepo);
1558 s->obsoletes = copydeps(pool, repo, r->obsoletes, fromrepo);
1559 s->recommends = copydeps(pool, repo, r->recommends, fromrepo);
1560 s->suggests = copydeps(pool, repo, r->suggests, fromrepo);
1561 s->supplements = copydeps(pool, repo, r->supplements, fromrepo);
1562 s->enhances = copydeps(pool, repo, r->enhances, fromrepo);
1564 /* copy all attributes */
1568 cbdata.handle = s - pool->solvables;
1569 cbdata.subhandle = 0;
1570 cbdata.dircache = dircache;
1571 p = r - fromrepo->pool->solvables;
1573 repo_search(fromrepo, p, 0, 0, SEARCH_NO_STORAGE_SOLVABLE | SEARCH_SUB | SEARCH_ARRAYSENTINEL, solvable_copy_cb, &cbdata);
1575 FOR_REPODATAS(fromrepo, i, data)
1577 if (p >= data->start && p < data->end)
1578 repodata_search(data, p, 0, SEARCH_SUB | SEARCH_ARRAYSENTINEL, solvable_copy_cb, &cbdata);
1579 cbdata.dircache = 0; /* only for first repodata */
1584 /* used to sort entries by package name that got returned in some database order */
1586 rpmids_sort_cmp(const void *va, const void *vb, void *dp)
1588 struct rpmdbentry const *a = va, *b = vb;
1589 char *namedata = dp;
1591 r = strcmp(namedata + a->nameoff, namedata + b->nameoff);
1594 return a->rpmdbid - b->rpmdbid;
1598 pkgids_sort_cmp(const void *va, const void *vb, void *dp)
1601 Pool *pool = repo->pool;
1602 Solvable *a = pool->solvables + *(Id *)va;
1603 Solvable *b = pool->solvables + *(Id *)vb;
1606 if (a->name != b->name)
1607 return strcmp(pool_id2str(pool, a->name), pool_id2str(pool, b->name));
1608 rpmdbid = repo->rpmdbid;
1609 return rpmdbid[(a - pool->solvables) - repo->start] - rpmdbid[(b - pool->solvables) - repo->start];
1613 swap_solvables(Repo *repo, Repodata *data, Id pa, Id pb)
1615 Pool *pool = repo->pool;
1618 tmp = pool->solvables[pa];
1619 pool->solvables[pa] = pool->solvables[pb];
1620 pool->solvables[pb] = tmp;
1623 Id tmpid = repo->rpmdbid[pa - repo->start];
1624 repo->rpmdbid[pa - repo->start] = repo->rpmdbid[pb - repo->start];
1625 repo->rpmdbid[pb - repo->start] = tmpid;
1627 /* only works if nothing is already internalized! */
1629 repodata_swap_attrs(data, pa, pb);
1633 mkrpmdbcookie(struct stat *st, unsigned char *cookie, int flags)
1636 memset(cookie, 0, 32);
1637 cookie[3] = RPMDB_COOKIE_VERSION;
1638 memcpy(cookie + 16, &st->st_ino, sizeof(st->st_ino));
1639 memcpy(cookie + 24, &st->st_dev, sizeof(st->st_dev));
1640 if ((flags & RPM_ADD_WITH_PKGID) != 0)
1642 if ((flags & RPM_ADD_WITH_HDRID) != 0)
1644 if ((flags & RPM_ADD_WITH_CHANGELOG) != 0)
1646 if ((flags & RPM_ADD_NO_FILELIST) == 0)
1648 if ((flags & RPM_ADD_NO_RPMLIBREQS) != 0)
1654 * read rpm db as repo
1659 repo_add_rpmdb(Repo *repo, Repo *ref, int flags)
1661 Pool *pool = repo->pool;
1662 char dbpath[PATH_MAX];
1663 struct stat packagesstat;
1664 unsigned char newcookie[32];
1665 const unsigned char *oldcookie = 0;
1666 Id oldcookietype = 0;
1668 int count = 0, done = 0;
1669 struct rpmdbstate state;
1674 now = solv_timems(0);
1675 memset(&state, 0, sizeof(state));
1678 data = repo_add_repodata(repo, flags);
1680 if (ref && !(ref->nsolvables && ref->rpmdbid && ref->pool == repo->pool))
1682 if ((flags & RPMDB_EMPTY_REFREPO) != 0)
1687 if (flags & REPO_USE_ROOTDIR)
1688 state.rootdir = solv_strdup(pool_get_rootdir(pool));
1689 if (!opendbenv(&state))
1691 solv_free(state.rootdir);
1695 /* XXX: should get ro lock of Packages database! */
1696 snprintf(dbpath, PATH_MAX, "%s/var/lib/rpm/Packages", state.rootdir ? state.rootdir : "");
1697 if (stat(dbpath, &packagesstat))
1699 pool_error(pool, -1, "%s: %s", dbpath, strerror(errno));
1703 mkrpmdbcookie(&packagesstat, newcookie, flags);
1704 repodata_set_bin_checksum(data, SOLVID_META, REPOSITORY_RPMDBCOOKIE, REPOKEY_TYPE_SHA256, newcookie);
1707 oldcookie = repo_lookup_bin_checksum(ref, SOLVID_META, REPOSITORY_RPMDBCOOKIE, &oldcookietype);
1708 if (!ref || !oldcookie || oldcookietype != REPOKEY_TYPE_SHA256 || memcmp(oldcookie, newcookie, 32) != 0)
1710 int solvstart = 0, solvend = 0;
1714 if (ref && (flags & RPMDB_EMPTY_REFREPO) != 0)
1715 repo_empty(ref, 1); /* get it out of the way */
1716 if ((flags & RPMDB_REPORT_PROGRESS) != 0)
1717 count = count_headers(pool, state.rootdir, state.dbenv);
1718 if (!openpkgdb(&state))
1723 if (state.db->cursor(state.db, NULL, &dbc, 0))
1726 return pool_error(pool, -1, "db->cursor failed");
1730 while ((dbid = getrpmcursor(&state, dbc)) != 0)
1740 s = pool_id2solvable(pool, repo_add_solvable(repo));
1742 solvstart = s - pool->solvables;
1743 solvend = s - pool->solvables + 1;
1746 repo->rpmdbid = repo_sidedata_create(repo, sizeof(Id));
1747 repo->rpmdbid[(s - pool->solvables) - repo->start] = dbid;
1748 if (rpm2solv(pool, repo, data, s, state.rpmhead, flags | RPM_ADD_TRIGGERS))
1755 /* We can reuse this solvable, but make sure it's still
1756 associated with this repo. */
1757 memset(s, 0, sizeof(*s));
1760 if ((flags & RPMDB_REPORT_PROGRESS) != 0)
1764 if (done < count && (done - 1) * 100 / count != done * 100 / count)
1765 pool_debug(pool, SOLV_ERROR, "%%%% %d\n", done * 100 / count);
1771 /* oops, could not reuse. free it instead */
1772 repo_free_solvable(repo, s - pool->solvables, 1);
1776 /* now sort all solvables in the new solvstart..solvend block */
1777 if (solvend - solvstart > 1)
1779 Id *pkgids = solv_malloc2(solvend - solvstart, sizeof(Id));
1780 for (i = solvstart; i < solvend; i++)
1781 pkgids[i - solvstart] = i;
1782 solv_sort(pkgids, solvend - solvstart, sizeof(Id), pkgids_sort_cmp, repo);
1784 for (i = solvstart; i < solvend; i++)
1786 int j = pkgids[i - solvstart];
1788 j = pkgids[i - solvstart] = pkgids[j - solvstart];
1790 swap_solvables(repo, data, i, j);
1797 Id dircache[COPYDIR_DIRCACHE_SIZE]; /* see copydir */
1798 struct rpmdbentry *entries = 0, *rp;
1801 unsigned int refmask, h;
1805 memset(dircache, 0, sizeof(dircache));
1807 /* get ids of installed rpms */
1808 entries = getinstalledrpmdbids(&state, "Name", 0, &nentries, &namedata);
1817 solv_sort(entries, nentries, sizeof(*entries), rpmids_sort_cmp, namedata);
1819 /* create hash from dbid to ref */
1820 refmask = mkmask(ref->nsolvables);
1821 refhash = solv_calloc(refmask + 1, sizeof(Id));
1822 for (i = 0; i < ref->end - ref->start; i++)
1824 if (!ref->rpmdbid[i])
1826 h = ref->rpmdbid[i] & refmask;
1828 h = (h + 317) & refmask;
1829 refhash[h] = i + 1; /* make it non-zero */
1832 /* count the misses, they will cost us time */
1833 if ((flags & RPMDB_REPORT_PROGRESS) != 0)
1835 for (i = 0, rp = entries; i < nentries; i++, rp++)
1839 Id dbid = rp->rpmdbid;
1841 while ((id = refhash[h]))
1843 if (ref->rpmdbid[id - 1] == dbid)
1845 h = (h + 317) & refmask;
1854 if (ref && (flags & RPMDB_EMPTY_REFREPO) != 0)
1855 s = pool_id2solvable(pool, repo_add_solvable_block_before(repo, nentries, ref));
1857 s = pool_id2solvable(pool, repo_add_solvable_block(repo, nentries));
1859 repo->rpmdbid = repo_sidedata_create(repo, sizeof(Id));
1861 for (i = 0, rp = entries; i < nentries; i++, rp++, s++)
1863 Id dbid = rp->rpmdbid;
1864 repo->rpmdbid[(s - pool->solvables) - repo->start] = rp->rpmdbid;
1868 while ((id = refhash[h]))
1870 if (ref->rpmdbid[id - 1] == dbid)
1872 h = (h + 317) & refmask;
1876 Solvable *r = ref->pool->solvables + ref->start + (id - 1);
1879 solvable_copy(s, r, data, dircache);
1884 res = getrpmdbid(&state, dbid);
1888 pool_error(pool, -1, "inconsistent rpm database, key %d not found. run 'rpm --rebuilddb' to fix.", dbid);
1891 solv_free(namedata);
1895 rpm2solv(pool, repo, data, s, state.rpmhead, flags | RPM_ADD_TRIGGERS);
1896 if ((flags & RPMDB_REPORT_PROGRESS) != 0)
1900 if (done < count && (done - 1) * 100 / count != done * 100 / count)
1901 pool_debug(pool, SOLV_ERROR, "%%%% %d\n", done * 100 / count);
1906 solv_free(namedata);
1908 if (ref && (flags & RPMDB_EMPTY_REFREPO) != 0)
1913 if (!(flags & REPO_NO_INTERNALIZE))
1914 repodata_internalize(data);
1915 if ((flags & RPMDB_REPORT_PROGRESS) != 0)
1916 pool_debug(pool, SOLV_ERROR, "%%%% 100\n");
1917 POOL_DEBUG(SOLV_DEBUG_STATS, "repo_add_rpmdb took %d ms\n", solv_timems(now));
1918 POOL_DEBUG(SOLV_DEBUG_STATS, "repo size: %d solvables\n", repo->nsolvables);
1919 POOL_DEBUG(SOLV_DEBUG_STATS, "repo memory used: %d K incore, %d K idarray\n", repodata_memused(data)/1024, repo->idarraysize / (int)(1024/sizeof(Id)));
1924 repo_add_rpmdb_reffp(Repo *repo, FILE *fp, int flags)
1930 return repo_add_rpmdb(repo, 0, flags);
1931 ref = repo_create(repo->pool, "add_rpmdb_reffp");
1932 if (repo_add_solv(ref, fp, 0) != 0)
1937 if (ref && ref->start == ref->end)
1943 repo_disable_paging(ref);
1944 res = repo_add_rpmdb(repo, ref, flags | RPMDB_EMPTY_REFREPO);
1950 static inline unsigned int
1951 getu32(const unsigned char *dp)
1953 return dp[0] << 24 | dp[1] << 16 | dp[2] << 8 | dp[3];
1958 repo_add_rpm(Repo *repo, const char *rpm, int flags)
1960 unsigned int sigdsize, sigcnt, l;
1961 Pool *pool = repo->pool;
1963 RpmHead *rpmhead = 0;
1964 int rpmheadsize = 0;
1965 char *payloadformat;
1967 unsigned char lead[4096];
1968 int headerstart, headerend;
1971 unsigned char pkgid[16];
1972 unsigned char leadsigid[16];
1973 unsigned char hdrid[32];
1974 int pkgidtype, leadsigidtype, hdridtype;
1976 Chksum *chksumh = 0;
1977 Chksum *leadsigchksumh = 0;
1978 int forcebinary = 0;
1980 data = repo_add_repodata(repo, flags);
1982 if ((flags & RPM_ADD_WITH_SHA256SUM) != 0)
1983 chksumtype = REPOKEY_TYPE_SHA256;
1984 else if ((flags & RPM_ADD_WITH_SHA1SUM) != 0)
1985 chksumtype = REPOKEY_TYPE_SHA1;
1987 if ((fp = fopen(flags & REPO_USE_ROOTDIR ? pool_prepend_rootdir_tmp(pool, rpm) : rpm, "r")) == 0)
1989 pool_error(pool, -1, "%s: %s", rpm, strerror(errno));
1992 if (fstat(fileno(fp), &stb))
1994 pool_error(pool, -1, "fstat: %s", strerror(errno));
1999 chksumh = solv_chksum_create(chksumtype);
2000 if ((flags & RPM_ADD_WITH_LEADSIGID) != 0)
2001 leadsigchksumh = solv_chksum_create(REPOKEY_TYPE_MD5);
2002 if (fread(lead, 96 + 16, 1, fp) != 1 || getu32(lead) != 0xedabeedb)
2004 pool_error(pool, -1, "%s: not a rpm", rpm);
2008 forcebinary = lead[6] != 0 || lead[7] != 1;
2010 solv_chksum_add(chksumh, lead, 96 + 16);
2012 solv_chksum_add(leadsigchksumh, lead, 96 + 16);
2013 if (lead[78] != 0 || lead[79] != 5)
2015 pool_error(pool, -1, "%s: not a rpm v5 header", rpm);
2019 if (getu32(lead + 96) != 0x8eade801)
2021 pool_error(pool, -1, "%s: bad signature header", rpm);
2025 sigcnt = getu32(lead + 96 + 8);
2026 sigdsize = getu32(lead + 96 + 12);
2027 if (sigcnt >= 0x100000 || sigdsize >= 0x100000)
2029 pool_error(pool, -1, "%s: bad signature header", rpm);
2033 sigdsize += sigcnt * 16;
2034 sigdsize = (sigdsize + 7) & ~7;
2035 headerstart = 96 + 16 + sigdsize;
2036 pkgidtype = leadsigidtype = hdridtype = 0;
2037 if ((flags & (RPM_ADD_WITH_PKGID | RPM_ADD_WITH_HDRID)) != 0)
2039 /* extract pkgid or hdrid from the signature header */
2040 if (sigdsize > rpmheadsize)
2042 rpmheadsize = sigdsize + 128;
2043 rpmhead = solv_realloc(rpmhead, sizeof(*rpmhead) + rpmheadsize);
2045 if (fread(rpmhead->data, sigdsize, 1, fp) != 1)
2047 pool_error(pool, -1, "%s: unexpected EOF", rpm);
2052 solv_chksum_add(chksumh, rpmhead->data, sigdsize);
2054 solv_chksum_add(leadsigchksumh, rpmhead->data, sigdsize);
2055 rpmhead->forcebinary = 0;
2056 rpmhead->cnt = sigcnt;
2057 rpmhead->dcnt = sigdsize - sigcnt * 16;
2058 rpmhead->dp = rpmhead->data + rpmhead->cnt * 16;
2059 if ((flags & RPM_ADD_WITH_PKGID) != 0)
2061 unsigned char *chksum;
2062 unsigned int chksumsize;
2063 chksum = headbinary(rpmhead, SIGTAG_MD5, &chksumsize);
2064 if (chksum && chksumsize == 16)
2066 pkgidtype = REPOKEY_TYPE_MD5;
2067 memcpy(pkgid, chksum, 16);
2070 if ((flags & RPM_ADD_WITH_HDRID) != 0)
2072 const char *str = headstring(rpmhead, TAG_SHA1HEADER);
2073 if (str && strlen(str) == 40)
2075 if (solv_hex2bin(&str, hdrid, 20) == 20)
2076 hdridtype = REPOKEY_TYPE_SHA1;
2078 else if (str && strlen(str) == 64)
2080 if (solv_hex2bin(&str, hdrid, 32) == 32)
2081 hdridtype = REPOKEY_TYPE_SHA256;
2087 /* just skip the signature header */
2090 l = sigdsize > 4096 ? 4096 : sigdsize;
2091 if (fread(lead, l, 1, fp) != 1)
2093 pool_error(pool, -1, "%s: unexpected EOF", rpm);
2098 solv_chksum_add(chksumh, lead, l);
2100 solv_chksum_add(leadsigchksumh, lead, l);
2106 leadsigchksumh = solv_chksum_free(leadsigchksumh, leadsigid);
2107 leadsigidtype = REPOKEY_TYPE_MD5;
2109 if (fread(lead, 16, 1, fp) != 1)
2111 pool_error(pool, -1, "%s: unexpected EOF", rpm);
2116 solv_chksum_add(chksumh, lead, 16);
2117 if (getu32(lead) != 0x8eade801)
2119 pool_error(pool, -1, "%s: bad header", rpm);
2123 sigcnt = getu32(lead + 8);
2124 sigdsize = getu32(lead + 12);
2125 if (sigcnt >= 0x100000 || sigdsize >= 0x2000000)
2127 pool_error(pool, -1, "%s: bad header", rpm);
2131 l = sigdsize + sigcnt * 16;
2132 headerend = headerstart + 16 + l;
2133 if (l > rpmheadsize)
2135 rpmheadsize = l + 128;
2136 rpmhead = solv_realloc(rpmhead, sizeof(*rpmhead) + rpmheadsize);
2138 if (fread(rpmhead->data, l, 1, fp) != 1)
2140 pool_error(pool, -1, "%s: unexpected EOF", rpm);
2145 solv_chksum_add(chksumh, rpmhead->data, l);
2146 rpmhead->forcebinary = forcebinary;
2147 rpmhead->cnt = sigcnt;
2148 rpmhead->dcnt = sigdsize;
2149 rpmhead->dp = rpmhead->data + rpmhead->cnt * 16;
2150 if (headexists(rpmhead, TAG_PATCHESNAME))
2152 /* this is a patch rpm, ignore */
2153 pool_error(pool, -1, "%s: is patch rpm", rpm);
2155 solv_chksum_free(chksumh, 0);
2159 payloadformat = headstring(rpmhead, TAG_PAYLOADFORMAT);
2160 if (payloadformat && !strcmp(payloadformat, "drpm"))
2162 /* this is a delta rpm */
2163 pool_error(pool, -1, "%s: is delta rpm", rpm);
2165 solv_chksum_free(chksumh, 0);
2170 while ((l = fread(lead, 1, sizeof(lead), fp)) > 0)
2171 solv_chksum_add(chksumh, lead, l);
2173 s = pool_id2solvable(pool, repo_add_solvable(repo));
2174 if (!rpm2solv(pool, repo, data, s, rpmhead, flags & ~(RPM_ADD_WITH_HDRID | RPM_ADD_WITH_PKGID)))
2176 repo_free_solvable(repo, s - pool->solvables, 1);
2177 solv_chksum_free(chksumh, 0);
2181 if (!(flags & REPO_NO_LOCATION))
2182 repodata_set_location(data, s - pool->solvables, 0, 0, rpm);
2183 if (S_ISREG(stb.st_mode))
2184 repodata_set_num(data, s - pool->solvables, SOLVABLE_DOWNLOADSIZE, (unsigned long long)stb.st_size);
2185 repodata_set_num(data, s - pool->solvables, SOLVABLE_HEADEREND, headerend);
2187 repodata_set_bin_checksum(data, s - pool->solvables, SOLVABLE_PKGID, pkgidtype, pkgid);
2189 repodata_set_bin_checksum(data, s - pool->solvables, SOLVABLE_HDRID, hdridtype, hdrid);
2191 repodata_set_bin_checksum(data, s - pool->solvables, SOLVABLE_LEADSIGID, leadsigidtype, leadsigid);
2194 repodata_set_bin_checksum(data, s - pool->solvables, SOLVABLE_CHECKSUM, chksumtype, solv_chksum_get(chksumh, 0));
2195 chksumh = solv_chksum_free(chksumh, 0);
2198 if (!(flags & REPO_NO_INTERNALIZE))
2199 repodata_internalize(data);
2200 return s - pool->solvables;
2204 repo_add_rpm_handle(Repo *repo, void *rpmhandle, int flags)
2206 Pool *pool = repo->pool;
2208 RpmHead *rpmhead = rpmhandle;
2210 char *payloadformat;
2212 data = repo_add_repodata(repo, flags);
2213 if (headexists(rpmhead, TAG_PATCHESNAME))
2215 pool_error(pool, -1, "is a patch rpm");
2218 payloadformat = headstring(rpmhead, TAG_PAYLOADFORMAT);
2219 if (payloadformat && !strcmp(payloadformat, "drpm"))
2221 /* this is a delta rpm */
2222 pool_error(pool, -1, "is a delta rpm");
2225 s = pool_id2solvable(pool, repo_add_solvable(repo));
2226 if (!rpm2solv(pool, repo, data, s, rpmhead, flags))
2228 repo_free_solvable(repo, s - pool->solvables, 1);
2231 if (!(flags & REPO_NO_INTERNALIZE))
2232 repodata_internalize(data);
2233 return s - pool->solvables;
2237 linkhash(const char *lt, char *hash)
2240 const unsigned char *str = (const unsigned char *)lt;
2244 while ((c = *str++) != 0)
2246 sprintf(hash, "%08x%08x%08x%08x", r, l, 0, 0);
2250 rpm_iterate_filelist(void *rpmhandle, int flags, void (*cb)(void *, const char *, struct filelistinfo *), void *cbdata)
2252 RpmHead *rpmhead = rpmhandle;
2257 unsigned int *di, diidx;
2258 unsigned int *co = 0;
2259 unsigned int *ff = 0;
2260 unsigned int lastdir;
2263 int cnt, dcnt, cnt2;
2268 struct filelistinfo info;
2270 dn = headstringarray(rpmhead, TAG_DIRNAMES, &dcnt);
2273 if ((flags & RPM_ITERATE_FILELIST_ONLYDIRS) != 0)
2275 for (i = 0; i < dcnt; i++)
2276 (*cb)(cbdata, dn[i], 0);
2280 bn = headstringarray(rpmhead, TAG_BASENAMES, &cnt);
2286 di = headint32array(rpmhead, TAG_DIRINDEXES, &cnt2);
2287 if (!di || cnt != cnt2)
2294 fm = headint16array(rpmhead, TAG_FILEMODES, &cnt2);
2295 if (!fm || cnt != cnt2)
2303 if ((flags & RPM_ITERATE_FILELIST_WITHMD5) != 0)
2305 md = headstringarray(rpmhead, TAG_FILEMD5S, &cnt2);
2306 if (!md || cnt != cnt2)
2316 if ((flags & RPM_ITERATE_FILELIST_WITHCOL) != 0)
2318 co = headint32array(rpmhead, TAG_FILECOLORS, &cnt2);
2319 if (!co || cnt != cnt2)
2330 if ((flags & RPM_ITERATE_FILELIST_NOGHOSTS) != 0)
2332 ff = headint32array(rpmhead, TAG_FILEFLAGS, &cnt2);
2333 if (!ff || cnt != cnt2)
2347 memset(&info, 0, sizeof(info));
2348 for (i = 0; i < cnt; i++)
2350 if (ff && (ff[i] & FILEFLAG_GHOST) != 0)
2355 l1 = lastdir == diidx ? lastdirl : strlen(dn[diidx]);
2356 l = l1 + strlen(bn[i]) + 1;
2360 space = solv_realloc(space, spacen);
2362 if (lastdir != diidx)
2364 strcpy(space, dn[diidx]);
2368 strcpy(space + l1, bn[i]);
2369 info.diridx = diidx;
2375 info.digest = md[i];
2376 if (fm && S_ISLNK(fm[i]))
2381 lt = headstringarray(rpmhead, TAG_FILELINKTOS, &cnt2);
2387 linkhash(lt[i], md5);
2393 sprintf(md5, "%08x%08x%08x%08x", (fm[i] >> 12) & 65535, 0, 0, 0);
2399 (*cb)(cbdata, space, &info);
2413 rpm_query(void *rpmhandle, Id what)
2415 const char *name, *arch, *sourcerpm;
2419 RpmHead *rpmhead = rpmhandle;
2424 name = headstring(rpmhead, TAG_NAME);
2427 sourcerpm = headstring(rpmhead, TAG_SOURCERPM);
2428 if (sourcerpm || (rpmhead->forcebinary && !headexists(rpmhead, TAG_SOURCEPACKAGE)))
2429 arch = headstring(rpmhead, TAG_ARCH);
2432 if (headexists(rpmhead, TAG_NOSOURCE) || headexists(rpmhead, TAG_NOPATCH))
2439 evr = headtoevr(rpmhead);
2440 l = strlen(name) + 1 + strlen(evr ? evr : "") + 1 + strlen(arch) + 1;
2442 sprintf(r, "%s-%s.%s", name, evr ? evr : "", arch);
2446 name = headstring(rpmhead, TAG_NAME);
2447 r = solv_strdup(name);
2449 case SOLVABLE_SUMMARY:
2450 name = headstring(rpmhead, TAG_SUMMARY);
2451 r = solv_strdup(name);
2453 case SOLVABLE_DESCRIPTION:
2454 name = headstring(rpmhead, TAG_DESCRIPTION);
2455 r = solv_strdup(name);
2458 r = headtoevr(rpmhead);
2465 rpm_query_num(void *rpmhandle, Id what, unsigned long long notfound)
2467 RpmHead *rpmhead = rpmhandle;
2472 case SOLVABLE_INSTALLTIME:
2473 u32 = headint32(rpmhead, TAG_INSTALLTIME);
2474 return u32 ? u32 : notfound;
2480 rpm_installedrpmdbids(void *rpmstate, const char *index, const char *match, Queue *rpmdbidq)
2482 struct rpmdbentry *entries;
2485 entries = getinstalledrpmdbids(rpmstate, index ? index : "Name", match, &nentries, 0);
2488 queue_empty(rpmdbidq);
2489 for (i = 0; i < nentries; i++)
2490 queue_push(rpmdbidq, entries[i].rpmdbid);
2497 rpm_byrpmdbid(void *rpmstate, Id rpmdbid)
2499 struct rpmdbstate *state = rpmstate;
2502 r = getrpmdbid(state, rpmdbid);
2504 pool_error(state->pool, 0, "header #%d not in database", rpmdbid);
2505 return r <= 0 ? 0 : state->rpmhead;
2509 rpm_byfp(void *rpmstate, FILE *fp, const char *name)
2511 struct rpmdbstate *state = rpmstate;
2512 /* int headerstart, headerend; */
2514 unsigned int sigdsize, sigcnt, l;
2515 unsigned char lead[4096];
2516 int forcebinary = 0;
2518 if (fread(lead, 96 + 16, 1, fp) != 1 || getu32(lead) != 0xedabeedb)
2520 pool_error(state->pool, 0, "%s: not a rpm", name);
2523 forcebinary = lead[6] != 0 || lead[7] != 1;
2524 if (lead[78] != 0 || lead[79] != 5)
2526 pool_error(state->pool, 0, "%s: not a V5 header", name);
2529 if (getu32(lead + 96) != 0x8eade801)
2531 pool_error(state->pool, 0, "%s: bad signature header", name);
2534 sigcnt = getu32(lead + 96 + 8);
2535 sigdsize = getu32(lead + 96 + 12);
2536 if (sigcnt >= 0x100000 || sigdsize >= 0x100000)
2538 pool_error(state->pool, 0, "%s: bad signature header", name);
2541 sigdsize += sigcnt * 16;
2542 sigdsize = (sigdsize + 7) & ~7;
2543 /* headerstart = 96 + 16 + sigdsize; */
2546 l = sigdsize > 4096 ? 4096 : sigdsize;
2547 if (fread(lead, l, 1, fp) != 1)
2549 pool_error(state->pool, 0, "%s: unexpected EOF", name);
2554 if (fread(lead, 16, 1, fp) != 1)
2556 pool_error(state->pool, 0, "%s: unexpected EOF", name);
2559 if (getu32(lead) != 0x8eade801)
2561 pool_error(state->pool, 0, "%s: bad header", name);
2564 sigcnt = getu32(lead + 8);
2565 sigdsize = getu32(lead + 12);
2566 if (sigcnt >= 0x100000 || sigdsize >= 0x2000000)
2568 pool_error(state->pool, 0, "%s: bad header", name);
2571 l = sigdsize + sigcnt * 16;
2572 /* headerend = headerstart + 16 + l; */
2573 if (l > state->rpmheadsize)
2575 state->rpmheadsize = l + 128;
2576 state->rpmhead = solv_realloc(state->rpmhead, sizeof(*state->rpmhead) + state->rpmheadsize);
2578 rpmhead = state->rpmhead;
2579 if (fread(rpmhead->data, l, 1, fp) != 1)
2581 pool_error(state->pool, 0, "%s: unexpected EOF", name);
2584 rpmhead->forcebinary = forcebinary;
2585 rpmhead->cnt = sigcnt;
2586 rpmhead->dcnt = sigdsize;
2587 rpmhead->dp = rpmhead->data + rpmhead->cnt * 16;
2591 #ifdef ENABLE_RPMDB_BYRPMHEADER
2594 rpm_byrpmh(void *rpmstate, Header h)
2596 struct rpmdbstate *state = rpmstate;
2597 const unsigned char *uh;
2598 unsigned int sigdsize, sigcnt, l;
2602 uh = headerUnload(h);
2604 uh = headerUnload(h, NULL);
2608 sigcnt = getu32(uh);
2609 sigdsize = getu32(uh + 4);
2610 l = sigdsize + sigcnt * 16;
2611 if (l > state->rpmheadsize)
2613 state->rpmheadsize = l + 128;
2614 state->rpmhead = solv_realloc(state->rpmhead, sizeof(*state->rpmhead) + state->rpmheadsize);
2616 rpmhead = state->rpmhead;
2617 memcpy(rpmhead->data, uh + 8, l - 8);
2619 rpmhead->forcebinary = 0;
2620 rpmhead->cnt = sigcnt;
2621 rpmhead->dcnt = sigdsize;
2622 rpmhead->dp = rpmhead->data + rpmhead->cnt * 16;