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
304 incore_add_id(Repodata *data, Id x)
307 /* make sure we have at least 5 bytes free */
308 if (data->incoredatafree < 5)
310 data->incoredata = sat_realloc(data->incoredata, data->incoredatalen + 1024);
311 data->incoredatafree = 1024;
313 dp = data->incoredata + data->incoredatalen;
319 *dp++ = (x >> 28) | 128;
321 *dp++ = (x >> 21) | 128;
322 *dp++ = (x >> 14) | 128;
325 *dp++ = (x >> 7) | 128;
327 data->incoredatafree -= dp - (data->incoredata + data->incoredatalen);
328 data->incoredatalen = dp - data->incoredata;
332 incore_add_blob(Repodata *data, unsigned char *buf, int len)
334 if (data->incoredatafree < len)
336 data->incoredata = sat_realloc(data->incoredata, data->incoredatalen + 1024 + len);
337 data->incoredatafree = 1024 + len;
339 memcpy(data->incoredata + data->incoredatalen, buf, len);
340 data->incoredatafree -= len;
341 data->incoredatalen += len;
345 incore_map_idarray(Repodata *data, unsigned char *dp, Id *map, Id max)
347 /* We have to map the IDs, which might also change
348 the necessary number of bytes, so we can't just copy
349 over the blob and adjust it. */
354 dp = data_read_ideof(dp, &id, &eof);
355 if (max && id >= max)
357 pool_debug(mypool, SAT_ERROR, "incore_map_idarray: id too large (%u/%u)\n", id, max);
358 data->error = SOLV_ERROR_ID_RANGE;
363 id = (id & 63) | ((id & ~63) << 1);
364 incore_add_id(data, eof ? id : id | 64);
371 incore_add_u32(Repodata *data, unsigned int x)
374 /* make sure we have at least 4 bytes free */
375 if (data->incoredatafree < 4)
377 data->incoredata = sat_realloc(data->incoredata, data->incoredatalen + 1024);
378 data->incoredatafree = 1024;
380 dp = data->incoredata + data->incoredatalen;
385 data->incoredatafree -= 4;
386 data->incoredatalen += 4;
391 incore_add_u8(Repodata *data, unsigned int x)
394 /* make sure we have at least 1 byte free */
395 if (data->incoredatafree < 1)
397 data->incoredata = sat_realloc(data->incoredata, data->incoredatalen + 1024);
398 data->incoredatafree = 1024;
400 dp = data->incoredata + data->incoredatalen;
402 data->incoredatafree--;
403 data->incoredatalen++;
408 /*******************************************************************************
409 * callback to create our stub sub-repodatas from the incore data
412 struct create_stub_data {
418 create_stub_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv)
420 struct create_stub_data *stubdata = cbdata;
421 if (key->name == REPOSITORY_EXTERNAL && key->type == REPOKEY_TYPE_FLEXARRAY)
425 repodata_internalize(stubdata->data);
426 if (data->start != data->end)
428 repodata_extend(stubdata->data, data->start);
429 repodata_extend(stubdata->data, data->end - 1);
434 return SEARCH_NEXT_SOLVABLE;
435 stubdata->data = repo_add_repodata(data->repo, 0);
436 stubdata->data->state = REPODATA_STUB;
437 stubdata->data->loadcallback = repodata_load_stub;
441 return SEARCH_NEXT_KEY;
444 case REPOKEY_TYPE_ID:
445 repodata_set_id(stubdata->data, SOLVID_META, key->name, kv->id);
447 case REPOKEY_TYPE_CONSTANTID:
448 repodata_set_constantid(stubdata->data, SOLVID_META, key->name, kv->id);
450 case REPOKEY_TYPE_STR:
451 repodata_set_str(stubdata->data, SOLVID_META, key->name, kv->str);
453 case REPOKEY_TYPE_VOID:
454 repodata_set_void(stubdata->data, SOLVID_META, key->name);
456 case REPOKEY_TYPE_NUM:
457 repodata_set_num(stubdata->data, SOLVID_META, key->name, kv->num);
459 case REPOKEY_TYPE_IDARRAY:
460 repodata_add_idarray(stubdata->data, SOLVID_META, key->name, kv->id);
461 if (key->name == REPOSITORY_KEYS)
463 if (!stubdata->xkeyname)
464 stubdata->xkeyname = kv->id;
469 xkey.name = stubdata->xkeyname;
471 xkey.storage = KEY_STORAGE_INCORE;
473 repodata_key2id(stubdata->data, &xkey, 1);
474 stubdata->xkeyname = 0;
477 stubdata->xkeyname = 0;
480 case REPOKEY_TYPE_MD5:
481 case REPOKEY_TYPE_SHA1:
482 case REPOKEY_TYPE_SHA256:
483 repodata_set_checksum(stubdata->data, SOLVID_META, key->name, key->type, kv->str);
486 return SEARCH_NEXT_KEY;
492 /*******************************************************************************
497 * read repo from .solv file and add it to pool
498 * if stubdata is set, substitute it with read data
499 * (this is used to replace a repodata stub with the real data)
503 repo_add_solv_parent(Repo *repo, FILE *fp, Repodata *parent)
505 Pool *pool = repo->pool;
507 unsigned int numid, numrel, numdir, numsolv;
508 unsigned int numkeys, numschemata;
511 Offset *str; /* map Id -> Offset into string space */
512 char *strsp; /* repo string space */
513 char *sp; /* pointer into string space */
514 Id *idmap; /* map of repo Ids to pool Ids */
516 unsigned int hashmask, h;
522 unsigned int size_idarray;
523 Id *idarraydatap, *idarraydataend;
526 unsigned int solvflags;
527 unsigned int solvversion;
529 Id *schemadata, *schemadatap, *schemadataend;
530 Id *schemata, key, *keyp;
533 int maxsize, allsize;
534 unsigned char *buf, *dp, *dps;
539 struct _Stringpool *spool;
543 memset(&data, 0, sizeof(data));
546 repopagestore_init(&data.store);
550 if (read_u32(&data) != ('S' << 24 | 'O' << 16 | 'L' << 8 | 'V'))
552 pool_debug(pool, SAT_ERROR, "not a SOLV file\n");
553 return SOLV_ERROR_NOT_SOLV;
555 solvversion = read_u32(&data);
561 pool_debug(pool, SAT_ERROR, "unsupported SOLV version\n");
562 return SOLV_ERROR_UNSUPPORTED;
565 pool_freeidhashes(pool);
567 numid = read_u32(&data);
568 numrel = read_u32(&data);
569 numdir = read_u32(&data);
570 numsolv = read_u32(&data);
571 numkeys = read_u32(&data);
572 numschemata = read_u32(&data);
573 solvflags = read_u32(&data);
575 if (numdir && numdir < 2)
577 pool_debug(pool, SAT_ERROR, "bad number of dirs\n");
578 return SOLV_ERROR_CORRUPT;
585 pool_debug(pool, SAT_ERROR, "relations are forbidden in a sub-repository\n");
586 return SOLV_ERROR_CORRUPT;
588 if (parent->end - parent->start != numsolv)
590 pool_debug(pool, SAT_ERROR, "sub-repository solvable number doesn't match main repository (%d - %d)\n", parent->end - parent->start, numsolv);
591 return SOLV_ERROR_CORRUPT;
595 /******* Part 1: string IDs *****************************************/
597 sizeid = read_u32(&data); /* size of string+Id space */
600 * read strings and Ids
615 spool->stringspace = sat_malloc(7);
616 strcpy(spool->stringspace, "<NULL>");
621 /* alloc string buffer */
622 spool->stringspace = sat_realloc(spool->stringspace, spool->sstrings + sizeid + 1);
623 /* alloc string offsets (Id -> Offset into string space) */
624 spool->strings = sat_realloc2(spool->strings, spool->nstrings + numid, sizeof(Offset));
626 strsp = spool->stringspace;
627 str = spool->strings; /* array of offsets into strsp, indexed by Id */
629 /* point to _BEHIND_ already allocated string/Id space */
630 strsp += spool->sstrings;
634 * read new repo at end of pool
637 if ((solvflags & SOLV_FLAG_PREFIX_POOL) == 0)
639 if (sizeid && fread(strsp, sizeid, 1, fp) != 1)
641 pool_debug(pool, SAT_ERROR, "read error while reading strings\n");
642 return SOLV_ERROR_EOF;
647 unsigned int pfsize = read_u32(&data);
648 char *prefix = sat_malloc(pfsize);
654 if (pfsize && fread(prefix, pfsize, 1, fp) != 1)
656 pool_debug(pool, SAT_ERROR, "read error while reading strings\n");
658 return SOLV_ERROR_EOF;
660 for (i = 1; i < numid; i++)
662 int same = (unsigned char)*pp++;
663 size_t len = strlen(pp) + 1;
664 freesp -= same + len;
667 pool_debug(pool, SAT_ERROR, "overflow while expanding strings\n");
669 return SOLV_ERROR_OVERFLOW;
672 memcpy(dest, old_str, same);
673 memcpy(dest + same, pp, len);
681 pool_debug(pool, SAT_ERROR, "expanding strings size mismatch\n");
682 return SOLV_ERROR_CORRUPT;
685 strsp[sizeid] = 0; /* make string space \0 terminated */
690 /* no shared pool, thus no idmap and no unification */
692 spool->nstrings = numid;
696 /* we need the '' for directories */
697 pool_debug(pool, SAT_ERROR, "store strings don't start with ''\n");
698 return SOLV_ERROR_CORRUPT;
700 for (i = 1; i < spool->nstrings; i++)
702 if (sp >= strsp + sizeid)
704 pool_debug(pool, SAT_ERROR, "not enough strings\n");
705 return SOLV_ERROR_OVERFLOW;
707 str[i] = sp - spool->stringspace;
708 sp += strlen(sp) + 1;
710 spool->sstrings = sp - spool->stringspace;
715 /* alloc id map for name and rel Ids. this maps ids in the solv files
716 * to the ids in our pool */
717 idmap = sat_calloc(numid + numrel, sizeof(Id));
720 * build hashes for all read strings
724 hashmask = mkmask(spool->nstrings + numid);
727 POOL_DEBUG(SAT_DEBUG_STATS, "read %d strings\n", numid);
728 POOL_DEBUG(SAT_DEBUG_STATS, "string hash buckets: %d\n", hashmask + 1);
732 * create hashtable with strings already in pool
735 hashtbl = sat_calloc(hashmask + 1, sizeof(Id));
736 for (i = 1; i < spool->nstrings; i++) /* leave out our dummy zero id */
738 h = strhash(spool->stringspace + spool->strings[i]) & hashmask;
739 hh = HASHCHAIN_START;
741 h = HASHCHAIN_NEXT(h, hh, hashmask);
746 * run over string space, calculate offsets
748 * build id map (maps solv Id -> pool Id)
751 for (i = 1; i < numid; i++)
753 if (sp >= strsp + sizeid)
757 pool_debug(pool, SAT_ERROR, "not enough strings %d %d\n", i, numid);
758 return SOLV_ERROR_OVERFLOW;
760 if (!*sp) /* empty string */
768 h = strhash(sp) & hashmask;
769 hh = HASHCHAIN_START;
775 if (!strcmp(spool->stringspace + spool->strings[id], sp))
776 break; /* existing string */
777 h = HASHCHAIN_NEXT(h, hh, hashmask);
780 /* length == offset to next string */
782 if (id == ID_NULL) /* end of hash chain -> new string */
784 id = spool->nstrings++;
786 str[id] = spool->sstrings; /* save Offset */
787 if (sp != spool->stringspace + spool->sstrings) /* not at end-of-buffer */
788 memmove(spool->stringspace + spool->sstrings, sp, l); /* append to pool buffer */
789 spool->sstrings += l;
791 idmap[i] = id; /* repo relative -> pool relative */
792 sp += l; /* next string */
796 pool_shrink_strings(pool); /* vacuum */
799 /******* Part 2: Relation IDs ***************************************/
809 pool->rels = sat_realloc2(pool->rels, pool->nrels + numrel, sizeof(Reldep));
812 hashmask = mkmask(pool->nrels + numrel);
814 POOL_DEBUG(SAT_DEBUG_STATS, "read %d rels\n", numrel);
815 POOL_DEBUG(SAT_DEBUG_STATS, "rel hash buckets: %d\n", hashmask + 1);
818 * prep hash table with already existing RelDeps
821 hashtbl = sat_calloc(hashmask + 1, sizeof(Id));
822 for (i = 1; i < pool->nrels; i++)
824 h = relhash(ran[i].name, ran[i].evr, ran[i].flags) & hashmask;
825 hh = HASHCHAIN_START;
827 h = HASHCHAIN_NEXT(h, hh, hashmask);
832 * read RelDeps from repo
835 for (i = 0; i < numrel; i++)
837 name = read_id(&data, i + numid); /* read (repo relative) Ids */
838 evr = read_id(&data, i + numid);
839 flags = read_u8(&data);
840 name = idmap[name]; /* map to (pool relative) Ids */
842 h = relhash(name, evr, flags) & hashmask;
843 hh = HASHCHAIN_START;
847 if (id == ID_NULL) /* end of hash chain */
849 if (ran[id].name == name && ran[id].evr == evr && ran[id].flags == flags)
851 h = HASHCHAIN_NEXT(h, hh, hashmask);
853 if (id == ID_NULL) /* new RelDep */
859 ran[id].flags = flags;
861 idmap[i + numid] = MAKERELDEP(id); /* fill Id map */
864 pool_shrink_rels(pool); /* vacuum */
868 /******* Part 3: Dirs ***********************************************/
871 data.dirpool.dirs = sat_malloc2(numdir, sizeof(Id));
872 data.dirpool.ndirs = numdir;
873 data.dirpool.dirs[0] = 0; /* dir 0: virtual root */
874 data.dirpool.dirs[1] = 1; /* dir 1: / */
875 for (i = 2; i < numdir; i++)
877 id = read_id(&data, i + numid);
879 data.dirpool.dirs[i] = -(id - numid);
881 data.dirpool.dirs[i] = idmap[id];
883 data.dirpool.dirs[i] = id;
887 /******* Part 4: Keys ***********************************************/
889 keys = sat_calloc(numkeys, sizeof(*keys));
890 /* keys start at 1 */
891 for (i = 1; i < numkeys; i++)
893 id = read_id(&data, numid);
897 id = str2id(pool, stringpool_id2str(spool, id), 1);
898 type = read_id(&data, numid);
902 type = str2id(pool, stringpool_id2str(spool, type), 1);
903 if (type < REPOKEY_TYPE_VOID || type > REPOKEY_TYPE_FLEXARRAY)
905 pool_debug(pool, SAT_ERROR, "unsupported data type '%s'\n", id2str(pool, type));
906 data.error = SOLV_ERROR_UNSUPPORTED;
907 type = REPOKEY_TYPE_VOID;
911 keys[i].size = read_id(&data, keys[i].type == REPOKEY_TYPE_CONSTANTID ? numid + numrel : 0);
912 keys[i].storage = read_id(&data, 0);
913 if (id >= SOLVABLE_NAME && id <= RPM_RPMDBID)
914 keys[i].storage = KEY_STORAGE_SOLVABLE;
915 else if (keys[i].storage == KEY_STORAGE_SOLVABLE)
916 keys[i].storage = KEY_STORAGE_INCORE;
917 if (keys[i].type == REPOKEY_TYPE_CONSTANTID)
920 keys[i].size = idmap[keys[i].size];
922 keys[i].size = str2id(pool, stringpool_id2str(spool, keys[i].size), 1);
925 fprintf(stderr, "key %d %s %s %d %d\n", i, id2str(pool,id), id2str(pool, keys[i].type),
926 keys[i].size, keys[i].storage);
930 have_xdata = parent ? 1 : 0;
931 for (i = 1; i < numkeys; i++)
932 if (keys[i].storage == KEY_STORAGE_INCORE || keys[i].storage == KEY_STORAGE_VERTICAL_OFFSET)
936 data.nkeys = numkeys;
937 for (i = 1; i < numkeys; i++)
940 data.keybits[(id >> 3) & (sizeof(data.keybits) - 1)] |= 1 << (id & 7);
943 /******* Part 5: Schemata ********************************************/
945 id = read_id(&data, 0);
946 schemadata = sat_calloc(id + 1, sizeof(Id));
947 schemadatap = schemadata + 1;
948 schemadataend = schemadatap + id;
949 schemata = sat_calloc(numschemata, sizeof(Id));
950 for (i = 1; i < numschemata; i++)
952 schemata[i] = schemadatap - schemadata;
953 schemadatap = read_idarray(&data, numid, 0, schemadatap, schemadataend);
955 Id *sp = schemadata + schemata[i];
956 fprintf (stderr, "schema %d:", i);
958 fprintf (stderr, " %d", *sp);
959 fprintf (stderr, "\n");
962 data.schemata = schemata;
963 data.nschemata = numschemata;
964 data.schemadata = schemadata;
965 data.schemadatalen = schemadataend - data.schemadata;
967 /******* Part 6: Data ********************************************/
969 idarraydatap = idarraydataend = 0;
972 maxsize = read_id(&data, 0);
973 allsize = read_id(&data, 0);
974 maxsize += 5; /* so we can read the next schema */
975 if (maxsize > allsize)
979 buf = sat_calloc(maxsize + 4, 1);
985 if (!l || fread(buf, l, 1, data.fp) != 1)
987 pool_debug(mypool, SAT_ERROR, "unexpected EOF\n");
988 data.error = SOLV_ERROR_EOF;
995 dp = data_read_id_max(dp, &id, 0, numschemata, &data.error);
998 incore_add_id(&data, 0); /* XXX? */
999 incore_add_id(&data, id);
1000 keyp = schemadata + schemata[id];
1001 data.mainschema = id;
1002 for (i = 0; keyp[i]; i++)
1005 data.mainschemaoffsets = sat_calloc(i, sizeof(Id));
1014 printf("key %d at %d\n", key, keyp - 1 - schemadata);
1020 if (s && keydepth == 2)
1022 s++; /* next solvable */
1024 data.incoreoffset[(s - pool->solvables) - data.start] = data.incoredatalen;
1026 dp = data_read_id_max(dp, &id, 0, numschemata, &data.error);
1027 incore_add_id(&data, id);
1028 keyp = schemadata + schemata[id];
1034 keyp = schemadata + stack[--keydepth];
1035 nentries = stack[--keydepth];
1037 printf("pop flexarray %d %d\n", keydepth, nentries);
1040 s = 0; /* back from solvables */
1047 data.mainschemaoffsets[keyp - 1 - (schemadata + schemata[data.mainschema])] = data.incoredatalen;
1048 /* read data chunk to dp */
1054 pool_debug(mypool, SAT_ERROR, "buffer overrun\n");
1055 data.error = SOLV_ERROR_EOF;
1059 memmove(buf, dp, left);
1063 if (l && fread(buf + left, l, 1, data.fp) != 1)
1065 pool_debug(mypool, SAT_ERROR, "unexpected EOF\n");
1066 data.error = SOLV_ERROR_EOF;
1075 printf("=> %s %s %p\n", id2str(pool, keys[key].name), id2str(pool, keys[key].type), s);
1077 id = keys[key].name;
1078 if (keys[key].storage == KEY_STORAGE_VERTICAL_OFFSET)
1081 dp = data_skip(dp, REPOKEY_TYPE_ID);
1082 dp = data_skip(dp, REPOKEY_TYPE_ID);
1083 incore_add_blob(&data, dps, dp - dps);
1086 switch (keys[key].type)
1088 case REPOKEY_TYPE_ID:
1089 dp = data_read_id_max(dp, &did, idmap, numid + numrel, &data.error);
1090 if (s && id == SOLVABLE_NAME)
1092 else if (s && id == SOLVABLE_ARCH)
1094 else if (s && id == SOLVABLE_EVR)
1096 else if (s && id == SOLVABLE_VENDOR)
1098 else if (keys[key].storage == KEY_STORAGE_INCORE)
1099 incore_add_id(&data, did);
1101 POOL_DEBUG(SAT_DEBUG_STATS, "%s -> %s\n", id2str(pool, id), id2str(pool, did));
1104 case REPOKEY_TYPE_U32:
1105 dp = data_read_u32(dp, &h);
1107 POOL_DEBUG(SAT_DEBUG_STATS, "%s -> %u\n", id2str(pool, id), h);
1109 if (s && id == RPM_RPMDBID)
1112 repo->rpmdbid = repo_sidedata_create(repo, sizeof(Id));
1113 repo->rpmdbid[(s - pool->solvables) - repo->start] = h;
1115 else if (keys[key].storage == KEY_STORAGE_INCORE)
1116 incore_add_u32(&data, h);
1118 case REPOKEY_TYPE_IDARRAY:
1119 case REPOKEY_TYPE_REL_IDARRAY:
1120 if (!s || id < INTERESTED_START || id > INTERESTED_END)
1123 dp = data_skip(dp, REPOKEY_TYPE_IDARRAY);
1124 if (keys[key].storage != KEY_STORAGE_INCORE)
1127 incore_map_idarray(&data, dps, idmap, numid);
1129 incore_add_blob(&data, dps, dp - dps);
1132 ido = idarraydatap - repo->idarraydata;
1133 if (keys[key].type == REPOKEY_TYPE_IDARRAY)
1134 dp = data_read_idarray(dp, &idarraydatap, idmap, numid + numrel, &data.error);
1135 else if (id == SOLVABLE_REQUIRES)
1136 dp = data_read_rel_idarray(dp, &idarraydatap, idmap, numid + numrel, &data.error, SOLVABLE_PREREQMARKER);
1137 else if (id == SOLVABLE_PROVIDES)
1138 dp = data_read_rel_idarray(dp, &idarraydatap, idmap, numid + numrel, &data.error, SOLVABLE_FILEMARKER);
1140 dp = data_read_rel_idarray(dp, &idarraydatap, idmap, numid + numrel, &data.error, 0);
1141 if (idarraydatap > idarraydataend)
1143 pool_debug(pool, SAT_ERROR, "idarray overflow\n");
1144 data.error = SOLV_ERROR_OVERFLOW;
1147 if (id == SOLVABLE_PROVIDES)
1149 else if (id == SOLVABLE_OBSOLETES)
1151 else if (id == SOLVABLE_CONFLICTS)
1153 else if (id == SOLVABLE_REQUIRES)
1155 else if (id == SOLVABLE_RECOMMENDS)
1157 else if (id == SOLVABLE_SUPPLEMENTS)
1158 s->supplements = ido;
1159 else if (id == SOLVABLE_SUGGESTS)
1161 else if (id == SOLVABLE_ENHANCES)
1164 POOL_DEBUG(SAT_DEBUG_STATS, "%s ->\n", id2str(pool, id));
1165 for (; repo->idarraydata[ido]; ido++)
1166 POOL_DEBUG(SAT_DEBUG_STATS," %s\n", dep2str(pool, repo->idarraydata[ido]));
1169 case REPOKEY_TYPE_FLEXARRAY:
1170 if (keydepth == sizeof(stack)/sizeof(*stack))
1172 pool_debug(pool, SAT_ERROR, "flexarray stack overflow\n");
1173 data.error = SOLV_ERROR_CORRUPT;
1176 stack[keydepth++] = nentries;
1177 stack[keydepth++] = keyp - schemadata;
1178 dp = data_read_id(dp, &nentries);
1179 incore_add_id(&data, nentries);
1182 /* zero size array? */
1184 nentries = stack[--keydepth];
1187 if (keydepth == 2 && id == REPOSITORY_SOLVABLES)
1189 /* horray! here come the solvables */
1190 if (nentries != numsolv)
1192 pool_debug(pool, SAT_ERROR, "inconsistent number of solvables: %d %d\n", nentries, numsolv);
1193 data.error = SOLV_ERROR_CORRUPT;
1198 pool_debug(pool, SAT_ERROR, "more than one solvable block\n");
1199 data.error = SOLV_ERROR_CORRUPT;
1203 s = pool_id2solvable(pool, parent->start);
1205 s = pool_id2solvable(pool, repo_add_solvable_block(repo, numsolv));
1206 data.start = s - pool->solvables;
1207 data.end = data.start + numsolv;
1208 repodata_extend_block(&data, data.start, numsolv);
1209 for (i = 1; i < numkeys; i++)
1212 if ((keys[i].type == REPOKEY_TYPE_IDARRAY || keys[i].type == REPOKEY_TYPE_REL_IDARRAY)
1213 && id >= INTERESTED_START && id <= INTERESTED_END)
1214 size_idarray += keys[i].size;
1216 /* allocate needed space in repo */
1217 /* we add maxsize because it is an upper limit for all idarrays, thus we can't overflow */
1218 repo_reserve_ids(repo, 0, size_idarray + maxsize + 1);
1219 idarraydatap = repo->idarraydata + repo->idarraysize;
1220 repo->idarraysize += size_idarray;
1221 idarraydataend = idarraydatap + size_idarray;
1224 data.incoreoffset[(s - pool->solvables) - data.start] = data.incoredatalen;
1227 dp = data_read_id_max(dp, &id, 0, numschemata, &data.error);
1228 incore_add_id(&data, id);
1229 keyp = schemadata + schemata[id];
1233 dp = data_skip(dp, keys[key].type);
1234 if (keys[key].storage == KEY_STORAGE_INCORE)
1235 incore_add_blob(&data, dps, dp - dps);
1239 /* should shrink idarraydata again */
1243 pool_debug(pool, SAT_ERROR, "unexpected EOF, depth = %d\n", keydepth);
1244 data.error = SOLV_ERROR_CORRUPT;
1251 pool_debug(mypool, SAT_ERROR, "buffer overrun\n");
1252 data.error = SOLV_ERROR_EOF;
1259 /* free solvables */
1260 repo_free_solvable_block(repo, data.start, data.end - data.start, 1);
1262 repo->idarraysize -= size_idarray;
1263 /* free incore data */
1264 data.incoredata = sat_free(data.incoredata);
1265 data.incoredatalen = data.incoredatafree = 0;
1268 if (data.incoredatafree)
1270 /* shrink excess size */
1271 data.incoredata = sat_realloc(data.incoredata, data.incoredatalen);
1272 data.incoredatafree = 0;
1275 for (i = 1; i < numkeys; i++)
1276 if (keys[i].storage == KEY_STORAGE_VERTICAL_OFFSET)
1278 if (i < numkeys && !data.error)
1281 unsigned int pagesize;
1283 /* we have vertical data, make it available */
1284 data.verticaloffset = sat_calloc(numkeys, sizeof(Id));
1285 for (i = 1; i < numkeys; i++)
1286 if (keys[i].storage == KEY_STORAGE_VERTICAL_OFFSET)
1288 data.verticaloffset[i] = fileoffset;
1289 fileoffset += keys[i].size;
1291 data.lastverticaloffset = fileoffset;
1292 pagesize = read_u32(&data);
1293 data.error = repopagestore_read_or_setup_pages(&data.store, data.fp, pagesize, fileoffset);
1297 /* no longer needed */
1305 /* XXX: free repodata? */
1311 /* overwrite stub repodata */
1312 repodata_free(parent);
1317 /* make it available as new repodata */
1318 repo->repodata = sat_realloc2(repo->repodata, repo->nrepodata + 1, sizeof(data));
1319 repo->repodata[repo->nrepodata++] = data;
1322 /* create stub repodata entries for all external */
1323 for (key = 1 ; key < data.nkeys; key++)
1324 if (data.keys[key].name == REPOSITORY_EXTERNAL && data.keys[key].type == REPOKEY_TYPE_FLEXARRAY)
1326 if (key < data.nkeys)
1328 struct create_stub_data stubdata;
1330 memset(&stubdata, 0, sizeof(stubdata));
1331 repodata_search(&data, SOLVID_META, REPOSITORY_EXTERNAL, create_stub_cb, &stubdata);
1337 repo_add_solv(Repo *repo, FILE *fp)
1339 return repo_add_solv_parent(repo, fp, 0);
1343 repodata_load_stub(Repodata *data)
1346 Pool *pool = data->repo->pool;
1347 if (!pool->loadcallback)
1349 data->state = REPODATA_ERROR;
1352 /* so that we can retrieve meta data */
1353 data->state = REPODATA_AVAILABLE;
1354 fp = pool->loadcallback(pool, data, pool->loadcallbackdata);
1357 data->state = REPODATA_ERROR;
1360 if (repo_add_solv_parent(data->repo, fp, data))
1361 data->state = REPODATA_ERROR;
1363 data->state = REPODATA_AVAILABLE;