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"
29 #include "attr_store_p.h"
32 #define INTERESTED_START SOLVABLE_NAME
33 #define INTERESTED_END SOLVABLE_FRESHENS
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... */
44 /*-----------------------------------------------------------------*/
45 /* .solv read functions */
52 read_u32(Repodata *data)
59 for (i = 0; i < 4; i++)
64 pool_debug(mypool, SAT_ERROR, "unexpected EOF\n");
65 data->error = SOLV_ERROR_EOF;
79 read_u8(Repodata *data)
88 pool_debug(mypool, SAT_ERROR, "unexpected EOF\n");
89 data->error = SOLV_ERROR_EOF;
101 read_id(Repodata *data, Id max)
108 for (i = 0; i < 5; i++)
113 pool_debug(mypool, SAT_ERROR, "unexpected EOF\n");
114 data->error = SOLV_ERROR_EOF;
122 pool_debug(mypool, SAT_ERROR, "read_id: id too large (%u/%u)\n", x, max);
123 data->error = SOLV_ERROR_ID_RANGE;
128 x = (x << 7) ^ c ^ 128;
130 pool_debug(mypool, SAT_ERROR, "read_id: id too long\n");
131 data->error = SOLV_ERROR_CORRUPT;
141 read_idarray(Repodata *data, Id max, Id *map, Id *store, Id *end, int relative)
154 pool_debug(mypool, SAT_ERROR, "unexpected EOF\n");
155 data->error = SOLV_ERROR_EOF;
160 x = (x << 6) | (c & 63);
163 if (x == 0 && c == 0x40)
168 pool_debug(mypool, SAT_ERROR, "read_idarray: array overflow\n");
169 data->error = SOLV_ERROR_OVERFLOW;
172 *store++ = SOLVABLE_PREREQMARKER;
182 pool_debug(mypool, SAT_ERROR, "read_idarray: id too large (%u/%u)\n", x, max);
183 data->error = SOLV_ERROR_ID_RANGE;
190 pool_debug(mypool, SAT_ERROR, "read_idarray: array overflow\n");
196 if (x == 0) /* already have trailing zero? */
200 pool_debug(mypool, SAT_ERROR, "read_idarray: array overflow\n");
201 data->error = SOLV_ERROR_OVERFLOW;
210 x = (x << 7) ^ c ^ 128;
215 read_str(Repodata *data, char **inbuf, unsigned *len)
217 unsigned char *buf = (unsigned char*)*inbuf;
220 buf = sat_malloc(1024);
225 while((c = getc(data->fp)) != 0)
229 pool_debug (mypool, SAT_ERROR, "unexpected EOF\n");
230 data->error = SOLV_ERROR_EOF;
233 /* Plus 1 as we also want to add the 0. */
237 /* Don't realloc on the inbuf, it might be on the stack. */
238 if (buf == (unsigned char*)*inbuf)
240 buf = sat_malloc(*len);
241 memcpy(buf, *inbuf, *len - 256);
244 buf = sat_realloc(buf, *len);
253 skip_item (Repodata *data, unsigned type, unsigned numid, unsigned numrel)
261 read_id(data, numid + numrel); /* just check Id */
264 read_id(data, numid + data->dirpool.ndirs); /* just check Id */
272 case TYPE_ATTR_STRING:
274 while (read_u8(data) != 0)
278 case TYPE_REL_IDARRAY:
279 case TYPE_ATTR_INTLIST:
280 while ((read_u8(data) & 0xc0) != 0)
283 case TYPE_DIRNUMNUMARRAY:
286 read_id(data, numid + data->dirpool.ndirs); /* just check Id */
288 if (!(read_id(data, 0) & 0x40))
292 case TYPE_DIRSTRARRAY:
295 Id id = read_id(data, 0);
296 while (read_u8(data) != 0)
302 case TYPE_COUNT_NAMED:
304 unsigned count = read_id(data, 0);
307 read_id(data, numid); /* Name */
308 unsigned t = read_id(data, TYPE_ATTR_TYPE_MAX + 1);
309 skip_item(data, t, numid, numrel);
315 unsigned count = read_id(data, 0);
316 unsigned t = read_id(data, TYPE_ATTR_TYPE_MAX + 1);
318 skip_item(data, t, numid, numrel);
321 case TYPE_ATTR_CHUNK:
327 case TYPE_ATTR_LOCALIDS:
328 while (read_id(data, 0) != 0)
332 pool_debug(mypool, SAT_ERROR, "unknown type %d\n", type);
333 data->error = SOLV_ERROR_CORRUPT;
339 key_cmp (const void *pa, const void *pb)
341 Repokey *a = (Repokey *)pa;
342 Repokey *b = (Repokey *)pb;
343 return a->name - b->name;
346 static void repodata_load_solv(Repodata *data);
349 parse_repodata(Repodata *maindata, Id *keyp, Repokey *keys, Id *idmap, unsigned numid, unsigned numrel, Repo *repo)
356 repo->repodata = sat_realloc2(repo->repodata, repo->nrepodata + 1, sizeof (*data));
357 data = repo->repodata + repo->nrepodata++;
358 memset(data, 0, sizeof(*data));
360 data->state = REPODATA_STUB;
361 data->loadcallback = repodata_load_solv;
363 while ((key = *keyp++) != 0)
366 switch (keys[key].type)
368 case TYPE_IDVALUEARRAY:
369 if (id != REPODATA_KEYS)
371 skip_item(maindata, TYPE_IDVALUEARRAY, numid, numrel);
374 /* read_idarray writes a terminating 0, that's why the + 1 */
375 ida = sat_calloc(keys[key].size + 1, sizeof(Id));
376 ide = read_idarray(maindata, 0, 0, ida, ida + keys[key].size + 1, 0);
380 pool_debug (mypool, SAT_ERROR, "invalid attribute data\n");
381 data->error = SOLV_ERROR_CORRUPT;
384 data->nkeys = 1 + (n >> 1);
385 data->keys = sat_malloc2(data->nkeys, sizeof(data->keys[0]));
386 memset(data->keys, 0, sizeof(Repokey));
387 for (i = 1, ide = ida; i < data->nkeys; i++)
391 pool_debug (mypool, SAT_ERROR, "invalid attribute data\n");
392 data->error = SOLV_ERROR_CORRUPT;
395 data->keys[i].name = idmap ? idmap[*ide++] : *ide++;
396 data->keys[i].type = *ide++;
397 data->keys[i].size = 0;
398 data->keys[i].storage = 0;
402 qsort(data->keys + 1, data->nkeys - 1, sizeof(data->keys[0]), key_cmp);
405 if (id != REPODATA_LOCATION)
406 skip_item(maindata, TYPE_STR, numid, numrel);
410 unsigned len = sizeof (buf);
411 char *filename = buf;
412 read_str(maindata, &filename, &len);
413 data->location = strdup(filename);
419 skip_item(maindata, keys[key].type, numid, numrel);
425 /*-----------------------------------------------------------------*/
429 skip_schema(Repodata *data, Id *keyp, Repokey *keys, unsigned int numid, unsigned int numrel)
432 while ((key = *keyp++) != 0)
433 skip_item(data, keys[key].type, numid, numrel);
436 /*-----------------------------------------------------------------*/
439 incore_add_id(Repodata *data, Id x)
442 /* make sure we have at least 5 bytes free */
443 if (data->incoredatafree < 5)
445 data->incoredata = sat_realloc(data->incoredata, data->incoredatalen + 1024);
446 data->incoredatafree = 1024;
448 dp = data->incoredata + data->incoredatalen;
454 *dp++ = (x >> 28) | 128;
456 *dp++ = (x >> 21) | 128;
457 *dp++ = (x >> 14) | 128;
460 *dp++ = (x >> 7) | 128;
462 data->incoredatafree -= dp - (data->incoredata + data->incoredatalen);
463 data->incoredatalen = dp - data->incoredata;
467 incore_add_u32(Repodata *data, unsigned int x)
470 /* make sure we have at least 4 bytes free */
471 if (data->incoredatafree < 4)
473 data->incoredata = sat_realloc(data->incoredata, data->incoredatalen + 1024);
474 data->incoredatafree = 1024;
476 dp = data->incoredata + data->incoredatalen;
481 data->incoredatafree -= 4;
482 data->incoredatalen += 4;
486 incore_add_u8(Repodata *data, unsigned int x)
489 /* make sure we have at least 1 byte free */
490 if (data->incoredatafree < 1)
492 data->incoredata = sat_realloc(data->incoredata, data->incoredatalen + 1024);
493 data->incoredatafree = 1024;
495 dp = data->incoredata + data->incoredatalen;
497 data->incoredatafree--;
498 data->incoredatalen++;
503 // ----------------------------------------------
507 * read repo from .solv file
512 repo_add_solv_parent(Repo *repo, FILE *fp, Repodata *parent)
514 Pool *pool = repo->pool;
516 unsigned int numid, numrel, numdir, numsolv;
517 unsigned int numkeys, numschemata, numinfo;
519 Attrstore *embedded_store = 0;
523 Offset *str; /* map Id -> Offset into string space */
524 char *strsp; /* repo string space */
525 char *sp; /* pointer into string space */
526 Id *idmap; /* map of repo Ids to pool Ids */
528 unsigned int hashmask, h;
534 unsigned int size_idarray;
535 Id *idarraydatap, *idarraydataend;
538 unsigned int solvflags;
539 unsigned int solvversion;
541 Id *schemadata, *schemadatap, *schemadataend;
544 unsigned oldnrepodata;
546 struct _Stringpool *spool;
550 memset(&data, 0, sizeof(data));
556 if (read_u32(&data) != ('S' << 24 | 'O' << 16 | 'L' << 8 | 'V'))
558 pool_debug(pool, SAT_ERROR, "not a SOLV file\n");
559 return SOLV_ERROR_NOT_SOLV;
561 solvversion = read_u32(&data);
572 pool_debug(pool, SAT_ERROR, "unsupported SOLV version\n");
573 return SOLV_ERROR_UNSUPPORTED;
576 pool_freeidhashes(pool);
578 numid = read_u32(&data);
579 numrel = read_u32(&data);
580 if (solvversion >= SOLV_VERSION_4)
581 numdir = read_u32(&data);
584 numsolv = read_u32(&data);
585 numkeys = read_u32(&data);
586 numschemata = read_u32(&data);
587 numinfo = read_u32(&data);
588 solvflags = read_u32(&data);
590 if (solvversion < SOLV_VERSION_5)
593 if (numdir && numdir < 2)
595 pool_debug(pool, SAT_ERROR, "bad number of dirs\n");
596 return SOLV_ERROR_CORRUPT;
598 if (numinfo && solvversion < SOLV_VERSION_3)
600 pool_debug(pool, SAT_ERROR, "unsupported SOLV format (has info)\n");
601 return SOLV_ERROR_UNSUPPORTED;
608 pool_debug(pool, SAT_ERROR, "relations are forbidden in a store\n");
609 return SOLV_ERROR_CORRUPT;
611 if (parent->end - parent->start != numsolv)
613 pool_debug(pool, SAT_ERROR, "unequal number of solvables in a store\n");
614 return SOLV_ERROR_CORRUPT;
618 pool_debug(pool, SAT_ERROR, "info blocks are forbidden in a store\n");
619 return SOLV_ERROR_CORRUPT;
623 /******* Part 1: string IDs *****************************************/
625 sizeid = read_u32(&data); /* size of string+Id space */
628 * read strings and Ids
643 spool->stringspace = sat_malloc(7);
644 strcpy(spool->stringspace, "<NULL>");
649 /* alloc string buffer */
650 spool->stringspace = sat_realloc(spool->stringspace, spool->sstrings + sizeid + 1);
651 /* alloc string offsets (Id -> Offset into string space) */
652 spool->strings = sat_realloc2(spool->strings, spool->nstrings + numid, sizeof(Offset));
654 strsp = spool->stringspace;
655 str = spool->strings; /* array of offsets into strsp, indexed by Id */
657 /* point to _BEHIND_ already allocated string/Id space */
658 strsp += spool->sstrings;
662 * read new repo at end of pool
665 if ((solvflags & SOLV_FLAG_PREFIX_POOL) == 0)
667 if (sizeid && fread(strsp, sizeid, 1, fp) != 1)
669 pool_debug(pool, SAT_ERROR, "read error while reading strings\n");
670 return SOLV_ERROR_EOF;
675 unsigned int pfsize = read_u32(&data);
676 char *prefix = sat_malloc(pfsize);
680 if (pfsize && fread(prefix, pfsize, 1, fp) != 1)
682 pool_debug(pool, SAT_ERROR, "read error while reading strings\n");
684 return SOLV_ERROR_EOF;
686 for (i = 1; i < numid; i++)
688 int same = (unsigned char)*pp++;
689 size_t len = strlen (pp) + 1;
691 memcpy(dest, old_str, same);
692 memcpy(dest + same, pp, len);
699 strsp[sizeid] = 0; /* make string space \0 terminated */
702 /* make sure first entry is "" for a store */
705 /* no shared pool, thus no idmap and no unification */
709 pool_debug(pool, SAT_ERROR, "store strings don't start with ''\n");
710 return SOLV_ERROR_CORRUPT;
712 spool->nstrings = numid;
714 for (i = 1; i < spool->nstrings; i++)
716 if (sp >= strsp + sizeid)
718 pool_debug(pool, SAT_ERROR, "not enough strings\n");
719 return SOLV_ERROR_OVERFLOW;
721 str[i] = sp - spool->stringspace;
722 sp += strlen(sp) + 1;
724 spool->sstrings = sp - spool->stringspace;
729 /* alloc id map for name and rel Ids. this maps ids in the solv files
730 * to the ids in our pool */
731 idmap = sat_calloc(numid + numrel, sizeof(Id));
734 * build hashes for all read strings
738 hashmask = mkmask(spool->nstrings + numid);
741 POOL_DEBUG(SAT_DEBUG_STATS, "read %d strings\n", numid);
742 POOL_DEBUG(SAT_DEBUG_STATS, "string hash buckets: %d\n", hashmask + 1);
746 * create hashtable with strings already in pool
749 hashtbl = sat_calloc(hashmask + 1, sizeof(Id));
750 for (i = 1; i < spool->nstrings; i++) /* leave out our dummy zero id */
752 h = strhash(spool->stringspace + spool->strings[i]) & hashmask;
753 hh = HASHCHAIN_START;
755 h = HASHCHAIN_NEXT(h, hh, hashmask);
760 * run over string space, calculate offsets
762 * build id map (maps solv Id -> pool Id)
765 for (i = 1; i < numid; i++)
767 if (sp >= strsp + sizeid)
771 pool_debug(pool, SAT_ERROR, "not enough strings\n");
772 return SOLV_ERROR_OVERFLOW;
774 if (!*sp) /* empty string */
782 h = strhash(sp) & hashmask;
783 hh = HASHCHAIN_START;
789 if (!strcmp(spool->stringspace + spool->strings[id], sp))
790 break; /* existing string */
791 h = HASHCHAIN_NEXT(h, hh, hashmask);
794 /* length == offset to next string */
796 if (id == ID_NULL) /* end of hash chain -> new string */
798 id = spool->nstrings++;
800 str[id] = spool->sstrings; /* save Offset */
801 if (sp != spool->stringspace + spool->sstrings) /* not at end-of-buffer */
802 memmove(spool->stringspace + spool->sstrings, sp, l); /* append to pool buffer */
803 spool->sstrings += l;
805 idmap[i] = id; /* repo relative -> pool relative */
806 sp += l; /* next string */
810 pool_shrink_strings(pool); /* vacuum */
813 /******* Part 2: Relation IDs ***************************************/
823 pool->rels = sat_realloc2(pool->rels, pool->nrels + numrel, sizeof(Reldep));
826 hashmask = mkmask(pool->nrels + numrel);
828 POOL_DEBUG(SAT_DEBUG_STATS, "read %d rels\n", numrel);
829 POOL_DEBUG(SAT_DEBUG_STATS, "rel hash buckets: %d\n", hashmask + 1);
832 * prep hash table with already existing RelDeps
835 hashtbl = sat_calloc(hashmask + 1, sizeof(Id));
836 for (i = 1; i < pool->nrels; i++)
838 h = relhash(ran[i].name, ran[i].evr, ran[i].flags) & hashmask;
839 hh = HASHCHAIN_START;
841 h = HASHCHAIN_NEXT(h, hh, hashmask);
846 * read RelDeps from repo
849 for (i = 0; i < numrel; i++)
851 name = read_id(&data, i + numid); /* read (repo relative) Ids */
852 evr = read_id(&data, i + numid);
853 flags = read_u8(&data);
854 name = idmap[name]; /* map to (pool relative) Ids */
856 h = relhash(name, evr, flags) & hashmask;
857 hh = HASHCHAIN_START;
861 if (id == ID_NULL) /* end of hash chain */
863 if (ran[id].name == name && ran[id].evr == evr && ran[id].flags == flags)
865 h = HASHCHAIN_NEXT(h, hh, hashmask);
867 if (id == ID_NULL) /* new RelDep */
873 ran[id].flags = flags;
875 idmap[i + numid] = MAKERELDEP(id); /* fill Id map */
878 pool_shrink_rels(pool); /* vacuum */
882 /******* Part 3: Dirs ***********************************************/
885 data.dirpool.dirs = sat_malloc2(numdir, sizeof(Id));
886 data.dirpool.ndirs = numdir;
887 data.dirpool.dirs[0] = 0; /* dir 0: virtual root */
888 data.dirpool.dirs[1] = 1; /* dir 1: / */
889 for (i = 2; i < numdir; i++)
891 id = read_id(&data, i + numid);
893 data.dirpool.dirs[i] = -(id - numid);
895 data.dirpool.dirs[i] = idmap[id];
897 data.dirpool.dirs[i] = id;
901 /******* Part 4: Keys ***********************************************/
903 keys = sat_calloc(numkeys, sizeof(*keys));
904 /* keys start at 1 */
905 for (i = 1; i < numkeys; i++)
907 id = read_id(&data, numid);
911 id = str2id(pool, stringpool_id2str(spool, id), 1);
913 keys[i].type = read_id(&data, 0);
914 keys[i].size = read_id(&data, 0);
916 fprintf (stderr, "key %d %s %d %d\n", i, id2str(pool,id), keys[i].type,
919 if (solvversion >= SOLV_VERSION_5)
921 keys[i].storage = read_id(&data, 0);
924 keys[i].storage = KEY_STORAGE_DROPPED;
927 keys[i].storage = KEY_STORAGE_INCORE;
930 switch (keys[i].type)
936 case TYPE_DIRNUMNUMARRAY:
937 keys[i].storage = KEY_STORAGE_INCORE;
945 case SOLVABLE_VENDOR:
946 keys[i].storage = KEY_STORAGE_SOLVABLE;
949 keys[i].storage = KEY_STORAGE_INCORE;
954 case TYPE_REL_IDARRAY:
955 if (id >= INTERESTED_START && id <= INTERESTED_END)
956 keys[i].storage = KEY_STORAGE_SOLVABLE;
958 keys[i].storage = KEY_STORAGE_INCORE;
961 if (id == RPM_RPMDBID)
962 keys[i].storage = KEY_STORAGE_SOLVABLE;
964 keys[i].storage = KEY_STORAGE_INCORE;
971 have_xdata = parent ? 1 : 0;
972 for (i = 1; i < numkeys; i++)
973 if (keys[i].storage == KEY_STORAGE_INCORE || keys[i].storage == KEY_STORAGE_VERTICAL_OFFSET)
977 data.nkeys = numkeys;
979 /******* Part 5: Schemata ********************************************/
981 id = read_id(&data, 0);
982 schemadata = sat_calloc(id + 1, sizeof(Id));
983 schemadatap = schemadata + 1;
984 schemadataend = schemadatap + id;
985 schemata = sat_calloc(numschemata, sizeof(Id));
986 for (i = 1; i < numschemata; i++)
988 schemata[i] = schemadatap - schemadata;
989 schemadatap = read_idarray(&data, numid, 0, schemadatap, schemadataend, 0);
991 Id *sp = schemadata + schemata[i];
992 fprintf (stderr, "schema %d:", i);
994 fprintf (stderr, " %d", *sp);
995 fprintf (stderr, "\n");
998 data.schemata = schemata;
999 data.nschemata = numschemata;
1000 data.schemadata = schemadata;
1001 data.schemadatalen = schemadataend - data.schemadata;
1004 /******* Part 6: Info ***********************************************/
1005 oldnrepodata = repo->nrepodata;
1006 for (i = 0; i < numinfo; i++)
1008 /* for now we're just interested in data that starts with
1009 * the repodata_external id
1012 id = read_id(&data, numschemata);
1013 if (solvversion < SOLV_VERSION_5)
1015 keyp = schemadata + schemata[id];
1017 if (keys[key].name == REPODATA_EXTERNAL && keys[key].type == TYPE_VOID)
1019 /* external data for some ids */
1020 parse_repodata(&data, keyp, keys, idmap, numid, numrel, repo);
1023 skip_schema(&data, keyp, keys, numid, numrel);
1027 /******* Part 7: packed sizes (optional) ****************************/
1029 if ((solvflags & SOLV_FLAG_PACKEDSIZES) != 0)
1031 exists = sat_malloc (numsolv);
1032 for (i = 0; i < numsolv; i++)
1033 exists[i] = read_id(&data, 0) != 0;
1037 /******* Part 8: item data *******************************************/
1039 /* calculate idarray size */
1041 for (i = 1; i < numkeys; i++)
1044 if ((keys[i].type == TYPE_IDARRAY || keys[i].type == TYPE_REL_IDARRAY)
1045 && id >= INTERESTED_START && id <= INTERESTED_END)
1046 size_idarray += keys[i].size;
1049 /* allocate needed space in repo */
1052 repo_reserve_ids(repo, 0, size_idarray);
1053 idarraydatap = repo->idarraydata + repo->idarraysize;
1054 repo->idarraysize += size_idarray;
1055 idarraydataend = idarraydatap + size_idarray;
1064 /* read solvables */
1067 data.start = parent->start;
1068 data.end = parent->end;
1069 s = pool_id2solvable(pool, data.start);
1073 s = pool_id2solvable(pool, repo_add_solvable_block(repo, numsolv));
1074 /* store start and end of our id block */
1075 data.start = s - pool->solvables;
1076 data.end = data.start + numsolv;
1077 /* In case we have subfiles, make them refer to our part of the
1079 for (i = oldnrepodata; i < repo->nrepodata; i++)
1081 repo->repodata[i].start = data.start;
1082 repo->repodata[i].end = data.end;
1089 data.incoreoffset = sat_calloc(numsolv, sizeof(Id));
1090 for (i = 0; i < numsolv; i++, s++)
1095 if (exists && !exists[i])
1097 id = read_id(&data, numschemata);
1098 if (solvversion < SOLV_VERSION_5)
1102 data.incoreoffset[i] = data.incoredatalen;
1103 incore_add_id(&data, id);
1105 keyp = schemadata + schemata[id];
1106 while ((key = *keyp++) != 0)
1108 id = keys[key].name;
1110 fprintf(stderr, "solv %d name %d type %d class %d\n", i, id, keys[key].type, keys[key].storage);
1112 if (keys[key].storage == KEY_STORAGE_VERTICAL_OFFSET)
1114 /* copy offset/length into incore */
1115 did = read_id(&data, 0);
1116 incore_add_id(&data, did);
1117 did = read_id(&data, 0);
1118 incore_add_id(&data, did);
1121 switch (keys[key].type)
1127 did = read_id(&data, numid + numrel);
1130 if (id == SOLVABLE_NAME) {
1133 /* Yeah, thats ugly. Better store kind as u8 in .solv files */
1134 const char *name = id2str(pool, s->name);
1135 const char *colon = strchr(name, ':');
1137 s->kind = colon - name + 1;
1140 else if (id == SOLVABLE_ARCH)
1142 else if (id == SOLVABLE_EVR)
1144 else if (id == SOLVABLE_VENDOR)
1146 else if (keys[key].storage == KEY_STORAGE_INCORE)
1147 incore_add_id(&data, did);
1149 POOL_DEBUG(SAT_DEBUG_STATS, "%s -> %s\n", id2str(pool, id), id2str(pool, did));
1153 did = read_id(&data, 0);
1154 if (keys[key].storage == KEY_STORAGE_INCORE)
1155 incore_add_id(&data, did);
1157 POOL_DEBUG(SAT_DEBUG_STATS, "%s -> %d\n", id2str(pool, id), did);
1161 h = read_u32(&data);
1163 POOL_DEBUG(SAT_DEBUG_STATS, "%s -> %u\n", id2str(pool, id), h);
1165 if (id == RPM_RPMDBID)
1168 repo->rpmdbid = sat_calloc(numsolv, sizeof(Id));
1169 repo->rpmdbid[i] = h;
1171 else if (keys[key].storage == KEY_STORAGE_INCORE)
1172 incore_add_u32(&data, h);
1175 if (keys[key].storage == KEY_STORAGE_INCORE)
1177 while ((h = read_u8(&data)) != 0)
1178 incore_add_u8(&data, h);
1179 incore_add_u8(&data, 0);
1183 while (read_u8(&data) != 0)
1188 case TYPE_REL_IDARRAY:
1189 if (id < INTERESTED_START || id > INTERESTED_END)
1191 if (keys[key].storage == KEY_STORAGE_INCORE)
1195 Id old = 0, rel = keys[key].type == TYPE_REL_IDARRAY ? SOLVABLE_PREREQMARKER : 0;
1198 did = read_id(&data, 0);
1200 did = (did & 0x3f) | ((did >> 1) & ~0x3f);
1214 if (did >= numid + numrel)
1217 did = ((did & ~0x3f) << 1) | h;
1218 incore_add_id(&data, did);
1224 while (((h = read_u8(&data)) & 0xc0) != 0)
1225 incore_add_u8(&data, h);
1231 while ((read_u8(&data) & 0xc0) != 0)
1237 ido = idarraydatap - repo->idarraydata;
1238 idarraydatap = read_idarray(&data, numid + numrel, idmap, idarraydatap, idarraydataend, keys[key].type == TYPE_REL_IDARRAY);
1239 if (id == SOLVABLE_PROVIDES)
1241 else if (id == SOLVABLE_OBSOLETES)
1243 else if (id == SOLVABLE_CONFLICTS)
1245 else if (id == SOLVABLE_REQUIRES)
1247 else if (id == SOLVABLE_RECOMMENDS)
1249 else if (id == SOLVABLE_SUPPLEMENTS)
1250 s->supplements = ido;
1251 else if (id == SOLVABLE_SUGGESTS)
1253 else if (id == SOLVABLE_ENHANCES)
1255 else if (id == SOLVABLE_FRESHENS)
1258 POOL_DEBUG(SAT_DEBUG_STATS, "%s ->\n", id2str(pool, id));
1259 for (; repo->idarraydata[ido]; ido++)
1260 POOL_DEBUG(SAT_DEBUG_STATS," %s\n", dep2str(pool, repo->idarraydata[ido]));
1267 case TYPE_ATTR_CHUNK:
1268 case TYPE_ATTR_STRING:
1269 case TYPE_ATTR_INTLIST:
1270 case TYPE_ATTR_LOCALIDS:
1271 if (!embedded_store)
1272 embedded_store = new_store (pool);
1273 add_attr_from_file (embedded_store, i, id, keys[key].type, idmap, numid, &data, keys[key].size);
1276 case TYPE_DIRNUMNUMARRAY:
1280 did = read_id(&data, numdir);
1281 num = read_id(&data, 0);
1282 num2 = read_id(&data, 0);
1283 if (keys[key].storage == KEY_STORAGE_INCORE)
1286 POOL_DEBUG(SAT_DEBUG_STATS, "%s -> %d %d %d\n", id2str(pool, id), did, num, num2);
1288 incore_add_id(&data, did);
1289 incore_add_id(&data, num);
1290 incore_add_id(&data, num2);
1298 skip_item(&data, keys[key].type, numid, numrel);
1305 /* free solvables */
1306 repo_free_solvable_block(repo, data.start, data.end - data.start, 1);
1308 repo->idarraysize -= size_idarray;
1309 /* free incore data */
1310 data.incoredata = sat_free(data.incoredata);
1311 data.incoredatalen = data.incoredatafree = 0;
1314 if (data.incoredatafree)
1316 /* shrink excess size */
1317 data.incoredata = sat_realloc(data.incoredata, data.incoredatalen);
1318 data.incoredatafree = 0;
1321 for (i = 1; i < numkeys; i++)
1322 if (keys[i].storage == KEY_STORAGE_VERTICAL_OFFSET)
1324 if (i < numkeys && !data.error)
1327 unsigned int pagesize;
1329 /* we have vertical data, make it available */
1330 data.verticaloffset = sat_calloc(numkeys, sizeof(Id));
1331 for (i = 1; i < numkeys; i++)
1332 if (keys[i].storage == KEY_STORAGE_VERTICAL_OFFSET)
1334 data.verticaloffset[i] = fileoffset;
1335 fileoffset += keys[i].size;
1337 data.lastverticaloffset = fileoffset;
1338 pagesize = read_u32(&data);
1339 repodata_read_or_setup_pages(&data, pagesize, fileoffset);
1343 /* no longer needed */
1350 sat_free(parent->schemata);
1351 sat_free(parent->schemadata);
1352 sat_free(parent->keys);
1355 else if (data.incoredatalen || data.fp)
1357 /* we got some data, make it available */
1358 repo->repodata = sat_realloc2(repo->repodata, repo->nrepodata + 1, sizeof(data));
1359 repo->repodata[repo->nrepodata++] = data;
1364 sat_free(data.dirpool.dirs);
1365 sat_free(data.incoreoffset);
1367 sat_free(schemadata);
1375 attr_store_pack (embedded_store);
1376 /* If we have any attributes we also have pages. */
1377 read_or_setup_pages (fp, embedded_store);
1378 /* The NULL name here means embedded attributes. */
1379 repo_add_attrstore (repo, embedded_store, NULL);
1388 repo_add_solv(Repo *repo, FILE *fp)
1390 return repo_add_solv_parent(repo, fp, 0);
1394 repodata_load_solv(Repodata *data)
1398 Pool *pool = data->repo->pool;
1399 if (!pool->loadcallback)
1401 data->state = REPODATA_ERROR;
1404 fp = pool->loadcallback(pool, data, pool->loadcallbackdata);
1411 data->state = REPODATA_ERROR;
1414 if (repo_add_solv_parent(data->repo, fp, data))
1415 data->state = REPODATA_ERROR;
1417 data->state = REPODATA_AVAILABLE;