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... */
46 /*******************************************************************************
47 * functions to extract data from a file handle
55 read_u32(Repodata *data)
62 for (i = 0; i < 4; i++)
67 pool_debug(mypool, SAT_ERROR, "unexpected EOF\n");
68 data->error = SOLV_ERROR_EOF;
82 read_u8(Repodata *data)
91 pool_debug(mypool, SAT_ERROR, "unexpected EOF\n");
92 data->error = SOLV_ERROR_EOF;
104 read_id(Repodata *data, Id max)
111 for (i = 0; i < 5; i++)
116 pool_debug(mypool, SAT_ERROR, "unexpected EOF\n");
117 data->error = SOLV_ERROR_EOF;
125 pool_debug(mypool, SAT_ERROR, "read_id: id too large (%u/%u)\n", x, max);
126 data->error = SOLV_ERROR_ID_RANGE;
131 x = (x << 7) ^ c ^ 128;
133 pool_debug(mypool, SAT_ERROR, "read_id: id too long\n");
134 data->error = SOLV_ERROR_CORRUPT;
140 read_idarray(Repodata *data, Id max, Id *map, Id *store, Id *end)
152 pool_debug(mypool, SAT_ERROR, "unexpected EOF\n");
153 data->error = SOLV_ERROR_EOF;
158 x = (x << 7) ^ c ^ 128;
161 x = (x << 6) | (c & 63);
164 pool_debug(mypool, SAT_ERROR, "read_idarray: id too large (%u/%u)\n", x, max);
165 data->error = SOLV_ERROR_ID_RANGE;
172 pool_debug(mypool, SAT_ERROR, "read_idarray: array overflow\n");
178 if (x == 0) /* already have trailing zero? */
182 pool_debug(mypool, SAT_ERROR, "read_idarray: array overflow\n");
183 data->error = SOLV_ERROR_OVERFLOW;
194 /*******************************************************************************
195 * functions to extract data from memory
202 static inline unsigned char *
203 data_read_id_max(unsigned char *dp, Id *ret, Id *map, int max, int *error)
206 dp = data_read_id(dp, &x);
209 pool_debug(mypool, SAT_ERROR, "data_read_idarray: id too large (%u/%u)\n", x, max);
210 *error = SOLV_ERROR_ID_RANGE;
213 *ret = map ? map[x] : x;
218 data_read_idarray(unsigned char *dp, Id **storep, Id *map, int max, int *error)
229 x = (x << 7) ^ c ^ 128;
232 x = (x << 6) | (c & 63);
235 pool_debug(mypool, SAT_ERROR, "data_read_idarray: id too large (%u/%u)\n", x, max);
236 *error = SOLV_ERROR_ID_RANGE;
250 data_read_rel_idarray(unsigned char *dp, Id **storep, Id *map, int max, int *error, Id marker)
262 x = (x << 7) ^ c ^ 128;
265 x = (x << 6) | (c & 63);
279 pool_debug(mypool, SAT_ERROR, "data_read_rel_idarray: id too large (%u/%u)\n", x, max);
280 *error = SOLV_ERROR_ID_RANGE;
283 *store++ = map ? map[x] : x;
296 /*******************************************************************************
297 * functions to add data to our incore memory space
300 #define INCORE_ADD_CHUNK 8192
301 #define DATA_READ_CHUNK 8192
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 + INCORE_ADD_CHUNK);
311 data->incoredatafree = INCORE_ADD_CHUNK;
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 + INCORE_ADD_CHUNK + len);
337 data->incoredatafree = INCORE_ADD_CHUNK + 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 + INCORE_ADD_CHUNK);
378 data->incoredatafree = INCORE_ADD_CHUNK;
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 /*******************************************************************************
413 * read repo from .solv file and add it to pool
417 repo_add_solv_flags(Repo *repo, FILE *fp, int flags)
419 Pool *pool = repo->pool;
421 unsigned int numid, numrel, numdir, numsolv;
422 unsigned int numkeys, numschemata;
425 Offset *str; /* map Id -> Offset into string space */
426 char *strsp; /* repo string space */
427 char *sp; /* pointer into string space */
428 Id *idmap; /* map of repo Ids to pool Ids */
430 unsigned int hashmask, h;
436 unsigned int size_idarray;
437 Id *idarraydatap, *idarraydataend;
440 unsigned int solvflags;
441 unsigned int solvversion;
443 Id *schemadata, *schemadatap, *schemadataend;
444 Id *schemata, key, *keyp;
447 int maxsize, allsize;
448 unsigned char *buf, *bufend, *dp, *dps;
451 int needchunk; /* need a new chunk of data */
454 struct _Stringpool *spool;
456 Repodata *parent = 0;
461 if ((flags & REPO_USE_LOADING) != 0)
463 /* this is a stub replace operation */
464 flags |= REPO_EXTEND_SOLVABLES;
465 /* use REPO_REUSE_REPODATA hack so that the old repodata is kept */
466 parent = repo_add_repodata(repo, flags | REPO_REUSE_REPODATA);
469 memset(&data, 0, sizeof(data));
472 repopagestore_init(&data.store);
476 if (read_u32(&data) != ('S' << 24 | 'O' << 16 | 'L' << 8 | 'V'))
478 pool_debug(pool, SAT_ERROR, "not a SOLV file\n");
479 return SOLV_ERROR_NOT_SOLV;
481 solvversion = read_u32(&data);
487 pool_debug(pool, SAT_ERROR, "unsupported SOLV version\n");
488 return SOLV_ERROR_UNSUPPORTED;
491 pool_freeidhashes(pool);
493 numid = read_u32(&data);
494 numrel = read_u32(&data);
495 numdir = read_u32(&data);
496 numsolv = read_u32(&data);
497 numkeys = read_u32(&data);
498 numschemata = read_u32(&data);
499 solvflags = read_u32(&data);
501 if (numdir && numdir < 2)
503 pool_debug(pool, SAT_ERROR, "bad number of dirs\n");
504 return SOLV_ERROR_CORRUPT;
507 if (numrel && (flags & REPO_LOCALPOOL) != 0)
509 pool_debug(pool, SAT_ERROR, "relations are forbidden in a local pool\n");
510 return SOLV_ERROR_CORRUPT;
512 if (parent && numsolv)
514 /* make sure that we exactly replace the stub repodata */
515 if (parent->end - parent->start != numsolv)
517 pool_debug(pool, SAT_ERROR, "sub-repository solvable number does not match main repository (%d - %d)\n", parent->end - parent->start, numsolv);
518 return SOLV_ERROR_CORRUPT;
520 for (i = 0; i < numsolv; i++)
521 if (pool->solvables[parent->start + i].repo != repo)
523 pool_debug(pool, SAT_ERROR, "main repository contains holes\n");
524 return SOLV_ERROR_CORRUPT;
528 /******* Part 1: string IDs *****************************************/
530 sizeid = read_u32(&data); /* size of string+Id space */
533 * read strings and Ids
542 if (!(flags & REPO_LOCALPOOL))
548 spool->stringspace = sat_malloc(7);
549 strcpy(spool->stringspace, "<NULL>");
554 /* alloc string buffer */
555 spool->stringspace = sat_realloc(spool->stringspace, spool->sstrings + sizeid + 1);
556 /* alloc string offsets (Id -> Offset into string space) */
557 spool->strings = sat_realloc2(spool->strings, spool->nstrings + numid, sizeof(Offset));
559 strsp = spool->stringspace;
560 str = spool->strings; /* array of offsets into strsp, indexed by Id */
562 /* point to _BEHIND_ already allocated string/Id space */
563 strsp += spool->sstrings;
567 * read new repo at end of pool
570 if ((solvflags & SOLV_FLAG_PREFIX_POOL) == 0)
572 if (sizeid && fread(strsp, sizeid, 1, fp) != 1)
574 pool_debug(pool, SAT_ERROR, "read error while reading strings\n");
575 return SOLV_ERROR_EOF;
580 unsigned int pfsize = read_u32(&data);
581 char *prefix = sat_malloc(pfsize);
587 if (pfsize && fread(prefix, pfsize, 1, fp) != 1)
589 pool_debug(pool, SAT_ERROR, "read error while reading strings\n");
591 return SOLV_ERROR_EOF;
593 for (i = 1; i < numid; i++)
595 int same = (unsigned char)*pp++;
596 size_t len = strlen(pp) + 1;
597 freesp -= same + len;
600 pool_debug(pool, SAT_ERROR, "overflow while expanding strings\n");
602 return SOLV_ERROR_OVERFLOW;
605 memcpy(dest, old_str, same);
606 memcpy(dest + same, pp, len);
614 pool_debug(pool, SAT_ERROR, "expanding strings size mismatch\n");
615 return SOLV_ERROR_CORRUPT;
618 strsp[sizeid] = 0; /* make string space \0 terminated */
621 if ((flags & REPO_LOCALPOOL) != 0)
623 /* no shared pool, thus no idmap and no unification */
625 spool->nstrings = numid;
629 /* we need the '' for directories */
630 pool_debug(pool, SAT_ERROR, "store strings don't start with ''\n");
631 return SOLV_ERROR_CORRUPT;
633 for (i = 1; i < spool->nstrings; i++)
635 if (sp >= strsp + sizeid)
637 pool_debug(pool, SAT_ERROR, "not enough strings\n");
638 return SOLV_ERROR_OVERFLOW;
640 str[i] = sp - spool->stringspace;
641 sp += strlen(sp) + 1;
643 spool->sstrings = sp - spool->stringspace;
648 /* alloc id map for name and rel Ids. this maps ids in the solv files
649 * to the ids in our pool */
650 idmap = sat_calloc(numid + numrel, sizeof(Id));
653 * build hashes for all read strings
657 hashmask = mkmask(spool->nstrings + numid);
660 POOL_DEBUG(SAT_DEBUG_STATS, "read %d strings\n", numid);
661 POOL_DEBUG(SAT_DEBUG_STATS, "string hash buckets: %d\n", hashmask + 1);
665 * create hashtable with strings already in pool
668 hashtbl = sat_calloc(hashmask + 1, sizeof(Id));
669 for (i = 1; i < spool->nstrings; i++) /* leave out our dummy zero id */
671 h = strhash(spool->stringspace + spool->strings[i]) & hashmask;
672 hh = HASHCHAIN_START;
674 h = HASHCHAIN_NEXT(h, hh, hashmask);
679 * run over string space, calculate offsets
681 * build id map (maps solv Id -> pool Id)
684 for (i = 1; i < numid; i++)
686 if (sp >= strsp + sizeid)
690 pool_debug(pool, SAT_ERROR, "not enough strings %d %d\n", i, numid);
691 return SOLV_ERROR_OVERFLOW;
693 if (!*sp) /* empty string */
701 h = strhash(sp) & hashmask;
702 hh = HASHCHAIN_START;
708 if (!strcmp(spool->stringspace + spool->strings[id], sp))
709 break; /* existing string */
710 h = HASHCHAIN_NEXT(h, hh, hashmask);
713 /* length == offset to next string */
715 if (id == ID_NULL) /* end of hash chain -> new string */
717 id = spool->nstrings++;
719 str[id] = spool->sstrings; /* save Offset */
720 if (sp != spool->stringspace + spool->sstrings) /* not at end-of-buffer */
721 memmove(spool->stringspace + spool->sstrings, sp, l); /* append to pool buffer */
722 spool->sstrings += l;
724 idmap[i] = id; /* repo relative -> pool relative */
725 sp += l; /* next string */
729 pool_shrink_strings(pool); /* vacuum */
732 /******* Part 2: Relation IDs ***************************************/
742 pool->rels = sat_realloc2(pool->rels, pool->nrels + numrel, sizeof(Reldep));
745 hashmask = mkmask(pool->nrels + numrel);
747 POOL_DEBUG(SAT_DEBUG_STATS, "read %d rels\n", numrel);
748 POOL_DEBUG(SAT_DEBUG_STATS, "rel hash buckets: %d\n", hashmask + 1);
751 * prep hash table with already existing RelDeps
754 hashtbl = sat_calloc(hashmask + 1, sizeof(Id));
755 for (i = 1; i < pool->nrels; i++)
757 h = relhash(ran[i].name, ran[i].evr, ran[i].flags) & hashmask;
758 hh = HASHCHAIN_START;
760 h = HASHCHAIN_NEXT(h, hh, hashmask);
765 * read RelDeps from repo
768 for (i = 0; i < numrel; i++)
770 name = read_id(&data, i + numid); /* read (repo relative) Ids */
771 evr = read_id(&data, i + numid);
772 relflags = read_u8(&data);
773 name = idmap[name]; /* map to (pool relative) Ids */
775 h = relhash(name, evr, relflags) & hashmask;
776 hh = HASHCHAIN_START;
780 if (id == ID_NULL) /* end of hash chain */
782 if (ran[id].name == name && ran[id].evr == evr && ran[id].flags == relflags)
784 h = HASHCHAIN_NEXT(h, hh, hashmask);
786 if (id == ID_NULL) /* new RelDep */
792 ran[id].flags = relflags;
794 idmap[i + numid] = MAKERELDEP(id); /* fill Id map */
797 pool_shrink_rels(pool); /* vacuum */
801 /******* Part 3: Dirs ***********************************************/
804 data.dirpool.dirs = sat_malloc2(numdir, sizeof(Id));
805 data.dirpool.ndirs = numdir;
806 data.dirpool.dirs[0] = 0; /* dir 0: virtual root */
807 data.dirpool.dirs[1] = 1; /* dir 1: / */
808 for (i = 2; i < numdir; i++)
810 id = read_id(&data, i + numid);
812 data.dirpool.dirs[i] = -(id - numid);
814 data.dirpool.dirs[i] = idmap[id];
816 data.dirpool.dirs[i] = id;
820 /******* Part 4: Keys ***********************************************/
822 keys = sat_calloc(numkeys, sizeof(*keys));
823 /* keys start at 1 */
824 for (i = 1; i < numkeys; i++)
826 id = read_id(&data, numid);
829 else if ((flags & REPO_LOCALPOOL) != 0)
830 id = str2id(pool, stringpool_id2str(spool, id), 1);
831 type = read_id(&data, numid);
834 else if ((flags & REPO_LOCALPOOL) != 0)
835 type = str2id(pool, stringpool_id2str(spool, type), 1);
836 if (type < REPOKEY_TYPE_VOID || type > REPOKEY_TYPE_FLEXARRAY)
838 pool_debug(pool, SAT_ERROR, "unsupported data type '%s'\n", id2str(pool, type));
839 data.error = SOLV_ERROR_UNSUPPORTED;
840 type = REPOKEY_TYPE_VOID;
844 keys[i].size = read_id(&data, keys[i].type == REPOKEY_TYPE_CONSTANTID ? numid + numrel : 0);
845 keys[i].storage = read_id(&data, 0);
846 /* old versions used SOLVABLE for main solvable data */
847 if (keys[i].storage == KEY_STORAGE_SOLVABLE)
848 keys[i].storage = KEY_STORAGE_INCORE;
849 if (keys[i].storage != KEY_STORAGE_INCORE && keys[i].storage != KEY_STORAGE_VERTICAL_OFFSET)
851 pool_debug(pool, SAT_ERROR, "unsupported storage type %d\n", keys[i].storage);
852 data.error = SOLV_ERROR_UNSUPPORTED;
854 if (id >= SOLVABLE_NAME && id <= RPM_RPMDBID)
856 if (keys[i].storage != KEY_STORAGE_INCORE)
858 pool_debug(pool, SAT_ERROR, "main solvable data must use incore storage%d\n", keys[i].storage);
859 data.error = SOLV_ERROR_UNSUPPORTED;
861 keys[i].storage = KEY_STORAGE_SOLVABLE;
863 /* cannot handle rel idarrays in incore/vertical */
864 if (type == REPOKEY_TYPE_REL_IDARRAY && keys[i].storage != KEY_STORAGE_SOLVABLE)
866 pool_debug(pool, SAT_ERROR, "type REL_IDARRAY only supported for STORAGE_SOLVABLE\n");
867 data.error = SOLV_ERROR_UNSUPPORTED;
869 if (keys[i].type == REPOKEY_TYPE_CONSTANTID && idmap)
870 keys[i].size = idmap[keys[i].size];
872 fprintf(stderr, "key %d %s %s %d %d\n", i, id2str(pool,id), id2str(pool, keys[i].type),
873 keys[i].size, keys[i].storage);
877 have_xdata = parent ? 1 : 0;
878 for (i = 1; i < numkeys; i++)
879 if (keys[i].storage == KEY_STORAGE_INCORE || keys[i].storage == KEY_STORAGE_VERTICAL_OFFSET)
883 data.nkeys = numkeys;
884 for (i = 1; i < numkeys; i++)
887 data.keybits[(id >> 3) & (sizeof(data.keybits) - 1)] |= 1 << (id & 7);
890 /******* Part 5: Schemata ********************************************/
892 id = read_id(&data, 0);
893 schemadata = sat_calloc(id + 1, sizeof(Id));
894 schemadatap = schemadata + 1;
895 schemadataend = schemadatap + id;
896 schemata = sat_calloc(numschemata, sizeof(Id));
897 for (i = 1; i < numschemata; i++)
899 schemata[i] = schemadatap - schemadata;
900 schemadatap = read_idarray(&data, numid, 0, schemadatap, schemadataend);
902 Id *sp = schemadata + schemata[i];
903 fprintf(stderr, "schema %d:", i);
905 fprintf(stderr, " %d", *sp);
906 fprintf(stderr, "\n");
909 data.schemata = schemata;
910 data.nschemata = numschemata;
911 data.schemadata = schemadata;
912 data.schemadatalen = schemadataend - data.schemadata;
914 /******* Part 6: Data ********************************************/
916 idarraydatap = idarraydataend = 0;
919 maxsize = read_id(&data, 0);
920 allsize = read_id(&data, 0);
921 maxsize += 5; /* so we can read the next schema of an array */
922 if (maxsize > allsize)
925 buf = sat_calloc(maxsize + DATA_READ_CHUNK + 4, 1); /* 4 extra bytes to detect overflows */
930 if (l < DATA_READ_CHUNK)
934 if (!l || fread(buf, l, 1, data.fp) != 1)
936 pool_debug(mypool, SAT_ERROR, "unexpected EOF\n");
937 data.error = SOLV_ERROR_EOF;
944 dp = data_read_id_max(dp, &id, 0, numschemata, &data.error);
947 incore_add_id(&data, 0); /* XXX? */
948 incore_add_id(&data, id);
949 keyp = schemadata + schemata[id];
950 data.mainschema = id;
951 for (i = 0; keyp[i]; i++)
954 data.mainschemaoffsets = sat_calloc(i, sizeof(Id));
962 /* make sure we have enough room */
963 if (keydepth == 0 || needchunk)
965 int left = bufend - dp;
966 /* read data chunk to dp */
971 pool_debug(mypool, SAT_ERROR, "buffer overrun\n");
972 data.error = SOLV_ERROR_EOF;
978 memmove(buf, dp, left);
980 if (l < DATA_READ_CHUNK)
984 if (l && fread(buf + left, l, 1, data.fp) != 1)
986 pool_debug(mypool, SAT_ERROR, "unexpected EOF\n");
987 data.error = SOLV_ERROR_EOF;
993 if (allsize + left < maxsize)
994 maxsize = allsize + left;
1002 printf("key %d at %d\n", key, (int)(keyp - 1 - schemadata));
1010 if (s && keydepth == 3)
1012 s++; /* next solvable */
1014 data.incoreoffset[(s - pool->solvables) - data.start] = data.incoredatalen;
1016 id = stack[keydepth - 1];
1019 dp = data_read_id_max(dp, &id, 0, numschemata, &data.error);
1020 incore_add_id(&data, id);
1022 keyp = schemadata + schemata[id];
1029 keyp = schemadata + stack[--keydepth];
1030 nentries = stack[--keydepth];
1032 printf("pop flexarray %d %d\n", keydepth, nentries);
1035 s = 0; /* back from solvables */
1040 data.mainschemaoffsets[keyp - 1 - (schemadata + schemata[data.mainschema])] = data.incoredatalen;
1043 printf("=> %s %s %p\n", id2str(pool, keys[key].name), id2str(pool, keys[key].type), s);
1045 id = keys[key].name;
1046 if (keys[key].storage == KEY_STORAGE_VERTICAL_OFFSET)
1049 dp = data_skip(dp, REPOKEY_TYPE_ID);
1050 dp = data_skip(dp, REPOKEY_TYPE_ID);
1051 incore_add_blob(&data, dps, dp - dps); /* just record offset/size */
1054 switch (keys[key].type)
1056 case REPOKEY_TYPE_ID:
1057 dp = data_read_id_max(dp, &did, idmap, numid + numrel, &data.error);
1058 if (s && id == SOLVABLE_NAME)
1060 else if (s && id == SOLVABLE_ARCH)
1062 else if (s && id == SOLVABLE_EVR)
1064 else if (s && id == SOLVABLE_VENDOR)
1066 else if (keys[key].storage == KEY_STORAGE_INCORE)
1067 incore_add_id(&data, did);
1069 POOL_DEBUG(SAT_DEBUG_STATS, "%s -> %s\n", id2str(pool, id), id2str(pool, did));
1072 case REPOKEY_TYPE_U32:
1073 dp = data_read_u32(dp, &h);
1075 POOL_DEBUG(SAT_DEBUG_STATS, "%s -> %u\n", id2str(pool, id), h);
1077 if (s && id == RPM_RPMDBID)
1080 repo->rpmdbid = repo_sidedata_create(repo, sizeof(Id));
1081 repo->rpmdbid[(s - pool->solvables) - repo->start] = h;
1083 else if (keys[key].storage == KEY_STORAGE_INCORE)
1084 incore_add_u32(&data, h);
1086 case REPOKEY_TYPE_IDARRAY:
1087 case REPOKEY_TYPE_REL_IDARRAY:
1088 if (!s || id < INTERESTED_START || id > INTERESTED_END)
1091 dp = data_skip(dp, REPOKEY_TYPE_IDARRAY);
1092 if (keys[key].storage != KEY_STORAGE_INCORE)
1095 incore_map_idarray(&data, dps, idmap, numid);
1097 incore_add_blob(&data, dps, dp - dps);
1100 ido = idarraydatap - repo->idarraydata;
1101 if (keys[key].type == REPOKEY_TYPE_IDARRAY)
1102 dp = data_read_idarray(dp, &idarraydatap, idmap, numid + numrel, &data.error);
1103 else if (id == SOLVABLE_REQUIRES)
1104 dp = data_read_rel_idarray(dp, &idarraydatap, idmap, numid + numrel, &data.error, SOLVABLE_PREREQMARKER);
1105 else if (id == SOLVABLE_PROVIDES)
1106 dp = data_read_rel_idarray(dp, &idarraydatap, idmap, numid + numrel, &data.error, SOLVABLE_FILEMARKER);
1108 dp = data_read_rel_idarray(dp, &idarraydatap, idmap, numid + numrel, &data.error, 0);
1109 if (idarraydatap > idarraydataend)
1111 pool_debug(pool, SAT_ERROR, "idarray overflow\n");
1112 data.error = SOLV_ERROR_OVERFLOW;
1115 if (id == SOLVABLE_PROVIDES)
1117 else if (id == SOLVABLE_OBSOLETES)
1119 else if (id == SOLVABLE_CONFLICTS)
1121 else if (id == SOLVABLE_REQUIRES)
1123 else if (id == SOLVABLE_RECOMMENDS)
1125 else if (id == SOLVABLE_SUPPLEMENTS)
1126 s->supplements = ido;
1127 else if (id == SOLVABLE_SUGGESTS)
1129 else if (id == SOLVABLE_ENHANCES)
1132 POOL_DEBUG(SAT_DEBUG_STATS, "%s ->\n", id2str(pool, id));
1133 for (; repo->idarraydata[ido]; ido++)
1134 POOL_DEBUG(SAT_DEBUG_STATS," %s\n", dep2str(pool, repo->idarraydata[ido]));
1137 case REPOKEY_TYPE_FIXARRAY:
1138 case REPOKEY_TYPE_FLEXARRAY:
1141 if (keydepth == sizeof(stack)/sizeof(*stack))
1143 pool_debug(pool, SAT_ERROR, "array stack overflow\n");
1144 data.error = SOLV_ERROR_CORRUPT;
1147 stack[keydepth++] = nentries;
1148 stack[keydepth++] = keyp - schemadata;
1149 stack[keydepth++] = 0;
1150 dp = data_read_id(dp, &nentries);
1151 incore_add_id(&data, nentries);
1154 /* zero size array? */
1156 nentries = stack[--keydepth];
1159 if (keydepth == 3 && id == REPOSITORY_SOLVABLES)
1161 /* horray! here come the solvables */
1162 if (nentries != numsolv)
1164 pool_debug(pool, SAT_ERROR, "inconsistent number of solvables: %d %d\n", nentries, numsolv);
1165 data.error = SOLV_ERROR_CORRUPT;
1170 pool_debug(pool, SAT_ERROR, "more than one solvable block\n");
1171 data.error = SOLV_ERROR_CORRUPT;
1175 s = pool_id2solvable(pool, parent->start);
1177 s = pool_id2solvable(pool, repo_add_solvable_block(repo, numsolv));
1178 data.start = s - pool->solvables;
1179 data.end = data.start + numsolv;
1180 repodata_extend_block(&data, data.start, numsolv);
1181 for (i = 1; i < numkeys; i++)
1184 if ((keys[i].type == REPOKEY_TYPE_IDARRAY || keys[i].type == REPOKEY_TYPE_REL_IDARRAY)
1185 && id >= INTERESTED_START && id <= INTERESTED_END)
1186 size_idarray += keys[i].size;
1188 /* allocate needed space in repo */
1189 /* we add maxsize because it is an upper limit for all idarrays, thus we can't overflow */
1190 repo_reserve_ids(repo, 0, size_idarray + maxsize + 1);
1191 idarraydatap = repo->idarraydata + repo->idarraysize;
1192 repo->idarraysize += size_idarray;
1193 idarraydataend = idarraydatap + size_idarray;
1196 data.incoreoffset[(s - pool->solvables) - data.start] = data.incoredatalen;
1199 dp = data_read_id_max(dp, &id, 0, numschemata, &data.error);
1200 incore_add_id(&data, id);
1201 if (keys[key].type == REPOKEY_TYPE_FIXARRAY)
1205 pool_debug(pool, SAT_ERROR, "illegal fixarray\n");
1206 data.error = SOLV_ERROR_CORRUPT;
1208 stack[keydepth - 1] = id;
1210 keyp = schemadata + schemata[id];
1214 dp = data_skip(dp, keys[key].type);
1215 if (keys[key].storage == KEY_STORAGE_INCORE)
1216 incore_add_blob(&data, dps, dp - dps);
1220 /* should shrink idarraydata again */
1224 pool_debug(pool, SAT_ERROR, "unexpected EOF, depth = %d\n", keydepth);
1225 data.error = SOLV_ERROR_CORRUPT;
1231 pool_debug(mypool, SAT_ERROR, "buffer overrun\n");
1232 data.error = SOLV_ERROR_EOF;
1239 /* free solvables */
1240 repo_free_solvable_block(repo, data.start, data.end - data.start, 1);
1242 repo->idarraysize -= size_idarray;
1243 /* free incore data */
1244 data.incoredata = sat_free(data.incoredata);
1245 data.incoredatalen = data.incoredatafree = 0;
1248 if (data.incoredatafree)
1250 /* shrink excess size */
1251 data.incoredata = sat_realloc(data.incoredata, data.incoredatalen);
1252 data.incoredatafree = 0;
1255 for (i = 1; i < numkeys; i++)
1256 if (keys[i].storage == KEY_STORAGE_VERTICAL_OFFSET)
1258 if (i < numkeys && !data.error)
1261 unsigned int pagesize;
1263 /* we have vertical data, make it available */
1264 data.verticaloffset = sat_calloc(numkeys, sizeof(Id));
1265 for (i = 1; i < numkeys; i++)
1266 if (keys[i].storage == KEY_STORAGE_VERTICAL_OFFSET)
1268 data.verticaloffset[i] = fileoffset;
1269 fileoffset += keys[i].size;
1271 data.lastverticaloffset = fileoffset;
1272 pagesize = read_u32(&data);
1273 data.error = repopagestore_read_or_setup_pages(&data.store, data.fp, pagesize, fileoffset);
1277 /* no longer needed */
1285 /* XXX: free repodata? */
1291 /* overwrite stub repodata */
1292 repodata_freedata(parent);
1297 /* make it available as new repodata */
1298 repo->repodata = sat_realloc2(repo->repodata, repo->nrepodata + 1, sizeof(data));
1299 repo->repodata[repo->nrepodata++] = data;
1302 /* create stub repodata entries for all external */
1303 if (!(flags & SOLV_ADD_NO_STUBS) && !parent)
1305 for (key = 1 ; key < data.nkeys; key++)
1306 if (data.keys[key].name == REPOSITORY_EXTERNAL && data.keys[key].type == REPOKEY_TYPE_FLEXARRAY)
1308 if (key < data.nkeys)
1309 repodata_create_stubs(repo->repodata + (repo->nrepodata - 1));
1312 POOL_DEBUG(SAT_DEBUG_STATS, "repo_add_solv took %d ms\n", sat_timems(now));
1313 POOL_DEBUG(SAT_DEBUG_STATS, "repo size: %d solvables\n", repo->nsolvables);
1314 POOL_DEBUG(SAT_DEBUG_STATS, "repo memory used: %d K incore, %d K idarray\n", data.incoredatalen/1024, repo->idarraysize / (int)(1024/sizeof(Id)));
1319 repo_add_solv(Repo *repo, FILE *fp)
1321 return repo_add_solv_flags(repo, fp, 0);