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
305 incore_add_id(Repodata *data, Id x)
308 /* make sure we have at least 5 bytes free */
309 if (data->incoredatafree < 5)
311 data->incoredata = sat_realloc(data->incoredata, data->incoredatalen + INCORE_ADD_CHUNK);
312 data->incoredatafree = INCORE_ADD_CHUNK;
314 dp = data->incoredata + data->incoredatalen;
320 *dp++ = (x >> 28) | 128;
322 *dp++ = (x >> 21) | 128;
323 *dp++ = (x >> 14) | 128;
326 *dp++ = (x >> 7) | 128;
328 data->incoredatafree -= dp - (data->incoredata + data->incoredatalen);
329 data->incoredatalen = dp - data->incoredata;
333 incore_add_blob(Repodata *data, unsigned char *buf, int len)
335 if (data->incoredatafree < len)
337 data->incoredata = sat_realloc(data->incoredata, data->incoredatalen + INCORE_ADD_CHUNK + len);
338 data->incoredatafree = INCORE_ADD_CHUNK + len;
340 memcpy(data->incoredata + data->incoredatalen, buf, len);
341 data->incoredatafree -= len;
342 data->incoredatalen += len;
346 incore_map_idarray(Repodata *data, unsigned char *dp, Id *map, Id max)
348 /* We have to map the IDs, which might also change
349 the necessary number of bytes, so we can't just copy
350 over the blob and adjust it. */
355 dp = data_read_ideof(dp, &id, &eof);
356 if (max && id >= max)
358 pool_debug(mypool, SAT_ERROR, "incore_map_idarray: id too large (%u/%u)\n", id, max);
359 data->error = SOLV_ERROR_ID_RANGE;
364 id = (id & 63) | ((id & ~63) << 1);
365 incore_add_id(data, eof ? id : id | 64);
372 incore_add_u32(Repodata *data, unsigned int x)
375 /* make sure we have at least 4 bytes free */
376 if (data->incoredatafree < 4)
378 data->incoredata = sat_realloc(data->incoredata, data->incoredatalen + INCORE_ADD_CHUNK);
379 data->incoredatafree = INCORE_ADD_CHUNK;
381 dp = data->incoredata + data->incoredatalen;
386 data->incoredatafree -= 4;
387 data->incoredatalen += 4;
392 incore_add_u8(Repodata *data, unsigned int x)
395 /* make sure we have at least 1 byte free */
396 if (data->incoredatafree < 1)
398 data->incoredata = sat_realloc(data->incoredata, data->incoredatalen + 1024);
399 data->incoredatafree = 1024;
401 dp = data->incoredata + data->incoredatalen;
403 data->incoredatafree--;
404 data->incoredatalen++;
409 /*******************************************************************************
410 * callback to create our stub sub-repodatas from the incore data
413 struct create_stub_data {
419 create_stub_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv)
421 struct create_stub_data *stubdata = cbdata;
422 if (key->name == REPOSITORY_EXTERNAL && key->type == REPOKEY_TYPE_FLEXARRAY)
426 repodata_internalize(stubdata->data);
427 if (data->start != data->end)
429 repodata_extend(stubdata->data, data->start);
430 repodata_extend(stubdata->data, data->end - 1);
435 return SEARCH_NEXT_SOLVABLE;
436 stubdata->data = repo_add_repodata(data->repo, 0);
437 stubdata->data->state = REPODATA_STUB;
438 stubdata->data->loadcallback = repodata_load_stub;
439 return SEARCH_ENTERSUB;
442 return SEARCH_NEXT_KEY;
445 case REPOKEY_TYPE_ID:
446 repodata_set_id(stubdata->data, SOLVID_META, key->name, kv->id);
448 case REPOKEY_TYPE_CONSTANTID:
449 repodata_set_constantid(stubdata->data, SOLVID_META, key->name, kv->id);
451 case REPOKEY_TYPE_STR:
452 repodata_set_str(stubdata->data, SOLVID_META, key->name, kv->str);
454 case REPOKEY_TYPE_VOID:
455 repodata_set_void(stubdata->data, SOLVID_META, key->name);
457 case REPOKEY_TYPE_NUM:
458 repodata_set_num(stubdata->data, SOLVID_META, key->name, kv->num);
460 case REPOKEY_TYPE_IDARRAY:
461 repodata_add_idarray(stubdata->data, SOLVID_META, key->name, kv->id);
462 if (key->name == REPOSITORY_KEYS)
464 if (!stubdata->xkeyname)
465 stubdata->xkeyname = kv->id;
470 xkey.name = stubdata->xkeyname;
472 xkey.storage = KEY_STORAGE_INCORE;
474 repodata_key2id(stubdata->data, &xkey, 1);
475 stubdata->xkeyname = 0;
478 stubdata->xkeyname = 0;
481 case REPOKEY_TYPE_MD5:
482 case REPOKEY_TYPE_SHA1:
483 case REPOKEY_TYPE_SHA256:
484 repodata_set_checksum(stubdata->data, SOLVID_META, key->name, key->type, kv->str);
487 return SEARCH_NEXT_KEY;
493 /*******************************************************************************
498 * read repo from .solv file and add it to pool
499 * if stubdata is set, substitute it with read data
500 * (this is used to replace a repodata stub with the real data)
504 repo_add_solv_parent(Repo *repo, FILE *fp, Repodata *parent)
506 Pool *pool = repo->pool;
508 unsigned int numid, numrel, numdir, numsolv;
509 unsigned int numkeys, numschemata;
512 Offset *str; /* map Id -> Offset into string space */
513 char *strsp; /* repo string space */
514 char *sp; /* pointer into string space */
515 Id *idmap; /* map of repo Ids to pool Ids */
517 unsigned int hashmask, h;
523 unsigned int size_idarray;
524 Id *idarraydatap, *idarraydataend;
527 unsigned int solvflags;
528 unsigned int solvversion;
530 Id *schemadata, *schemadatap, *schemadataend;
531 Id *schemata, key, *keyp;
534 int maxsize, allsize;
535 unsigned char *buf, *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 */
977 if (maxsize > allsize)
981 buf = sat_calloc(maxsize + 4, 1);
987 if (!l || fread(buf, l, 1, data.fp) != 1)
989 pool_debug(mypool, SAT_ERROR, "unexpected EOF\n");
990 data.error = SOLV_ERROR_EOF;
997 dp = data_read_id_max(dp, &id, 0, numschemata, &data.error);
1000 incore_add_id(&data, 0); /* XXX? */
1001 incore_add_id(&data, id);
1002 keyp = schemadata + schemata[id];
1003 data.mainschema = id;
1004 for (i = 0; keyp[i]; i++)
1007 data.mainschemaoffsets = sat_calloc(i, sizeof(Id));
1017 printf("key %d at %d\n", key, keyp - 1 - schemadata);
1025 if (s && keydepth == 2)
1027 s++; /* next solvable */
1029 data.incoreoffset[(s - pool->solvables) - data.start] = data.incoredatalen;
1031 dp = data_read_id_max(dp, &id, 0, numschemata, &data.error);
1032 incore_add_id(&data, id);
1033 keyp = schemadata + schemata[id];
1039 keyp = schemadata + stack[--keydepth];
1040 nentries = stack[--keydepth];
1042 printf("pop flexarray %d %d\n", keydepth, nentries);
1045 s = 0; /* back from solvables */
1050 data.mainschemaoffsets[keyp - 1 - (schemadata + schemata[data.mainschema])] = data.incoredatalen;
1053 /* read data chunk to dp */
1059 pool_debug(mypool, SAT_ERROR, "buffer overrun\n");
1060 data.error = SOLV_ERROR_EOF;
1064 memmove(buf, dp, left);
1068 if (l && fread(buf + left, l, 1, data.fp) != 1)
1070 pool_debug(mypool, SAT_ERROR, "unexpected EOF\n");
1071 data.error = SOLV_ERROR_EOF;
1081 printf("=> %s %s %p\n", id2str(pool, keys[key].name), id2str(pool, keys[key].type), s);
1083 id = keys[key].name;
1084 if (keys[key].storage == KEY_STORAGE_VERTICAL_OFFSET)
1087 dp = data_skip(dp, REPOKEY_TYPE_ID);
1088 dp = data_skip(dp, REPOKEY_TYPE_ID);
1089 incore_add_blob(&data, dps, dp - dps);
1092 switch (keys[key].type)
1094 case REPOKEY_TYPE_ID:
1095 dp = data_read_id_max(dp, &did, idmap, numid + numrel, &data.error);
1096 if (s && id == SOLVABLE_NAME)
1098 else if (s && id == SOLVABLE_ARCH)
1100 else if (s && id == SOLVABLE_EVR)
1102 else if (s && id == SOLVABLE_VENDOR)
1104 else if (keys[key].storage == KEY_STORAGE_INCORE)
1105 incore_add_id(&data, did);
1107 POOL_DEBUG(SAT_DEBUG_STATS, "%s -> %s\n", id2str(pool, id), id2str(pool, did));
1110 case REPOKEY_TYPE_U32:
1111 dp = data_read_u32(dp, &h);
1113 POOL_DEBUG(SAT_DEBUG_STATS, "%s -> %u\n", id2str(pool, id), h);
1115 if (s && id == RPM_RPMDBID)
1118 repo->rpmdbid = repo_sidedata_create(repo, sizeof(Id));
1119 repo->rpmdbid[(s - pool->solvables) - repo->start] = h;
1121 else if (keys[key].storage == KEY_STORAGE_INCORE)
1122 incore_add_u32(&data, h);
1124 case REPOKEY_TYPE_IDARRAY:
1125 case REPOKEY_TYPE_REL_IDARRAY:
1126 if (!s || id < INTERESTED_START || id > INTERESTED_END)
1129 dp = data_skip(dp, REPOKEY_TYPE_IDARRAY);
1130 if (keys[key].storage != KEY_STORAGE_INCORE)
1133 incore_map_idarray(&data, dps, idmap, numid);
1135 incore_add_blob(&data, dps, dp - dps);
1138 ido = idarraydatap - repo->idarraydata;
1139 if (keys[key].type == REPOKEY_TYPE_IDARRAY)
1140 dp = data_read_idarray(dp, &idarraydatap, idmap, numid + numrel, &data.error);
1141 else if (id == SOLVABLE_REQUIRES)
1142 dp = data_read_rel_idarray(dp, &idarraydatap, idmap, numid + numrel, &data.error, SOLVABLE_PREREQMARKER);
1143 else if (id == SOLVABLE_PROVIDES)
1144 dp = data_read_rel_idarray(dp, &idarraydatap, idmap, numid + numrel, &data.error, SOLVABLE_FILEMARKER);
1146 dp = data_read_rel_idarray(dp, &idarraydatap, idmap, numid + numrel, &data.error, 0);
1147 if (idarraydatap > idarraydataend)
1149 pool_debug(pool, SAT_ERROR, "idarray overflow\n");
1150 data.error = SOLV_ERROR_OVERFLOW;
1153 if (id == SOLVABLE_PROVIDES)
1155 else if (id == SOLVABLE_OBSOLETES)
1157 else if (id == SOLVABLE_CONFLICTS)
1159 else if (id == SOLVABLE_REQUIRES)
1161 else if (id == SOLVABLE_RECOMMENDS)
1163 else if (id == SOLVABLE_SUPPLEMENTS)
1164 s->supplements = ido;
1165 else if (id == SOLVABLE_SUGGESTS)
1167 else if (id == SOLVABLE_ENHANCES)
1170 POOL_DEBUG(SAT_DEBUG_STATS, "%s ->\n", id2str(pool, id));
1171 for (; repo->idarraydata[ido]; ido++)
1172 POOL_DEBUG(SAT_DEBUG_STATS," %s\n", dep2str(pool, repo->idarraydata[ido]));
1175 case REPOKEY_TYPE_FLEXARRAY:
1176 if (keydepth == sizeof(stack)/sizeof(*stack))
1178 pool_debug(pool, SAT_ERROR, "flexarray stack overflow\n");
1179 data.error = SOLV_ERROR_CORRUPT;
1182 stack[keydepth++] = nentries;
1183 stack[keydepth++] = keyp - schemadata;
1184 dp = data_read_id(dp, &nentries);
1185 incore_add_id(&data, nentries);
1188 /* zero size array? */
1190 nentries = stack[--keydepth];
1193 if (keydepth == 2 && id == REPOSITORY_SOLVABLES)
1195 /* horray! here come the solvables */
1196 if (nentries != numsolv)
1198 pool_debug(pool, SAT_ERROR, "inconsistent number of solvables: %d %d\n", nentries, numsolv);
1199 data.error = SOLV_ERROR_CORRUPT;
1204 pool_debug(pool, SAT_ERROR, "more than one solvable block\n");
1205 data.error = SOLV_ERROR_CORRUPT;
1209 s = pool_id2solvable(pool, parent->start);
1211 s = pool_id2solvable(pool, repo_add_solvable_block(repo, numsolv));
1212 data.start = s - pool->solvables;
1213 data.end = data.start + numsolv;
1214 repodata_extend_block(&data, data.start, numsolv);
1215 for (i = 1; i < numkeys; i++)
1218 if ((keys[i].type == REPOKEY_TYPE_IDARRAY || keys[i].type == REPOKEY_TYPE_REL_IDARRAY)
1219 && id >= INTERESTED_START && id <= INTERESTED_END)
1220 size_idarray += keys[i].size;
1222 /* allocate needed space in repo */
1223 /* we add maxsize because it is an upper limit for all idarrays, thus we can't overflow */
1224 repo_reserve_ids(repo, 0, size_idarray + maxsize + 1);
1225 idarraydatap = repo->idarraydata + repo->idarraysize;
1226 repo->idarraysize += size_idarray;
1227 idarraydataend = idarraydatap + size_idarray;
1230 data.incoreoffset[(s - pool->solvables) - data.start] = data.incoredatalen;
1233 dp = data_read_id_max(dp, &id, 0, numschemata, &data.error);
1234 incore_add_id(&data, id);
1235 keyp = schemadata + schemata[id];
1239 dp = data_skip(dp, keys[key].type);
1240 if (keys[key].storage == KEY_STORAGE_INCORE)
1241 incore_add_blob(&data, dps, dp - dps);
1245 /* should shrink idarraydata again */
1249 pool_debug(pool, SAT_ERROR, "unexpected EOF, depth = %d\n", keydepth);
1250 data.error = SOLV_ERROR_CORRUPT;
1257 pool_debug(mypool, SAT_ERROR, "buffer overrun\n");
1258 data.error = SOLV_ERROR_EOF;
1265 /* free solvables */
1266 repo_free_solvable_block(repo, data.start, data.end - data.start, 1);
1268 repo->idarraysize -= size_idarray;
1269 /* free incore data */
1270 data.incoredata = sat_free(data.incoredata);
1271 data.incoredatalen = data.incoredatafree = 0;
1274 if (data.incoredatafree)
1276 /* shrink excess size */
1277 data.incoredata = sat_realloc(data.incoredata, data.incoredatalen);
1278 data.incoredatafree = 0;
1281 for (i = 1; i < numkeys; i++)
1282 if (keys[i].storage == KEY_STORAGE_VERTICAL_OFFSET)
1284 if (i < numkeys && !data.error)
1287 unsigned int pagesize;
1289 /* we have vertical data, make it available */
1290 data.verticaloffset = sat_calloc(numkeys, sizeof(Id));
1291 for (i = 1; i < numkeys; i++)
1292 if (keys[i].storage == KEY_STORAGE_VERTICAL_OFFSET)
1294 data.verticaloffset[i] = fileoffset;
1295 fileoffset += keys[i].size;
1297 data.lastverticaloffset = fileoffset;
1298 pagesize = read_u32(&data);
1299 data.error = repopagestore_read_or_setup_pages(&data.store, data.fp, pagesize, fileoffset);
1303 /* no longer needed */
1311 /* XXX: free repodata? */
1317 /* overwrite stub repodata */
1318 repodata_free(parent);
1323 /* make it available as new repodata */
1324 repo->repodata = sat_realloc2(repo->repodata, repo->nrepodata + 1, sizeof(data));
1325 repo->repodata[repo->nrepodata++] = data;
1328 /* create stub repodata entries for all external */
1329 for (key = 1 ; key < data.nkeys; key++)
1330 if (data.keys[key].name == REPOSITORY_EXTERNAL && data.keys[key].type == REPOKEY_TYPE_FLEXARRAY)
1332 if (key < data.nkeys)
1334 struct create_stub_data stubdata;
1336 memset(&stubdata, 0, sizeof(stubdata));
1337 repodata_search(&data, SOLVID_META, REPOSITORY_EXTERNAL, SEARCH_ARRAYSENTINEL, create_stub_cb, &stubdata);
1343 repo_add_solv(Repo *repo, FILE *fp)
1345 return repo_add_solv_parent(repo, fp, 0);
1349 repodata_load_stub(Repodata *data)
1352 Pool *pool = data->repo->pool;
1353 if (!pool->loadcallback)
1355 data->state = REPODATA_ERROR;
1358 /* so that we can retrieve meta data */
1359 data->state = REPODATA_AVAILABLE;
1360 fp = pool->loadcallback(pool, data, pool->loadcallbackdata);
1363 data->state = REPODATA_ERROR;
1366 if (repo_add_solv_parent(data->repo, fp, data))
1367 data->state = REPODATA_ERROR;
1369 data->state = REPODATA_AVAILABLE;