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 parent = repo_add_repodata(repo, flags | REPO_REUSE_REPODATA);
468 memset(&data, 0, sizeof(data));
471 repopagestore_init(&data.store);
475 if (read_u32(&data) != ('S' << 24 | 'O' << 16 | 'L' << 8 | 'V'))
477 pool_debug(pool, SAT_ERROR, "not a SOLV file\n");
478 return SOLV_ERROR_NOT_SOLV;
480 solvversion = read_u32(&data);
486 pool_debug(pool, SAT_ERROR, "unsupported SOLV version\n");
487 return SOLV_ERROR_UNSUPPORTED;
490 pool_freeidhashes(pool);
492 numid = read_u32(&data);
493 numrel = read_u32(&data);
494 numdir = read_u32(&data);
495 numsolv = read_u32(&data);
496 numkeys = read_u32(&data);
497 numschemata = read_u32(&data);
498 solvflags = read_u32(&data);
500 if (numdir && numdir < 2)
502 pool_debug(pool, SAT_ERROR, "bad number of dirs\n");
503 return SOLV_ERROR_CORRUPT;
506 if (numrel && (flags & REPO_LOCALPOOL) != 0)
508 pool_debug(pool, SAT_ERROR, "relations are forbidden in a local pool\n");
509 return SOLV_ERROR_CORRUPT;
511 if (parent && numsolv && parent->end - parent->start != numsolv)
513 pool_debug(pool, SAT_ERROR, "sub-repository solvable number doesn't match main repository (%d - %d)\n", parent->end - parent->start, numsolv);
514 return SOLV_ERROR_CORRUPT;
517 /******* Part 1: string IDs *****************************************/
519 sizeid = read_u32(&data); /* size of string+Id space */
522 * read strings and Ids
531 if (!(flags & REPO_LOCALPOOL))
537 spool->stringspace = sat_malloc(7);
538 strcpy(spool->stringspace, "<NULL>");
543 /* alloc string buffer */
544 spool->stringspace = sat_realloc(spool->stringspace, spool->sstrings + sizeid + 1);
545 /* alloc string offsets (Id -> Offset into string space) */
546 spool->strings = sat_realloc2(spool->strings, spool->nstrings + numid, sizeof(Offset));
548 strsp = spool->stringspace;
549 str = spool->strings; /* array of offsets into strsp, indexed by Id */
551 /* point to _BEHIND_ already allocated string/Id space */
552 strsp += spool->sstrings;
556 * read new repo at end of pool
559 if ((solvflags & SOLV_FLAG_PREFIX_POOL) == 0)
561 if (sizeid && fread(strsp, sizeid, 1, fp) != 1)
563 pool_debug(pool, SAT_ERROR, "read error while reading strings\n");
564 return SOLV_ERROR_EOF;
569 unsigned int pfsize = read_u32(&data);
570 char *prefix = sat_malloc(pfsize);
576 if (pfsize && fread(prefix, pfsize, 1, fp) != 1)
578 pool_debug(pool, SAT_ERROR, "read error while reading strings\n");
580 return SOLV_ERROR_EOF;
582 for (i = 1; i < numid; i++)
584 int same = (unsigned char)*pp++;
585 size_t len = strlen(pp) + 1;
586 freesp -= same + len;
589 pool_debug(pool, SAT_ERROR, "overflow while expanding strings\n");
591 return SOLV_ERROR_OVERFLOW;
594 memcpy(dest, old_str, same);
595 memcpy(dest + same, pp, len);
603 pool_debug(pool, SAT_ERROR, "expanding strings size mismatch\n");
604 return SOLV_ERROR_CORRUPT;
607 strsp[sizeid] = 0; /* make string space \0 terminated */
610 if ((flags & REPO_LOCALPOOL) != 0)
612 /* no shared pool, thus no idmap and no unification */
614 spool->nstrings = numid;
618 /* we need the '' for directories */
619 pool_debug(pool, SAT_ERROR, "store strings don't start with ''\n");
620 return SOLV_ERROR_CORRUPT;
622 for (i = 1; i < spool->nstrings; i++)
624 if (sp >= strsp + sizeid)
626 pool_debug(pool, SAT_ERROR, "not enough strings\n");
627 return SOLV_ERROR_OVERFLOW;
629 str[i] = sp - spool->stringspace;
630 sp += strlen(sp) + 1;
632 spool->sstrings = sp - spool->stringspace;
637 /* alloc id map for name and rel Ids. this maps ids in the solv files
638 * to the ids in our pool */
639 idmap = sat_calloc(numid + numrel, sizeof(Id));
642 * build hashes for all read strings
646 hashmask = mkmask(spool->nstrings + numid);
649 POOL_DEBUG(SAT_DEBUG_STATS, "read %d strings\n", numid);
650 POOL_DEBUG(SAT_DEBUG_STATS, "string hash buckets: %d\n", hashmask + 1);
654 * create hashtable with strings already in pool
657 hashtbl = sat_calloc(hashmask + 1, sizeof(Id));
658 for (i = 1; i < spool->nstrings; i++) /* leave out our dummy zero id */
660 h = strhash(spool->stringspace + spool->strings[i]) & hashmask;
661 hh = HASHCHAIN_START;
663 h = HASHCHAIN_NEXT(h, hh, hashmask);
668 * run over string space, calculate offsets
670 * build id map (maps solv Id -> pool Id)
673 for (i = 1; i < numid; i++)
675 if (sp >= strsp + sizeid)
679 pool_debug(pool, SAT_ERROR, "not enough strings %d %d\n", i, numid);
680 return SOLV_ERROR_OVERFLOW;
682 if (!*sp) /* empty string */
690 h = strhash(sp) & hashmask;
691 hh = HASHCHAIN_START;
697 if (!strcmp(spool->stringspace + spool->strings[id], sp))
698 break; /* existing string */
699 h = HASHCHAIN_NEXT(h, hh, hashmask);
702 /* length == offset to next string */
704 if (id == ID_NULL) /* end of hash chain -> new string */
706 id = spool->nstrings++;
708 str[id] = spool->sstrings; /* save Offset */
709 if (sp != spool->stringspace + spool->sstrings) /* not at end-of-buffer */
710 memmove(spool->stringspace + spool->sstrings, sp, l); /* append to pool buffer */
711 spool->sstrings += l;
713 idmap[i] = id; /* repo relative -> pool relative */
714 sp += l; /* next string */
718 pool_shrink_strings(pool); /* vacuum */
721 /******* Part 2: Relation IDs ***************************************/
731 pool->rels = sat_realloc2(pool->rels, pool->nrels + numrel, sizeof(Reldep));
734 hashmask = mkmask(pool->nrels + numrel);
736 POOL_DEBUG(SAT_DEBUG_STATS, "read %d rels\n", numrel);
737 POOL_DEBUG(SAT_DEBUG_STATS, "rel hash buckets: %d\n", hashmask + 1);
740 * prep hash table with already existing RelDeps
743 hashtbl = sat_calloc(hashmask + 1, sizeof(Id));
744 for (i = 1; i < pool->nrels; i++)
746 h = relhash(ran[i].name, ran[i].evr, ran[i].flags) & hashmask;
747 hh = HASHCHAIN_START;
749 h = HASHCHAIN_NEXT(h, hh, hashmask);
754 * read RelDeps from repo
757 for (i = 0; i < numrel; i++)
759 name = read_id(&data, i + numid); /* read (repo relative) Ids */
760 evr = read_id(&data, i + numid);
761 relflags = read_u8(&data);
762 name = idmap[name]; /* map to (pool relative) Ids */
764 h = relhash(name, evr, relflags) & hashmask;
765 hh = HASHCHAIN_START;
769 if (id == ID_NULL) /* end of hash chain */
771 if (ran[id].name == name && ran[id].evr == evr && ran[id].flags == relflags)
773 h = HASHCHAIN_NEXT(h, hh, hashmask);
775 if (id == ID_NULL) /* new RelDep */
781 ran[id].flags = relflags;
783 idmap[i + numid] = MAKERELDEP(id); /* fill Id map */
786 pool_shrink_rels(pool); /* vacuum */
790 /******* Part 3: Dirs ***********************************************/
793 data.dirpool.dirs = sat_malloc2(numdir, sizeof(Id));
794 data.dirpool.ndirs = numdir;
795 data.dirpool.dirs[0] = 0; /* dir 0: virtual root */
796 data.dirpool.dirs[1] = 1; /* dir 1: / */
797 for (i = 2; i < numdir; i++)
799 id = read_id(&data, i + numid);
801 data.dirpool.dirs[i] = -(id - numid);
803 data.dirpool.dirs[i] = idmap[id];
805 data.dirpool.dirs[i] = id;
809 /******* Part 4: Keys ***********************************************/
811 keys = sat_calloc(numkeys, sizeof(*keys));
812 /* keys start at 1 */
813 for (i = 1; i < numkeys; i++)
815 id = read_id(&data, numid);
818 else if ((flags & REPO_LOCALPOOL) != 0)
819 id = str2id(pool, stringpool_id2str(spool, id), 1);
820 type = read_id(&data, numid);
823 else if ((flags & REPO_LOCALPOOL) != 0)
824 type = str2id(pool, stringpool_id2str(spool, type), 1);
825 if (type < REPOKEY_TYPE_VOID || type > REPOKEY_TYPE_FLEXARRAY)
827 pool_debug(pool, SAT_ERROR, "unsupported data type '%s'\n", id2str(pool, type));
828 data.error = SOLV_ERROR_UNSUPPORTED;
829 type = REPOKEY_TYPE_VOID;
833 keys[i].size = read_id(&data, keys[i].type == REPOKEY_TYPE_CONSTANTID ? numid + numrel : 0);
834 keys[i].storage = read_id(&data, 0);
835 if (id >= SOLVABLE_NAME && id <= RPM_RPMDBID)
836 keys[i].storage = KEY_STORAGE_SOLVABLE;
837 else if (keys[i].storage == KEY_STORAGE_SOLVABLE)
838 keys[i].storage = KEY_STORAGE_INCORE;
839 if (keys[i].type == REPOKEY_TYPE_CONSTANTID)
842 keys[i].size = idmap[keys[i].size];
843 else if ((flags & REPO_LOCALPOOL) != 0)
844 keys[i].size = str2id(pool, stringpool_id2str(spool, keys[i].size), 1);
847 fprintf(stderr, "key %d %s %s %d %d\n", i, id2str(pool,id), id2str(pool, keys[i].type),
848 keys[i].size, keys[i].storage);
852 have_xdata = parent ? 1 : 0;
853 for (i = 1; i < numkeys; i++)
854 if (keys[i].storage == KEY_STORAGE_INCORE || keys[i].storage == KEY_STORAGE_VERTICAL_OFFSET)
858 data.nkeys = numkeys;
859 for (i = 1; i < numkeys; i++)
862 data.keybits[(id >> 3) & (sizeof(data.keybits) - 1)] |= 1 << (id & 7);
865 /******* Part 5: Schemata ********************************************/
867 id = read_id(&data, 0);
868 schemadata = sat_calloc(id + 1, sizeof(Id));
869 schemadatap = schemadata + 1;
870 schemadataend = schemadatap + id;
871 schemata = sat_calloc(numschemata, sizeof(Id));
872 for (i = 1; i < numschemata; i++)
874 schemata[i] = schemadatap - schemadata;
875 schemadatap = read_idarray(&data, numid, 0, schemadatap, schemadataend);
877 Id *sp = schemadata + schemata[i];
878 fprintf(stderr, "schema %d:", i);
880 fprintf(stderr, " %d", *sp);
881 fprintf(stderr, "\n");
884 data.schemata = schemata;
885 data.nschemata = numschemata;
886 data.schemadata = schemadata;
887 data.schemadatalen = schemadataend - data.schemadata;
889 /******* Part 6: Data ********************************************/
891 idarraydatap = idarraydataend = 0;
894 maxsize = read_id(&data, 0);
895 allsize = read_id(&data, 0);
896 maxsize += 5; /* so we can read the next schema of an array */
897 if (maxsize > allsize)
900 buf = sat_calloc(maxsize + DATA_READ_CHUNK + 4, 1); /* 4 extra bytes to detect overflows */
905 if (l < DATA_READ_CHUNK)
909 if (!l || fread(buf, l, 1, data.fp) != 1)
911 pool_debug(mypool, SAT_ERROR, "unexpected EOF\n");
912 data.error = SOLV_ERROR_EOF;
919 dp = data_read_id_max(dp, &id, 0, numschemata, &data.error);
922 incore_add_id(&data, 0); /* XXX? */
923 incore_add_id(&data, id);
924 keyp = schemadata + schemata[id];
925 data.mainschema = id;
926 for (i = 0; keyp[i]; i++)
929 data.mainschemaoffsets = sat_calloc(i, sizeof(Id));
939 printf("key %d at %d\n", key, keyp - 1 - schemadata);
947 if (s && keydepth == 3)
949 s++; /* next solvable */
951 data.incoreoffset[(s - pool->solvables) - data.start] = data.incoredatalen;
953 id = stack[keydepth - 1];
956 dp = data_read_id_max(dp, &id, 0, numschemata, &data.error);
957 incore_add_id(&data, id);
959 keyp = schemadata + schemata[id];
966 keyp = schemadata + stack[--keydepth];
967 nentries = stack[--keydepth];
969 printf("pop flexarray %d %d\n", keydepth, nentries);
972 s = 0; /* back from solvables */
977 data.mainschemaoffsets[keyp - 1 - (schemadata + schemata[data.mainschema])] = data.incoredatalen;
978 if (keydepth == 0 || needchunk)
980 int left = bufend - dp;
981 /* read data chunk to dp */
986 pool_debug(mypool, SAT_ERROR, "buffer overrun\n");
987 data.error = SOLV_ERROR_EOF;
993 memmove(buf, dp, left);
995 if (l < DATA_READ_CHUNK)
999 if (l && fread(buf + left, l, 1, data.fp) != 1)
1001 pool_debug(mypool, SAT_ERROR, "unexpected EOF\n");
1002 data.error = SOLV_ERROR_EOF;
1007 bufend = buf + left;
1008 if (allsize + left < maxsize)
1009 maxsize = allsize + left;
1016 printf("=> %s %s %p\n", id2str(pool, keys[key].name), id2str(pool, keys[key].type), s);
1018 id = keys[key].name;
1019 if (keys[key].storage == KEY_STORAGE_VERTICAL_OFFSET)
1022 dp = data_skip(dp, REPOKEY_TYPE_ID);
1023 dp = data_skip(dp, REPOKEY_TYPE_ID);
1024 incore_add_blob(&data, dps, dp - dps);
1027 switch (keys[key].type)
1029 case REPOKEY_TYPE_ID:
1030 dp = data_read_id_max(dp, &did, idmap, numid + numrel, &data.error);
1031 if (s && id == SOLVABLE_NAME)
1033 else if (s && id == SOLVABLE_ARCH)
1035 else if (s && id == SOLVABLE_EVR)
1037 else if (s && id == SOLVABLE_VENDOR)
1039 else if (keys[key].storage == KEY_STORAGE_INCORE)
1040 incore_add_id(&data, did);
1042 POOL_DEBUG(SAT_DEBUG_STATS, "%s -> %s\n", id2str(pool, id), id2str(pool, did));
1045 case REPOKEY_TYPE_U32:
1046 dp = data_read_u32(dp, &h);
1048 POOL_DEBUG(SAT_DEBUG_STATS, "%s -> %u\n", id2str(pool, id), h);
1050 if (s && id == RPM_RPMDBID)
1053 repo->rpmdbid = repo_sidedata_create(repo, sizeof(Id));
1054 repo->rpmdbid[(s - pool->solvables) - repo->start] = h;
1056 else if (keys[key].storage == KEY_STORAGE_INCORE)
1057 incore_add_u32(&data, h);
1059 case REPOKEY_TYPE_IDARRAY:
1060 case REPOKEY_TYPE_REL_IDARRAY:
1061 if (!s || id < INTERESTED_START || id > INTERESTED_END)
1064 dp = data_skip(dp, REPOKEY_TYPE_IDARRAY);
1065 if (keys[key].storage != KEY_STORAGE_INCORE)
1068 incore_map_idarray(&data, dps, idmap, numid);
1070 incore_add_blob(&data, dps, dp - dps);
1073 ido = idarraydatap - repo->idarraydata;
1074 if (keys[key].type == REPOKEY_TYPE_IDARRAY)
1075 dp = data_read_idarray(dp, &idarraydatap, idmap, numid + numrel, &data.error);
1076 else if (id == SOLVABLE_REQUIRES)
1077 dp = data_read_rel_idarray(dp, &idarraydatap, idmap, numid + numrel, &data.error, SOLVABLE_PREREQMARKER);
1078 else if (id == SOLVABLE_PROVIDES)
1079 dp = data_read_rel_idarray(dp, &idarraydatap, idmap, numid + numrel, &data.error, SOLVABLE_FILEMARKER);
1081 dp = data_read_rel_idarray(dp, &idarraydatap, idmap, numid + numrel, &data.error, 0);
1082 if (idarraydatap > idarraydataend)
1084 pool_debug(pool, SAT_ERROR, "idarray overflow\n");
1085 data.error = SOLV_ERROR_OVERFLOW;
1088 if (id == SOLVABLE_PROVIDES)
1090 else if (id == SOLVABLE_OBSOLETES)
1092 else if (id == SOLVABLE_CONFLICTS)
1094 else if (id == SOLVABLE_REQUIRES)
1096 else if (id == SOLVABLE_RECOMMENDS)
1098 else if (id == SOLVABLE_SUPPLEMENTS)
1099 s->supplements = ido;
1100 else if (id == SOLVABLE_SUGGESTS)
1102 else if (id == SOLVABLE_ENHANCES)
1105 POOL_DEBUG(SAT_DEBUG_STATS, "%s ->\n", id2str(pool, id));
1106 for (; repo->idarraydata[ido]; ido++)
1107 POOL_DEBUG(SAT_DEBUG_STATS," %s\n", dep2str(pool, repo->idarraydata[ido]));
1110 case REPOKEY_TYPE_FIXARRAY:
1111 case REPOKEY_TYPE_FLEXARRAY:
1114 if (keydepth == sizeof(stack)/sizeof(*stack))
1116 pool_debug(pool, SAT_ERROR, "array stack overflow\n");
1117 data.error = SOLV_ERROR_CORRUPT;
1120 stack[keydepth++] = nentries;
1121 stack[keydepth++] = keyp - schemadata;
1122 stack[keydepth++] = 0;
1123 dp = data_read_id(dp, &nentries);
1124 incore_add_id(&data, nentries);
1127 /* zero size array? */
1129 nentries = stack[--keydepth];
1132 if (keydepth == 3 && id == REPOSITORY_SOLVABLES)
1134 /* horray! here come the solvables */
1135 if (nentries != numsolv)
1137 pool_debug(pool, SAT_ERROR, "inconsistent number of solvables: %d %d\n", nentries, numsolv);
1138 data.error = SOLV_ERROR_CORRUPT;
1143 pool_debug(pool, SAT_ERROR, "more than one solvable block\n");
1144 data.error = SOLV_ERROR_CORRUPT;
1148 s = pool_id2solvable(pool, parent->start);
1150 s = pool_id2solvable(pool, repo_add_solvable_block(repo, numsolv));
1151 data.start = s - pool->solvables;
1152 data.end = data.start + numsolv;
1153 repodata_extend_block(&data, data.start, numsolv);
1154 for (i = 1; i < numkeys; i++)
1157 if ((keys[i].type == REPOKEY_TYPE_IDARRAY || keys[i].type == REPOKEY_TYPE_REL_IDARRAY)
1158 && id >= INTERESTED_START && id <= INTERESTED_END)
1159 size_idarray += keys[i].size;
1161 /* allocate needed space in repo */
1162 /* we add maxsize because it is an upper limit for all idarrays, thus we can't overflow */
1163 repo_reserve_ids(repo, 0, size_idarray + maxsize + 1);
1164 idarraydatap = repo->idarraydata + repo->idarraysize;
1165 repo->idarraysize += size_idarray;
1166 idarraydataend = idarraydatap + size_idarray;
1169 data.incoreoffset[(s - pool->solvables) - data.start] = data.incoredatalen;
1172 dp = data_read_id_max(dp, &id, 0, numschemata, &data.error);
1173 incore_add_id(&data, id);
1174 if (keys[key].type == REPOKEY_TYPE_FIXARRAY)
1178 pool_debug(pool, SAT_ERROR, "illegal fixarray\n");
1179 data.error = SOLV_ERROR_CORRUPT;
1181 stack[keydepth - 1] = id;
1183 keyp = schemadata + schemata[id];
1187 dp = data_skip(dp, keys[key].type);
1188 if (keys[key].storage == KEY_STORAGE_INCORE)
1189 incore_add_blob(&data, dps, dp - dps);
1193 /* should shrink idarraydata again */
1197 pool_debug(pool, SAT_ERROR, "unexpected EOF, depth = %d\n", keydepth);
1198 data.error = SOLV_ERROR_CORRUPT;
1204 pool_debug(mypool, SAT_ERROR, "buffer overrun\n");
1205 data.error = SOLV_ERROR_EOF;
1212 /* free solvables */
1213 repo_free_solvable_block(repo, data.start, data.end - data.start, 1);
1215 repo->idarraysize -= size_idarray;
1216 /* free incore data */
1217 data.incoredata = sat_free(data.incoredata);
1218 data.incoredatalen = data.incoredatafree = 0;
1221 if (data.incoredatafree)
1223 /* shrink excess size */
1224 data.incoredata = sat_realloc(data.incoredata, data.incoredatalen);
1225 data.incoredatafree = 0;
1228 for (i = 1; i < numkeys; i++)
1229 if (keys[i].storage == KEY_STORAGE_VERTICAL_OFFSET)
1231 if (i < numkeys && !data.error)
1234 unsigned int pagesize;
1236 /* we have vertical data, make it available */
1237 data.verticaloffset = sat_calloc(numkeys, sizeof(Id));
1238 for (i = 1; i < numkeys; i++)
1239 if (keys[i].storage == KEY_STORAGE_VERTICAL_OFFSET)
1241 data.verticaloffset[i] = fileoffset;
1242 fileoffset += keys[i].size;
1244 data.lastverticaloffset = fileoffset;
1245 pagesize = read_u32(&data);
1246 data.error = repopagestore_read_or_setup_pages(&data.store, data.fp, pagesize, fileoffset);
1250 /* no longer needed */
1258 /* XXX: free repodata? */
1264 /* overwrite stub repodata */
1265 repodata_freedata(parent);
1270 /* make it available as new repodata */
1271 repo->repodata = sat_realloc2(repo->repodata, repo->nrepodata + 1, sizeof(data));
1272 repo->repodata[repo->nrepodata++] = data;
1275 /* create stub repodata entries for all external */
1276 for (key = 1 ; key < data.nkeys; key++)
1277 if (data.keys[key].name == REPOSITORY_EXTERNAL && data.keys[key].type == REPOKEY_TYPE_FLEXARRAY)
1279 if (key < data.nkeys && !parent)
1280 repodata_create_stubs(&data);
1282 POOL_DEBUG(SAT_DEBUG_STATS, "repo_add_solv took %d ms\n", sat_timems(now));
1283 POOL_DEBUG(SAT_DEBUG_STATS, "repo size: %d solvables\n", repo->nsolvables);
1284 POOL_DEBUG(SAT_DEBUG_STATS, "repo memory used: %d K incore, %d K idarray\n", data.incoredatalen/1024, repo->idarraysize / (int)(1024/sizeof(Id)));
1289 repo_add_solv(Repo *repo, FILE *fp)
1291 return repo_add_solv_flags(repo, fp, 0);