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;
545 struct _Stringpool *spool;
549 memset(&data, 0, sizeof(data));
555 if (read_u32(&data) != ('S' << 24 | 'O' << 16 | 'L' << 8 | 'V'))
557 pool_debug(pool, SAT_ERROR, "not a SOLV file\n");
558 return SOLV_ERROR_NOT_SOLV;
560 solvversion = read_u32(&data);
571 pool_debug(pool, SAT_ERROR, "unsupported SOLV version\n");
572 return SOLV_ERROR_UNSUPPORTED;
575 pool_freeidhashes(pool);
577 numid = read_u32(&data);
578 numrel = read_u32(&data);
579 if (solvversion >= SOLV_VERSION_4)
580 numdir = read_u32(&data);
583 numsolv = read_u32(&data);
584 numkeys = read_u32(&data);
585 numschemata = read_u32(&data);
586 numinfo = read_u32(&data);
587 solvflags = read_u32(&data);
589 if (solvversion < SOLV_VERSION_5)
592 if (numdir && numdir < 2)
594 pool_debug(pool, SAT_ERROR, "bad number of dirs\n");
595 return SOLV_ERROR_CORRUPT;
597 if (numinfo && solvversion < SOLV_VERSION_3)
599 pool_debug(pool, SAT_ERROR, "unsupported SOLV format (has info)\n");
600 return SOLV_ERROR_UNSUPPORTED;
607 pool_debug(pool, SAT_ERROR, "relations are forbidden in a store\n");
608 return SOLV_ERROR_CORRUPT;
610 if (parent->end - parent->start != numsolv)
612 pool_debug(pool, SAT_ERROR, "unequal number of solvables in a store\n");
613 return SOLV_ERROR_CORRUPT;
617 pool_debug(pool, SAT_ERROR, "info blocks are forbidden in a store\n");
618 return SOLV_ERROR_CORRUPT;
622 /******* Part 1: string IDs *****************************************/
624 sizeid = read_u32(&data); /* size of string+Id space */
627 * read strings and Ids
642 spool->stringspace = sat_malloc(7);
643 strcpy(spool->stringspace, "<NULL>");
648 /* alloc string buffer */
649 spool->stringspace = sat_realloc(spool->stringspace, spool->sstrings + sizeid + 1);
650 /* alloc string offsets (Id -> Offset into string space) */
651 spool->strings = sat_realloc2(spool->strings, spool->nstrings + numid, sizeof(Offset));
653 strsp = spool->stringspace;
654 str = spool->strings; /* array of offsets into strsp, indexed by Id */
656 /* point to _BEHIND_ already allocated string/Id space */
657 strsp += spool->sstrings;
661 * read new repo at end of pool
664 if ((solvflags & SOLV_FLAG_PREFIX_POOL) == 0)
666 if (sizeid && fread(strsp, sizeid, 1, fp) != 1)
668 pool_debug(pool, SAT_ERROR, "read error while reading strings\n");
669 return SOLV_ERROR_EOF;
674 unsigned int pfsize = read_u32(&data);
675 char *prefix = sat_malloc(pfsize);
679 if (pfsize && fread(prefix, pfsize, 1, fp) != 1)
681 pool_debug(pool, SAT_ERROR, "read error while reading strings\n");
683 return SOLV_ERROR_EOF;
685 for (i = 1; i < numid; i++)
687 int same = (unsigned char)*pp++;
688 size_t len = strlen (pp) + 1;
690 memcpy(dest, old_str, same);
691 memcpy(dest + same, pp, len);
698 strsp[sizeid] = 0; /* make string space \0 terminated */
701 /* make sure first entry is "" for a store */
704 /* no shared pool, thus no idmap and no unification */
708 pool_debug(pool, SAT_ERROR, "store strings don't start with ''\n");
709 return SOLV_ERROR_CORRUPT;
711 spool->nstrings = numid;
713 for (i = 1; i < spool->nstrings; i++)
715 if (sp >= strsp + sizeid)
717 pool_debug(pool, SAT_ERROR, "not enough strings\n");
718 return SOLV_ERROR_OVERFLOW;
720 str[i] = sp - spool->stringspace;
721 sp += strlen(sp) + 1;
723 spool->sstrings = sp - spool->stringspace;
728 /* alloc id map for name and rel Ids. this maps ids in the solv files
729 * to the ids in our pool */
730 idmap = sat_calloc(numid + numrel, sizeof(Id));
733 * build hashes for all read strings
737 hashmask = mkmask(spool->nstrings + numid);
740 POOL_DEBUG(SAT_DEBUG_STATS, "read %d strings\n", numid);
741 POOL_DEBUG(SAT_DEBUG_STATS, "string hash buckets: %d\n", hashmask + 1);
745 * create hashtable with strings already in pool
748 hashtbl = sat_calloc(hashmask + 1, sizeof(Id));
749 for (i = 1; i < spool->nstrings; i++) /* leave out our dummy zero id */
751 h = strhash(spool->stringspace + spool->strings[i]) & hashmask;
752 hh = HASHCHAIN_START;
754 h = HASHCHAIN_NEXT(h, hh, hashmask);
759 * run over string space, calculate offsets
761 * build id map (maps solv Id -> pool Id)
764 for (i = 1; i < numid; i++)
766 if (sp >= strsp + sizeid)
770 pool_debug(pool, SAT_ERROR, "not enough strings\n");
771 return SOLV_ERROR_OVERFLOW;
773 if (!*sp) /* empty string */
781 h = strhash(sp) & hashmask;
782 hh = HASHCHAIN_START;
788 if (!strcmp(spool->stringspace + spool->strings[id], sp))
789 break; /* existing string */
790 h = HASHCHAIN_NEXT(h, hh, hashmask);
793 /* length == offset to next string */
795 if (id == ID_NULL) /* end of hash chain -> new string */
797 id = spool->nstrings++;
799 str[id] = spool->sstrings; /* save Offset */
800 if (sp != spool->stringspace + spool->sstrings) /* not at end-of-buffer */
801 memmove(spool->stringspace + spool->sstrings, sp, l); /* append to pool buffer */
802 spool->sstrings += l;
804 idmap[i] = id; /* repo relative -> pool relative */
805 sp += l; /* next string */
809 pool_shrink_strings(pool); /* vacuum */
812 /******* Part 2: Relation IDs ***************************************/
822 pool->rels = sat_realloc2(pool->rels, pool->nrels + numrel, sizeof(Reldep));
825 hashmask = mkmask(pool->nrels + numrel);
827 POOL_DEBUG(SAT_DEBUG_STATS, "read %d rels\n", numrel);
828 POOL_DEBUG(SAT_DEBUG_STATS, "rel hash buckets: %d\n", hashmask + 1);
831 * prep hash table with already existing RelDeps
834 hashtbl = sat_calloc(hashmask + 1, sizeof(Id));
835 for (i = 1; i < pool->nrels; i++)
837 h = relhash(ran[i].name, ran[i].evr, ran[i].flags) & hashmask;
838 hh = HASHCHAIN_START;
840 h = HASHCHAIN_NEXT(h, hh, hashmask);
845 * read RelDeps from repo
848 for (i = 0; i < numrel; i++)
850 name = read_id(&data, i + numid); /* read (repo relative) Ids */
851 evr = read_id(&data, i + numid);
852 flags = read_u8(&data);
853 name = idmap[name]; /* map to (pool relative) Ids */
855 h = relhash(name, evr, flags) & hashmask;
856 hh = HASHCHAIN_START;
860 if (id == ID_NULL) /* end of hash chain */
862 if (ran[id].name == name && ran[id].evr == evr && ran[id].flags == flags)
864 h = HASHCHAIN_NEXT(h, hh, hashmask);
866 if (id == ID_NULL) /* new RelDep */
872 ran[id].flags = flags;
874 idmap[i + numid] = MAKERELDEP(id); /* fill Id map */
877 pool_shrink_rels(pool); /* vacuum */
881 /******* Part 3: Dirs ***********************************************/
884 data.dirpool.dirs = sat_malloc2(numdir, sizeof(Id));
885 data.dirpool.ndirs = numdir;
886 data.dirpool.dirs[0] = 0; /* dir 0: virtual root */
887 data.dirpool.dirs[1] = 1; /* dir 1: / */
888 for (i = 2; i < numdir; i++)
890 id = read_id(&data, i + numid);
892 data.dirpool.dirs[i] = -(id - numid);
894 data.dirpool.dirs[i] = idmap[id];
896 data.dirpool.dirs[i] = id;
900 /******* Part 4: Keys ***********************************************/
902 keys = sat_calloc(numkeys, sizeof(*keys));
903 /* keys start at 1 */
904 for (i = 1; i < numkeys; i++)
906 id = read_id(&data, numid);
910 id = str2id(pool, stringpool_id2str(spool, id), 1);
912 keys[i].type = read_id(&data, 0);
913 keys[i].size = read_id(&data, 0);
915 fprintf (stderr, "key %d %s %d %d\n", i, id2str(pool,id), keys[i].type,
918 if (solvversion >= SOLV_VERSION_5)
920 keys[i].storage = read_id(&data, 0);
923 keys[i].storage = KEY_STORAGE_DROPPED;
926 keys[i].storage = KEY_STORAGE_INCORE;
929 switch (keys[i].type)
935 case TYPE_DIRNUMNUMARRAY:
936 keys[i].storage = KEY_STORAGE_INCORE;
944 case SOLVABLE_VENDOR:
945 keys[i].storage = KEY_STORAGE_SOLVABLE;
948 keys[i].storage = KEY_STORAGE_INCORE;
953 case TYPE_REL_IDARRAY:
954 if (id >= INTERESTED_START && id <= INTERESTED_END)
955 keys[i].storage = KEY_STORAGE_SOLVABLE;
957 keys[i].storage = KEY_STORAGE_INCORE;
960 if (id == RPM_RPMDBID)
961 keys[i].storage = KEY_STORAGE_SOLVABLE;
963 keys[i].storage = KEY_STORAGE_INCORE;
970 have_xdata = parent ? 1 : 0;
971 for (i = 1; i < numkeys; i++)
972 if (keys[i].storage == KEY_STORAGE_INCORE || keys[i].storage == KEY_STORAGE_VERTICAL_OFFSET)
976 data.nkeys = numkeys;
978 /******* Part 5: Schemata ********************************************/
980 id = read_id(&data, 0);
981 schemadata = sat_calloc(id + 1, sizeof(Id));
982 schemadatap = schemadata + 1;
983 schemadataend = schemadatap + id;
984 schemata = sat_calloc(numschemata, sizeof(Id));
985 for (i = 1; i < numschemata; i++)
987 schemata[i] = schemadatap - schemadata;
988 schemadatap = read_idarray(&data, numid, 0, schemadatap, schemadataend, 0);
990 Id *sp = schemadata + schemata[i];
991 fprintf (stderr, "schema %d:", i);
993 fprintf (stderr, " %d", *sp);
994 fprintf (stderr, "\n");
997 data.schemata = schemata;
998 data.nschemata = numschemata;
999 data.schemadata = schemadata;
1000 data.schemadatalen = schemadataend - data.schemadata;
1003 /******* Part 6: Info ***********************************************/
1004 for (i = 0; i < numinfo; i++)
1006 /* for now we're just interested in data that starts with
1007 * the repodata_external id
1010 id = read_id(&data, numschemata);
1011 if (solvversion < SOLV_VERSION_5)
1013 keyp = schemadata + schemata[id];
1015 if (keys[key].name == REPODATA_EXTERNAL && keys[key].type == TYPE_VOID)
1017 /* external data for some ids */
1018 parse_repodata(&data, keyp, keys, idmap, numid, numrel, repo);
1021 skip_schema(&data, keyp, keys, numid, numrel);
1025 /******* Part 7: packed sizes (optional) ****************************/
1027 if ((solvflags & SOLV_FLAG_PACKEDSIZES) != 0)
1029 exists = sat_malloc (numsolv);
1030 for (i = 0; i < numsolv; i++)
1031 exists[i] = read_id(&data, 0) != 0;
1035 /******* Part 8: item data *******************************************/
1037 /* calculate idarray size */
1039 for (i = 1; i < numkeys; i++)
1042 if ((keys[i].type == TYPE_IDARRAY || keys[i].type == TYPE_REL_IDARRAY)
1043 && id >= INTERESTED_START && id <= INTERESTED_END)
1044 size_idarray += keys[i].size;
1047 /* allocate needed space in repo */
1050 repo_reserve_ids(repo, 0, size_idarray);
1051 idarraydatap = repo->idarraydata + repo->idarraysize;
1052 repo->idarraysize += size_idarray;
1053 idarraydataend = idarraydatap + size_idarray;
1062 /* read solvables */
1065 data.start = parent->start;
1066 data.end = parent->end;
1067 s = pool_id2solvable(pool, data.start);
1071 s = pool_id2solvable(pool, repo_add_solvable_block(repo, numsolv));
1072 /* store start and end of our id block */
1073 data.start = s - pool->solvables;
1074 data.end = data.start + numsolv;
1075 /* In case we have subfiles, make them refer to our part of the
1077 for (i = 0; i < repo->nrepodata; i++)
1079 repo->repodata[i].start = data.start;
1080 repo->repodata[i].end = data.end;
1087 data.incoreoffset = sat_calloc(numsolv, sizeof(Id));
1088 for (i = 0; i < numsolv; i++, s++)
1093 if (exists && !exists[i])
1095 id = read_id(&data, numschemata);
1096 if (solvversion < SOLV_VERSION_5)
1100 data.incoreoffset[i] = data.incoredatalen;
1101 incore_add_id(&data, id);
1103 keyp = schemadata + schemata[id];
1104 while ((key = *keyp++) != 0)
1106 id = keys[key].name;
1108 fprintf(stderr, "solv %d name %d type %d class %d\n", i, id, keys[key].type, keys[key].storage);
1110 if (keys[key].storage == KEY_STORAGE_VERTICAL_OFFSET)
1112 /* copy offset/length into incore */
1113 did = read_id(&data, 0);
1114 incore_add_id(&data, did);
1115 did = read_id(&data, 0);
1116 incore_add_id(&data, did);
1119 switch (keys[key].type)
1125 did = read_id(&data, numid + numrel);
1128 if (id == SOLVABLE_NAME) {
1131 /* Yeah, thats ugly. Better store kind as u8 in .solv files */
1132 const char *name = id2str(pool, s->name);
1133 const char *colon = strchr(name, ':');
1135 s->kind = colon - name + 1;
1138 else if (id == SOLVABLE_ARCH)
1140 else if (id == SOLVABLE_EVR)
1142 else if (id == SOLVABLE_VENDOR)
1144 else if (keys[key].storage == KEY_STORAGE_INCORE)
1145 incore_add_id(&data, did);
1147 POOL_DEBUG(SAT_DEBUG_STATS, "%s -> %s\n", id2str(pool, id), id2str(pool, did));
1151 did = read_id(&data, 0);
1152 if (keys[key].storage == KEY_STORAGE_INCORE)
1153 incore_add_id(&data, did);
1155 POOL_DEBUG(SAT_DEBUG_STATS, "%s -> %d\n", id2str(pool, id), did);
1159 h = read_u32(&data);
1161 POOL_DEBUG(SAT_DEBUG_STATS, "%s -> %u\n", id2str(pool, id), h);
1163 if (id == RPM_RPMDBID)
1166 repo->rpmdbid = sat_calloc(numsolv, sizeof(Id));
1167 repo->rpmdbid[i] = h;
1169 else if (keys[key].storage == KEY_STORAGE_INCORE)
1170 incore_add_u32(&data, h);
1173 if (keys[key].storage == KEY_STORAGE_INCORE)
1175 while ((h = read_u8(&data)) != 0)
1176 incore_add_u8(&data, h);
1177 incore_add_u8(&data, 0);
1181 while (read_u8(&data) != 0)
1186 case TYPE_REL_IDARRAY:
1187 if (id < INTERESTED_START || id > INTERESTED_END)
1189 if (keys[key].storage == KEY_STORAGE_INCORE)
1193 Id old = 0, rel = keys[key].type == TYPE_REL_IDARRAY ? SOLVABLE_PREREQMARKER : 0;
1196 did = read_id(&data, 0);
1198 did = (did & 0x3f) | ((did >> 1) & ~0x3f);
1212 if (did >= numid + numrel)
1215 did = ((did & ~0x3f) << 1) | h;
1216 incore_add_id(&data, did);
1222 while (((h = read_u8(&data)) & 0xc0) != 0)
1223 incore_add_u8(&data, h);
1229 while ((read_u8(&data) & 0xc0) != 0)
1235 ido = idarraydatap - repo->idarraydata;
1236 idarraydatap = read_idarray(&data, numid + numrel, idmap, idarraydatap, idarraydataend, keys[key].type == TYPE_REL_IDARRAY);
1237 if (id == SOLVABLE_PROVIDES)
1239 else if (id == SOLVABLE_OBSOLETES)
1241 else if (id == SOLVABLE_CONFLICTS)
1243 else if (id == SOLVABLE_REQUIRES)
1245 else if (id == SOLVABLE_RECOMMENDS)
1247 else if (id == SOLVABLE_SUPPLEMENTS)
1248 s->supplements = ido;
1249 else if (id == SOLVABLE_SUGGESTS)
1251 else if (id == SOLVABLE_ENHANCES)
1253 else if (id == SOLVABLE_FRESHENS)
1256 POOL_DEBUG(SAT_DEBUG_STATS, "%s ->\n", id2str(pool, id));
1257 for (; repo->idarraydata[ido]; ido++)
1258 POOL_DEBUG(SAT_DEBUG_STATS," %s\n", dep2str(pool, repo->idarraydata[ido]));
1265 case TYPE_ATTR_CHUNK:
1266 case TYPE_ATTR_STRING:
1267 case TYPE_ATTR_INTLIST:
1268 case TYPE_ATTR_LOCALIDS:
1269 if (!embedded_store)
1270 embedded_store = new_store (pool);
1271 add_attr_from_file (embedded_store, i, id, keys[key].type, idmap, numid, &data, keys[key].size);
1274 case TYPE_DIRNUMNUMARRAY:
1278 did = read_id(&data, numdir);
1279 num = read_id(&data, 0);
1280 num2 = read_id(&data, 0);
1281 if (keys[key].storage == KEY_STORAGE_INCORE)
1284 POOL_DEBUG(SAT_DEBUG_STATS, "%s -> %d %d %d\n", id2str(pool, id), did, num, num2);
1286 incore_add_id(&data, did);
1287 incore_add_id(&data, num);
1288 incore_add_id(&data, num2);
1296 skip_item(&data, keys[key].type, numid, numrel);
1303 /* free solvables */
1304 repo_free_solvable_block(repo, data.start, data.end - data.start, 1);
1306 repo->idarraysize -= size_idarray;
1307 /* free incore data */
1308 data.incoredata = sat_free(data.incoredata);
1309 data.incoredatalen = data.incoredatafree = 0;
1312 if (data.incoredatafree)
1314 /* shrink excess size */
1315 data.incoredata = sat_realloc(data.incoredata, data.incoredatalen);
1316 data.incoredatafree = 0;
1319 for (i = 1; i < numkeys; i++)
1320 if (keys[i].storage == KEY_STORAGE_VERTICAL_OFFSET)
1322 if (i < numkeys && !data.error)
1325 unsigned int pagesize;
1327 /* we have vertical data, make it available */
1328 data.verticaloffset = sat_calloc(numkeys, sizeof(Id));
1329 for (i = 1; i < numkeys; i++)
1330 if (keys[i].storage == KEY_STORAGE_VERTICAL_OFFSET)
1332 data.verticaloffset[i] = fileoffset;
1333 fileoffset += keys[i].size;
1335 data.lastverticaloffset = fileoffset;
1336 pagesize = read_u32(&data);
1337 repodata_read_or_setup_pages(&data, pagesize, fileoffset);
1341 /* no longer needed */
1348 sat_free(parent->schemata);
1349 sat_free(parent->schemadata);
1350 sat_free(parent->keys);
1353 else if (data.incoredatalen || data.fp)
1355 /* we got some data, make it available */
1356 repo->repodata = sat_realloc2(repo->repodata, repo->nrepodata + 1, sizeof(data));
1357 repo->repodata[repo->nrepodata++] = data;
1362 sat_free(data.dirpool.dirs);
1363 sat_free(data.incoreoffset);
1365 sat_free(schemadata);
1373 attr_store_pack (embedded_store);
1374 /* If we have any attributes we also have pages. */
1375 read_or_setup_pages (fp, embedded_store);
1376 /* The NULL name here means embedded attributes. */
1377 repo_add_attrstore (repo, embedded_store, NULL);
1386 repo_add_solv(Repo *repo, FILE *fp)
1388 return repo_add_solv_parent(repo, fp, 0);
1392 repodata_load_solv(Repodata *data)
1396 Pool *pool = data->repo->pool;
1397 if (!pool->loadcallback)
1399 data->state = REPODATA_ERROR;
1402 fp = pool->loadcallback(pool, data, pool->loadcallbackdata);
1409 data->state = REPODATA_ERROR;
1412 if (repo_add_solv_parent(data->repo, fp, data))
1413 data->state = REPODATA_ERROR;
1415 data->state = REPODATA_AVAILABLE;