2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
11 * Read the binary dump of a Repo and create a Repo * from it
14 * Repo *pool_addrepo_solv(Pool *pool, FILE *fp)
26 #include "repo_solv.h"
32 #define INTERESTED_START SOLVABLE_NAME
33 #define INTERESTED_END SOLVABLE_ENHANCES
35 #define SOLV_ERROR_NOT_SOLV 1
36 #define SOLV_ERROR_UNSUPPORTED 2
37 #define SOLV_ERROR_EOF 3
38 #define SOLV_ERROR_ID_RANGE 4
39 #define SOLV_ERROR_OVERFLOW 5
40 #define SOLV_ERROR_CORRUPT 6
42 static Pool *mypool; /* for pool_debug... */
45 static void repodata_load_stub(Repodata *data);
48 /*******************************************************************************
49 * functions to extract data from a file handle
57 read_u32(Repodata *data)
64 for (i = 0; i < 4; i++)
69 pool_debug(mypool, SAT_ERROR, "unexpected EOF\n");
70 data->error = SOLV_ERROR_EOF;
84 read_u8(Repodata *data)
93 pool_debug(mypool, SAT_ERROR, "unexpected EOF\n");
94 data->error = SOLV_ERROR_EOF;
106 read_id(Repodata *data, Id max)
113 for (i = 0; i < 5; i++)
118 pool_debug(mypool, SAT_ERROR, "unexpected EOF\n");
119 data->error = SOLV_ERROR_EOF;
127 pool_debug(mypool, SAT_ERROR, "read_id: id too large (%u/%u)\n", x, max);
128 data->error = SOLV_ERROR_ID_RANGE;
133 x = (x << 7) ^ c ^ 128;
135 pool_debug(mypool, SAT_ERROR, "read_id: id too long\n");
136 data->error = SOLV_ERROR_CORRUPT;
142 read_idarray(Repodata *data, Id max, Id *map, Id *store, Id *end)
154 pool_debug(mypool, SAT_ERROR, "unexpected EOF\n");
155 data->error = SOLV_ERROR_EOF;
160 x = (x << 7) ^ c ^ 128;
163 x = (x << 6) | (c & 63);
166 pool_debug(mypool, SAT_ERROR, "read_idarray: id too large (%u/%u)\n", x, max);
167 data->error = SOLV_ERROR_ID_RANGE;
174 pool_debug(mypool, SAT_ERROR, "read_idarray: array overflow\n");
180 if (x == 0) /* already have trailing zero? */
184 pool_debug(mypool, SAT_ERROR, "read_idarray: array overflow\n");
185 data->error = SOLV_ERROR_OVERFLOW;
196 /*******************************************************************************
197 * functions to extract data from memory
204 static inline unsigned char *
205 data_read_id_max(unsigned char *dp, Id *ret, Id *map, int max, int *error)
208 dp = data_read_id(dp, &x);
211 pool_debug(mypool, SAT_ERROR, "data_read_idarray: id too large (%u/%u)\n", x, max);
212 *error = SOLV_ERROR_ID_RANGE;
215 *ret = map ? map[x] : x;
220 data_read_idarray(unsigned char *dp, Id **storep, Id *map, int max, int *error)
231 x = (x << 7) ^ c ^ 128;
234 x = (x << 6) | (c & 63);
237 pool_debug(mypool, SAT_ERROR, "data_read_idarray: id too large (%u/%u)\n", x, max);
238 *error = SOLV_ERROR_ID_RANGE;
252 data_read_rel_idarray(unsigned char *dp, Id **storep, Id *map, int max, int *error, Id marker)
264 x = (x << 7) ^ c ^ 128;
267 x = (x << 6) | (c & 63);
281 pool_debug(mypool, SAT_ERROR, "data_read_rel_idarray: id too large (%u/%u)\n", x, max);
282 *error = SOLV_ERROR_ID_RANGE;
285 *store++ = map ? map[x] : x;
298 /*******************************************************************************
299 * functions to add data to our incore memory space
302 #define INCORE_ADD_CHUNK 8192
303 #define DATA_READ_CHUNK 8192
306 incore_add_id(Repodata *data, Id x)
309 /* make sure we have at least 5 bytes free */
310 if (data->incoredatafree < 5)
312 data->incoredata = sat_realloc(data->incoredata, data->incoredatalen + INCORE_ADD_CHUNK);
313 data->incoredatafree = INCORE_ADD_CHUNK;
315 dp = data->incoredata + data->incoredatalen;
321 *dp++ = (x >> 28) | 128;
323 *dp++ = (x >> 21) | 128;
324 *dp++ = (x >> 14) | 128;
327 *dp++ = (x >> 7) | 128;
329 data->incoredatafree -= dp - (data->incoredata + data->incoredatalen);
330 data->incoredatalen = dp - data->incoredata;
334 incore_add_blob(Repodata *data, unsigned char *buf, int len)
336 if (data->incoredatafree < len)
338 data->incoredata = sat_realloc(data->incoredata, data->incoredatalen + INCORE_ADD_CHUNK + len);
339 data->incoredatafree = INCORE_ADD_CHUNK + len;
341 memcpy(data->incoredata + data->incoredatalen, buf, len);
342 data->incoredatafree -= len;
343 data->incoredatalen += len;
347 incore_map_idarray(Repodata *data, unsigned char *dp, Id *map, Id max)
349 /* We have to map the IDs, which might also change
350 the necessary number of bytes, so we can't just copy
351 over the blob and adjust it. */
356 dp = data_read_ideof(dp, &id, &eof);
357 if (max && id >= max)
359 pool_debug(mypool, SAT_ERROR, "incore_map_idarray: id too large (%u/%u)\n", id, max);
360 data->error = SOLV_ERROR_ID_RANGE;
365 id = (id & 63) | ((id & ~63) << 1);
366 incore_add_id(data, eof ? id : id | 64);
373 incore_add_u32(Repodata *data, unsigned int x)
376 /* make sure we have at least 4 bytes free */
377 if (data->incoredatafree < 4)
379 data->incoredata = sat_realloc(data->incoredata, data->incoredatalen + INCORE_ADD_CHUNK);
380 data->incoredatafree = INCORE_ADD_CHUNK;
382 dp = data->incoredata + data->incoredatalen;
387 data->incoredatafree -= 4;
388 data->incoredatalen += 4;
393 incore_add_u8(Repodata *data, unsigned int x)
396 /* make sure we have at least 1 byte free */
397 if (data->incoredatafree < 1)
399 data->incoredata = sat_realloc(data->incoredata, data->incoredatalen + 1024);
400 data->incoredatafree = 1024;
402 dp = data->incoredata + data->incoredatalen;
404 data->incoredatafree--;
405 data->incoredatalen++;
410 /*******************************************************************************
411 * callback to create our stub sub-repodatas from the incore data
414 struct create_stub_data {
420 create_stub_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv)
422 struct create_stub_data *stubdata = cbdata;
423 if (key->name == REPOSITORY_EXTERNAL && key->type == REPOKEY_TYPE_FLEXARRAY)
427 repodata_internalize(stubdata->data);
428 if (data->start != data->end)
430 repodata_extend(stubdata->data, data->start);
431 repodata_extend(stubdata->data, data->end - 1);
436 return SEARCH_NEXT_SOLVABLE;
437 stubdata->data = repo_add_repodata(data->repo, 0);
438 stubdata->data->state = REPODATA_STUB;
439 stubdata->data->loadcallback = repodata_load_stub;
440 return SEARCH_ENTERSUB;
443 return SEARCH_NEXT_KEY;
446 case REPOKEY_TYPE_ID:
447 repodata_set_id(stubdata->data, SOLVID_META, key->name, kv->id);
449 case REPOKEY_TYPE_CONSTANTID:
450 repodata_set_constantid(stubdata->data, SOLVID_META, key->name, kv->id);
452 case REPOKEY_TYPE_STR:
453 repodata_set_str(stubdata->data, SOLVID_META, key->name, kv->str);
455 case REPOKEY_TYPE_VOID:
456 repodata_set_void(stubdata->data, SOLVID_META, key->name);
458 case REPOKEY_TYPE_NUM:
459 repodata_set_num(stubdata->data, SOLVID_META, key->name, kv->num);
461 case REPOKEY_TYPE_IDARRAY:
462 repodata_add_idarray(stubdata->data, SOLVID_META, key->name, kv->id);
463 if (key->name == REPOSITORY_KEYS)
465 if (!stubdata->xkeyname)
466 stubdata->xkeyname = kv->id;
471 xkey.name = stubdata->xkeyname;
473 xkey.storage = KEY_STORAGE_INCORE;
475 repodata_key2id(stubdata->data, &xkey, 1);
476 stubdata->xkeyname = 0;
479 stubdata->xkeyname = 0;
482 case REPOKEY_TYPE_MD5:
483 case REPOKEY_TYPE_SHA1:
484 case REPOKEY_TYPE_SHA256:
485 repodata_set_checksum(stubdata->data, SOLVID_META, key->name, key->type, kv->str);
488 return SEARCH_NEXT_KEY;
494 /*******************************************************************************
499 * read repo from .solv file and add it to pool
500 * if stubdata is set, substitute it with read data
501 * (this is used to replace a repodata stub with the real data)
505 repo_add_solv_parent(Repo *repo, FILE *fp, Repodata *parent)
507 Pool *pool = repo->pool;
509 unsigned int numid, numrel, numdir, numsolv;
510 unsigned int numkeys, numschemata;
513 Offset *str; /* map Id -> Offset into string space */
514 char *strsp; /* repo string space */
515 char *sp; /* pointer into string space */
516 Id *idmap; /* map of repo Ids to pool Ids */
518 unsigned int hashmask, h;
524 unsigned int size_idarray;
525 Id *idarraydatap, *idarraydataend;
528 unsigned int solvflags;
529 unsigned int solvversion;
531 Id *schemadata, *schemadatap, *schemadataend;
532 Id *schemata, key, *keyp;
535 int maxsize, allsize;
536 unsigned char *buf, *bufend, *dp, *dps;
539 int needchunk; /* need a new chunk of data */
541 struct _Stringpool *spool;
545 memset(&data, 0, sizeof(data));
548 repopagestore_init(&data.store);
552 if (read_u32(&data) != ('S' << 24 | 'O' << 16 | 'L' << 8 | 'V'))
554 pool_debug(pool, SAT_ERROR, "not a SOLV file\n");
555 return SOLV_ERROR_NOT_SOLV;
557 solvversion = read_u32(&data);
563 pool_debug(pool, SAT_ERROR, "unsupported SOLV version\n");
564 return SOLV_ERROR_UNSUPPORTED;
567 pool_freeidhashes(pool);
569 numid = read_u32(&data);
570 numrel = read_u32(&data);
571 numdir = read_u32(&data);
572 numsolv = read_u32(&data);
573 numkeys = read_u32(&data);
574 numschemata = read_u32(&data);
575 solvflags = read_u32(&data);
577 if (numdir && numdir < 2)
579 pool_debug(pool, SAT_ERROR, "bad number of dirs\n");
580 return SOLV_ERROR_CORRUPT;
587 pool_debug(pool, SAT_ERROR, "relations are forbidden in a sub-repository\n");
588 return SOLV_ERROR_CORRUPT;
590 if (parent->end - parent->start != numsolv)
592 pool_debug(pool, SAT_ERROR, "sub-repository solvable number doesn't match main repository (%d - %d)\n", parent->end - parent->start, numsolv);
593 return SOLV_ERROR_CORRUPT;
597 /******* Part 1: string IDs *****************************************/
599 sizeid = read_u32(&data); /* size of string+Id space */
602 * read strings and Ids
617 spool->stringspace = sat_malloc(7);
618 strcpy(spool->stringspace, "<NULL>");
623 /* alloc string buffer */
624 spool->stringspace = sat_realloc(spool->stringspace, spool->sstrings + sizeid + 1);
625 /* alloc string offsets (Id -> Offset into string space) */
626 spool->strings = sat_realloc2(spool->strings, spool->nstrings + numid, sizeof(Offset));
628 strsp = spool->stringspace;
629 str = spool->strings; /* array of offsets into strsp, indexed by Id */
631 /* point to _BEHIND_ already allocated string/Id space */
632 strsp += spool->sstrings;
636 * read new repo at end of pool
639 if ((solvflags & SOLV_FLAG_PREFIX_POOL) == 0)
641 if (sizeid && fread(strsp, sizeid, 1, fp) != 1)
643 pool_debug(pool, SAT_ERROR, "read error while reading strings\n");
644 return SOLV_ERROR_EOF;
649 unsigned int pfsize = read_u32(&data);
650 char *prefix = sat_malloc(pfsize);
656 if (pfsize && fread(prefix, pfsize, 1, fp) != 1)
658 pool_debug(pool, SAT_ERROR, "read error while reading strings\n");
660 return SOLV_ERROR_EOF;
662 for (i = 1; i < numid; i++)
664 int same = (unsigned char)*pp++;
665 size_t len = strlen(pp) + 1;
666 freesp -= same + len;
669 pool_debug(pool, SAT_ERROR, "overflow while expanding strings\n");
671 return SOLV_ERROR_OVERFLOW;
674 memcpy(dest, old_str, same);
675 memcpy(dest + same, pp, len);
683 pool_debug(pool, SAT_ERROR, "expanding strings size mismatch\n");
684 return SOLV_ERROR_CORRUPT;
687 strsp[sizeid] = 0; /* make string space \0 terminated */
692 /* no shared pool, thus no idmap and no unification */
694 spool->nstrings = numid;
698 /* we need the '' for directories */
699 pool_debug(pool, SAT_ERROR, "store strings don't start with ''\n");
700 return SOLV_ERROR_CORRUPT;
702 for (i = 1; i < spool->nstrings; i++)
704 if (sp >= strsp + sizeid)
706 pool_debug(pool, SAT_ERROR, "not enough strings\n");
707 return SOLV_ERROR_OVERFLOW;
709 str[i] = sp - spool->stringspace;
710 sp += strlen(sp) + 1;
712 spool->sstrings = sp - spool->stringspace;
717 /* alloc id map for name and rel Ids. this maps ids in the solv files
718 * to the ids in our pool */
719 idmap = sat_calloc(numid + numrel, sizeof(Id));
722 * build hashes for all read strings
726 hashmask = mkmask(spool->nstrings + numid);
729 POOL_DEBUG(SAT_DEBUG_STATS, "read %d strings\n", numid);
730 POOL_DEBUG(SAT_DEBUG_STATS, "string hash buckets: %d\n", hashmask + 1);
734 * create hashtable with strings already in pool
737 hashtbl = sat_calloc(hashmask + 1, sizeof(Id));
738 for (i = 1; i < spool->nstrings; i++) /* leave out our dummy zero id */
740 h = strhash(spool->stringspace + spool->strings[i]) & hashmask;
741 hh = HASHCHAIN_START;
743 h = HASHCHAIN_NEXT(h, hh, hashmask);
748 * run over string space, calculate offsets
750 * build id map (maps solv Id -> pool Id)
753 for (i = 1; i < numid; i++)
755 if (sp >= strsp + sizeid)
759 pool_debug(pool, SAT_ERROR, "not enough strings %d %d\n", i, numid);
760 return SOLV_ERROR_OVERFLOW;
762 if (!*sp) /* empty string */
770 h = strhash(sp) & hashmask;
771 hh = HASHCHAIN_START;
777 if (!strcmp(spool->stringspace + spool->strings[id], sp))
778 break; /* existing string */
779 h = HASHCHAIN_NEXT(h, hh, hashmask);
782 /* length == offset to next string */
784 if (id == ID_NULL) /* end of hash chain -> new string */
786 id = spool->nstrings++;
788 str[id] = spool->sstrings; /* save Offset */
789 if (sp != spool->stringspace + spool->sstrings) /* not at end-of-buffer */
790 memmove(spool->stringspace + spool->sstrings, sp, l); /* append to pool buffer */
791 spool->sstrings += l;
793 idmap[i] = id; /* repo relative -> pool relative */
794 sp += l; /* next string */
798 pool_shrink_strings(pool); /* vacuum */
801 /******* Part 2: Relation IDs ***************************************/
811 pool->rels = sat_realloc2(pool->rels, pool->nrels + numrel, sizeof(Reldep));
814 hashmask = mkmask(pool->nrels + numrel);
816 POOL_DEBUG(SAT_DEBUG_STATS, "read %d rels\n", numrel);
817 POOL_DEBUG(SAT_DEBUG_STATS, "rel hash buckets: %d\n", hashmask + 1);
820 * prep hash table with already existing RelDeps
823 hashtbl = sat_calloc(hashmask + 1, sizeof(Id));
824 for (i = 1; i < pool->nrels; i++)
826 h = relhash(ran[i].name, ran[i].evr, ran[i].flags) & hashmask;
827 hh = HASHCHAIN_START;
829 h = HASHCHAIN_NEXT(h, hh, hashmask);
834 * read RelDeps from repo
837 for (i = 0; i < numrel; i++)
839 name = read_id(&data, i + numid); /* read (repo relative) Ids */
840 evr = read_id(&data, i + numid);
841 flags = read_u8(&data);
842 name = idmap[name]; /* map to (pool relative) Ids */
844 h = relhash(name, evr, flags) & hashmask;
845 hh = HASHCHAIN_START;
849 if (id == ID_NULL) /* end of hash chain */
851 if (ran[id].name == name && ran[id].evr == evr && ran[id].flags == flags)
853 h = HASHCHAIN_NEXT(h, hh, hashmask);
855 if (id == ID_NULL) /* new RelDep */
861 ran[id].flags = flags;
863 idmap[i + numid] = MAKERELDEP(id); /* fill Id map */
866 pool_shrink_rels(pool); /* vacuum */
870 /******* Part 3: Dirs ***********************************************/
873 data.dirpool.dirs = sat_malloc2(numdir, sizeof(Id));
874 data.dirpool.ndirs = numdir;
875 data.dirpool.dirs[0] = 0; /* dir 0: virtual root */
876 data.dirpool.dirs[1] = 1; /* dir 1: / */
877 for (i = 2; i < numdir; i++)
879 id = read_id(&data, i + numid);
881 data.dirpool.dirs[i] = -(id - numid);
883 data.dirpool.dirs[i] = idmap[id];
885 data.dirpool.dirs[i] = id;
889 /******* Part 4: Keys ***********************************************/
891 keys = sat_calloc(numkeys, sizeof(*keys));
892 /* keys start at 1 */
893 for (i = 1; i < numkeys; i++)
895 id = read_id(&data, numid);
899 id = str2id(pool, stringpool_id2str(spool, id), 1);
900 type = read_id(&data, numid);
904 type = str2id(pool, stringpool_id2str(spool, type), 1);
905 if (type < REPOKEY_TYPE_VOID || type > REPOKEY_TYPE_FLEXARRAY)
907 pool_debug(pool, SAT_ERROR, "unsupported data type '%s'\n", id2str(pool, type));
908 data.error = SOLV_ERROR_UNSUPPORTED;
909 type = REPOKEY_TYPE_VOID;
913 keys[i].size = read_id(&data, keys[i].type == REPOKEY_TYPE_CONSTANTID ? numid + numrel : 0);
914 keys[i].storage = read_id(&data, 0);
915 if (id >= SOLVABLE_NAME && id <= RPM_RPMDBID)
916 keys[i].storage = KEY_STORAGE_SOLVABLE;
917 else if (keys[i].storage == KEY_STORAGE_SOLVABLE)
918 keys[i].storage = KEY_STORAGE_INCORE;
919 if (keys[i].type == REPOKEY_TYPE_CONSTANTID)
922 keys[i].size = idmap[keys[i].size];
924 keys[i].size = str2id(pool, stringpool_id2str(spool, keys[i].size), 1);
927 fprintf(stderr, "key %d %s %s %d %d\n", i, id2str(pool,id), id2str(pool, keys[i].type),
928 keys[i].size, keys[i].storage);
932 have_xdata = parent ? 1 : 0;
933 for (i = 1; i < numkeys; i++)
934 if (keys[i].storage == KEY_STORAGE_INCORE || keys[i].storage == KEY_STORAGE_VERTICAL_OFFSET)
938 data.nkeys = numkeys;
939 for (i = 1; i < numkeys; i++)
942 data.keybits[(id >> 3) & (sizeof(data.keybits) - 1)] |= 1 << (id & 7);
945 /******* Part 5: Schemata ********************************************/
947 id = read_id(&data, 0);
948 schemadata = sat_calloc(id + 1, sizeof(Id));
949 schemadatap = schemadata + 1;
950 schemadataend = schemadatap + id;
951 schemata = sat_calloc(numschemata, sizeof(Id));
952 for (i = 1; i < numschemata; i++)
954 schemata[i] = schemadatap - schemadata;
955 schemadatap = read_idarray(&data, numid, 0, schemadatap, schemadataend);
957 Id *sp = schemadata + schemata[i];
958 fprintf(stderr, "schema %d:", i);
960 fprintf(stderr, " %d", *sp);
961 fprintf(stderr, "\n");
964 data.schemata = schemata;
965 data.nschemata = numschemata;
966 data.schemadata = schemadata;
967 data.schemadatalen = schemadataend - data.schemadata;
969 /******* Part 6: Data ********************************************/
971 idarraydatap = idarraydataend = 0;
974 maxsize = read_id(&data, 0);
975 allsize = read_id(&data, 0);
976 maxsize += 5; /* so we can read the next schema of an array */
977 if (maxsize > allsize)
980 buf = sat_calloc(maxsize + DATA_READ_CHUNK + 4, 1); /* 4 extra bytes to detect overflows */
985 if (l < DATA_READ_CHUNK)
989 if (!l || fread(buf, l, 1, data.fp) != 1)
991 pool_debug(mypool, SAT_ERROR, "unexpected EOF\n");
992 data.error = SOLV_ERROR_EOF;
999 dp = data_read_id_max(dp, &id, 0, numschemata, &data.error);
1002 incore_add_id(&data, 0); /* XXX? */
1003 incore_add_id(&data, id);
1004 keyp = schemadata + schemata[id];
1005 data.mainschema = id;
1006 for (i = 0; keyp[i]; i++)
1009 data.mainschemaoffsets = sat_calloc(i, sizeof(Id));
1019 printf("key %d at %d\n", key, keyp - 1 - schemadata);
1027 if (s && keydepth == 3)
1029 s++; /* next solvable */
1031 data.incoreoffset[(s - pool->solvables) - data.start] = data.incoredatalen;
1033 id = stack[keydepth - 1];
1036 dp = data_read_id_max(dp, &id, 0, numschemata, &data.error);
1037 incore_add_id(&data, id);
1039 keyp = schemadata + schemata[id];
1046 keyp = schemadata + stack[--keydepth];
1047 nentries = stack[--keydepth];
1049 printf("pop flexarray %d %d\n", keydepth, nentries);
1052 s = 0; /* back from solvables */
1057 data.mainschemaoffsets[keyp - 1 - (schemadata + schemata[data.mainschema])] = data.incoredatalen;
1058 if (keydepth == 0 || needchunk)
1060 int left = bufend - dp;
1061 /* read data chunk to dp */
1066 pool_debug(mypool, SAT_ERROR, "buffer overrun\n");
1067 data.error = SOLV_ERROR_EOF;
1073 memmove(buf, dp, left);
1075 if (l < DATA_READ_CHUNK)
1076 l = DATA_READ_CHUNK;
1079 if (l && fread(buf + left, l, 1, data.fp) != 1)
1081 pool_debug(mypool, SAT_ERROR, "unexpected EOF\n");
1082 data.error = SOLV_ERROR_EOF;
1087 bufend = buf + left;
1088 if (allsize + left < maxsize)
1089 maxsize = allsize + left;
1096 printf("=> %s %s %p\n", id2str(pool, keys[key].name), id2str(pool, keys[key].type), s);
1098 id = keys[key].name;
1099 if (keys[key].storage == KEY_STORAGE_VERTICAL_OFFSET)
1102 dp = data_skip(dp, REPOKEY_TYPE_ID);
1103 dp = data_skip(dp, REPOKEY_TYPE_ID);
1104 incore_add_blob(&data, dps, dp - dps);
1107 switch (keys[key].type)
1109 case REPOKEY_TYPE_ID:
1110 dp = data_read_id_max(dp, &did, idmap, numid + numrel, &data.error);
1111 if (s && id == SOLVABLE_NAME)
1113 else if (s && id == SOLVABLE_ARCH)
1115 else if (s && id == SOLVABLE_EVR)
1117 else if (s && id == SOLVABLE_VENDOR)
1119 else if (keys[key].storage == KEY_STORAGE_INCORE)
1120 incore_add_id(&data, did);
1122 POOL_DEBUG(SAT_DEBUG_STATS, "%s -> %s\n", id2str(pool, id), id2str(pool, did));
1125 case REPOKEY_TYPE_U32:
1126 dp = data_read_u32(dp, &h);
1128 POOL_DEBUG(SAT_DEBUG_STATS, "%s -> %u\n", id2str(pool, id), h);
1130 if (s && id == RPM_RPMDBID)
1133 repo->rpmdbid = repo_sidedata_create(repo, sizeof(Id));
1134 repo->rpmdbid[(s - pool->solvables) - repo->start] = h;
1136 else if (keys[key].storage == KEY_STORAGE_INCORE)
1137 incore_add_u32(&data, h);
1139 case REPOKEY_TYPE_IDARRAY:
1140 case REPOKEY_TYPE_REL_IDARRAY:
1141 if (!s || id < INTERESTED_START || id > INTERESTED_END)
1144 dp = data_skip(dp, REPOKEY_TYPE_IDARRAY);
1145 if (keys[key].storage != KEY_STORAGE_INCORE)
1148 incore_map_idarray(&data, dps, idmap, numid);
1150 incore_add_blob(&data, dps, dp - dps);
1153 ido = idarraydatap - repo->idarraydata;
1154 if (keys[key].type == REPOKEY_TYPE_IDARRAY)
1155 dp = data_read_idarray(dp, &idarraydatap, idmap, numid + numrel, &data.error);
1156 else if (id == SOLVABLE_REQUIRES)
1157 dp = data_read_rel_idarray(dp, &idarraydatap, idmap, numid + numrel, &data.error, SOLVABLE_PREREQMARKER);
1158 else if (id == SOLVABLE_PROVIDES)
1159 dp = data_read_rel_idarray(dp, &idarraydatap, idmap, numid + numrel, &data.error, SOLVABLE_FILEMARKER);
1161 dp = data_read_rel_idarray(dp, &idarraydatap, idmap, numid + numrel, &data.error, 0);
1162 if (idarraydatap > idarraydataend)
1164 pool_debug(pool, SAT_ERROR, "idarray overflow\n");
1165 data.error = SOLV_ERROR_OVERFLOW;
1168 if (id == SOLVABLE_PROVIDES)
1170 else if (id == SOLVABLE_OBSOLETES)
1172 else if (id == SOLVABLE_CONFLICTS)
1174 else if (id == SOLVABLE_REQUIRES)
1176 else if (id == SOLVABLE_RECOMMENDS)
1178 else if (id == SOLVABLE_SUPPLEMENTS)
1179 s->supplements = ido;
1180 else if (id == SOLVABLE_SUGGESTS)
1182 else if (id == SOLVABLE_ENHANCES)
1185 POOL_DEBUG(SAT_DEBUG_STATS, "%s ->\n", id2str(pool, id));
1186 for (; repo->idarraydata[ido]; ido++)
1187 POOL_DEBUG(SAT_DEBUG_STATS," %s\n", dep2str(pool, repo->idarraydata[ido]));
1190 case REPOKEY_TYPE_FIXARRAY:
1191 case REPOKEY_TYPE_FLEXARRAY:
1194 if (keydepth == sizeof(stack)/sizeof(*stack))
1196 pool_debug(pool, SAT_ERROR, "array stack overflow\n");
1197 data.error = SOLV_ERROR_CORRUPT;
1200 stack[keydepth++] = nentries;
1201 stack[keydepth++] = keyp - schemadata;
1202 stack[keydepth++] = 0;
1203 dp = data_read_id(dp, &nentries);
1204 incore_add_id(&data, nentries);
1207 /* zero size array? */
1209 nentries = stack[--keydepth];
1212 if (keydepth == 3 && id == REPOSITORY_SOLVABLES)
1214 /* horray! here come the solvables */
1215 if (nentries != numsolv)
1217 pool_debug(pool, SAT_ERROR, "inconsistent number of solvables: %d %d\n", nentries, numsolv);
1218 data.error = SOLV_ERROR_CORRUPT;
1223 pool_debug(pool, SAT_ERROR, "more than one solvable block\n");
1224 data.error = SOLV_ERROR_CORRUPT;
1228 s = pool_id2solvable(pool, parent->start);
1230 s = pool_id2solvable(pool, repo_add_solvable_block(repo, numsolv));
1231 data.start = s - pool->solvables;
1232 data.end = data.start + numsolv;
1233 repodata_extend_block(&data, data.start, numsolv);
1234 for (i = 1; i < numkeys; i++)
1237 if ((keys[i].type == REPOKEY_TYPE_IDARRAY || keys[i].type == REPOKEY_TYPE_REL_IDARRAY)
1238 && id >= INTERESTED_START && id <= INTERESTED_END)
1239 size_idarray += keys[i].size;
1241 /* allocate needed space in repo */
1242 /* we add maxsize because it is an upper limit for all idarrays, thus we can't overflow */
1243 repo_reserve_ids(repo, 0, size_idarray + maxsize + 1);
1244 idarraydatap = repo->idarraydata + repo->idarraysize;
1245 repo->idarraysize += size_idarray;
1246 idarraydataend = idarraydatap + size_idarray;
1249 data.incoreoffset[(s - pool->solvables) - data.start] = data.incoredatalen;
1252 dp = data_read_id_max(dp, &id, 0, numschemata, &data.error);
1253 incore_add_id(&data, id);
1254 if (keys[key].type == REPOKEY_TYPE_FIXARRAY)
1258 pool_debug(pool, SAT_ERROR, "illegal fixarray\n");
1259 data.error = SOLV_ERROR_CORRUPT;
1261 stack[keydepth - 1] = id;
1263 keyp = schemadata + schemata[id];
1267 dp = data_skip(dp, keys[key].type);
1268 if (keys[key].storage == KEY_STORAGE_INCORE)
1269 incore_add_blob(&data, dps, dp - dps);
1273 /* should shrink idarraydata again */
1277 pool_debug(pool, SAT_ERROR, "unexpected EOF, depth = %d\n", keydepth);
1278 data.error = SOLV_ERROR_CORRUPT;
1284 pool_debug(mypool, SAT_ERROR, "buffer overrun\n");
1285 data.error = SOLV_ERROR_EOF;
1292 /* free solvables */
1293 repo_free_solvable_block(repo, data.start, data.end - data.start, 1);
1295 repo->idarraysize -= size_idarray;
1296 /* free incore data */
1297 data.incoredata = sat_free(data.incoredata);
1298 data.incoredatalen = data.incoredatafree = 0;
1301 if (data.incoredatafree)
1303 /* shrink excess size */
1304 data.incoredata = sat_realloc(data.incoredata, data.incoredatalen);
1305 data.incoredatafree = 0;
1308 for (i = 1; i < numkeys; i++)
1309 if (keys[i].storage == KEY_STORAGE_VERTICAL_OFFSET)
1311 if (i < numkeys && !data.error)
1314 unsigned int pagesize;
1316 /* we have vertical data, make it available */
1317 data.verticaloffset = sat_calloc(numkeys, sizeof(Id));
1318 for (i = 1; i < numkeys; i++)
1319 if (keys[i].storage == KEY_STORAGE_VERTICAL_OFFSET)
1321 data.verticaloffset[i] = fileoffset;
1322 fileoffset += keys[i].size;
1324 data.lastverticaloffset = fileoffset;
1325 pagesize = read_u32(&data);
1326 data.error = repopagestore_read_or_setup_pages(&data.store, data.fp, pagesize, fileoffset);
1330 /* no longer needed */
1338 /* XXX: free repodata? */
1344 /* overwrite stub repodata */
1345 repodata_free(parent);
1350 /* make it available as new repodata */
1351 repo->repodata = sat_realloc2(repo->repodata, repo->nrepodata + 1, sizeof(data));
1352 repo->repodata[repo->nrepodata++] = data;
1355 /* create stub repodata entries for all external */
1356 for (key = 1 ; key < data.nkeys; key++)
1357 if (data.keys[key].name == REPOSITORY_EXTERNAL && data.keys[key].type == REPOKEY_TYPE_FLEXARRAY)
1359 if (key < data.nkeys)
1361 struct create_stub_data stubdata;
1363 memset(&stubdata, 0, sizeof(stubdata));
1364 repodata_search(&data, SOLVID_META, REPOSITORY_EXTERNAL, SEARCH_ARRAYSENTINEL, create_stub_cb, &stubdata);
1370 repo_add_solv(Repo *repo, FILE *fp)
1372 return repo_add_solv_parent(repo, fp, 0);
1376 repodata_load_stub(Repodata *data)
1379 Pool *pool = data->repo->pool;
1380 if (!pool->loadcallback)
1382 data->state = REPODATA_ERROR;
1385 /* so that we can retrieve meta data */
1386 data->state = REPODATA_AVAILABLE;
1387 fp = pool->loadcallback(pool, data, pool->loadcallbackdata);
1390 data->state = REPODATA_ERROR;
1393 if (repo_add_solv_parent(data->repo, fp, data))
1394 data->state = REPODATA_ERROR;
1396 data->state = REPODATA_AVAILABLE;