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 #define INTERESTED_START SOLVABLE_NAME
30 #define INTERESTED_END SOLVABLE_FRESHENS
32 #define SOLV_ERROR_NOT_SOLV 1
33 #define SOLV_ERROR_UNSUPPORTED 2
34 #define SOLV_ERROR_EOF 3
35 #define SOLV_ERROR_ID_RANGE 4
36 #define SOLV_ERROR_OVERFLOW 5
37 #define SOLV_ERROR_CORRUPT 6
39 static Pool *mypool; /* for pool_debug... */
41 /*-----------------------------------------------------------------*/
42 /* .solv read functions */
49 read_u32(Repodata *data)
56 for (i = 0; i < 4; i++)
61 pool_debug(mypool, SAT_ERROR, "unexpected EOF\n");
62 data->error = SOLV_ERROR_EOF;
76 read_u8(Repodata *data)
85 pool_debug(mypool, SAT_ERROR, "unexpected EOF\n");
86 data->error = SOLV_ERROR_EOF;
98 read_id(Repodata *data, Id max)
105 for (i = 0; i < 5; i++)
110 pool_debug(mypool, SAT_ERROR, "unexpected EOF\n");
111 data->error = SOLV_ERROR_EOF;
119 pool_debug(mypool, SAT_ERROR, "read_id: id too large (%u/%u)\n", x, max);
120 data->error = SOLV_ERROR_ID_RANGE;
125 x = (x << 7) ^ c ^ 128;
127 pool_debug(mypool, SAT_ERROR, "read_id: id too long\n");
128 data->error = SOLV_ERROR_CORRUPT;
138 read_idarray(Repodata *data, Id max, Id *map, Id *store, Id *end, int relative)
151 pool_debug(mypool, SAT_ERROR, "unexpected EOF\n");
152 data->error = SOLV_ERROR_EOF;
157 x = (x << 6) | (c & 63);
160 if (x == 0 && c == 0x40)
165 pool_debug(mypool, SAT_ERROR, "read_idarray: array overflow\n");
166 data->error = SOLV_ERROR_OVERFLOW;
169 *store++ = SOLVABLE_PREREQMARKER;
179 pool_debug(mypool, SAT_ERROR, "read_idarray: id too large (%u/%u)\n", x, max);
180 data->error = SOLV_ERROR_ID_RANGE;
187 pool_debug(mypool, SAT_ERROR, "read_idarray: array overflow\n");
193 if (x == 0) /* already have trailing zero? */
197 pool_debug(mypool, SAT_ERROR, "read_idarray: array overflow\n");
198 data->error = SOLV_ERROR_OVERFLOW;
207 x = (x << 7) ^ c ^ 128;
212 read_str(Repodata *data, char **inbuf, unsigned *len)
214 unsigned char *buf = (unsigned char*)*inbuf;
217 buf = sat_malloc(1024);
222 while((c = getc(data->fp)) != 0)
226 pool_debug (mypool, SAT_ERROR, "unexpected EOF\n");
227 data->error = SOLV_ERROR_EOF;
230 /* Plus 1 as we also want to add the 0. */
234 /* Don't realloc on the inbuf, it might be on the stack. */
235 if (buf == (unsigned char*)*inbuf)
237 buf = sat_malloc(*len);
238 memcpy(buf, *inbuf, *len - 256);
241 buf = sat_realloc(buf, *len);
250 skip_item (Repodata *data, unsigned type, unsigned numid, unsigned numrel)
258 read_id(data, numid + numrel); /* just check Id */
261 read_id(data, numid + data->dirpool.ndirs); /* just check Id */
269 case TYPE_ATTR_STRING:
271 while (read_u8(data) != 0)
275 case TYPE_REL_IDARRAY:
276 case TYPE_ATTR_INTLIST:
277 while ((read_u8(data) & 0xc0) != 0)
280 case TYPE_DIRNUMNUMARRAY:
283 read_id(data, numid + data->dirpool.ndirs); /* just check Id */
285 if (!(read_id(data, 0) & 0x40))
289 case TYPE_DIRSTRARRAY:
292 Id id = read_id(data, 0);
293 while (read_u8(data) != 0)
299 case TYPE_COUNT_NAMED:
301 unsigned count = read_id(data, 0);
304 read_id(data, numid); /* Name */
305 unsigned t = read_id(data, TYPE_ATTR_TYPE_MAX + 1);
306 skip_item(data, t, numid, numrel);
312 unsigned count = read_id(data, 0);
313 unsigned t = read_id(data, TYPE_ATTR_TYPE_MAX + 1);
315 skip_item(data, t, numid, numrel);
318 case TYPE_ATTR_CHUNK:
324 case TYPE_ATTR_LOCALIDS:
325 while (read_id(data, 0) != 0)
329 pool_debug(mypool, SAT_ERROR, "unknown type %d\n", type);
330 data->error = SOLV_ERROR_CORRUPT;
336 key_cmp (const void *pa, const void *pb)
338 Repokey *a = (Repokey *)pa;
339 Repokey *b = (Repokey *)pb;
340 return a->name - b->name;
343 static void repodata_load_solv(Repodata *data);
346 parse_repodata(Repodata *maindata, Id *keyp, Repokey *keys, Id *idmap, unsigned numid, unsigned numrel, Repo *repo)
353 repo->repodata = sat_realloc2(repo->repodata, repo->nrepodata + 1, sizeof (*data));
354 data = repo->repodata + repo->nrepodata++;
355 memset(data, 0, sizeof(*data));
357 data->state = REPODATA_STUB;
358 data->loadcallback = repodata_load_solv;
360 while ((key = *keyp++) != 0)
363 switch (keys[key].type)
365 case TYPE_IDVALUEARRAY:
366 if (id != REPODATA_KEYS)
368 skip_item(maindata, TYPE_IDVALUEARRAY, numid, numrel);
371 /* read_idarray writes a terminating 0, that's why the + 1 */
372 ida = sat_calloc(keys[key].size + 1, sizeof(Id));
373 ide = read_idarray(maindata, 0, 0, ida, ida + keys[key].size + 1, 0);
377 pool_debug (mypool, SAT_ERROR, "invalid attribute data\n");
378 data->error = SOLV_ERROR_CORRUPT;
381 data->nkeys = 1 + (n >> 1);
382 data->keys = sat_malloc2(data->nkeys, sizeof(data->keys[0]));
383 memset(data->keys, 0, sizeof(Repokey));
384 for (i = 1, ide = ida; i < data->nkeys; i++)
388 pool_debug (mypool, SAT_ERROR, "invalid attribute data\n");
389 data->error = SOLV_ERROR_CORRUPT;
392 data->keys[i].name = idmap ? idmap[*ide++] : *ide++;
393 data->keys[i].type = *ide++;
394 data->keys[i].size = 0;
395 data->keys[i].storage = 0;
399 qsort(data->keys + 1, data->nkeys - 1, sizeof(data->keys[0]), key_cmp);
402 if (id != REPODATA_LOCATION)
403 skip_item(maindata, TYPE_STR, numid, numrel);
407 unsigned len = sizeof (buf);
408 char *filename = buf;
409 read_str(maindata, &filename, &len);
410 data->location = strdup(filename);
416 skip_item(maindata, keys[key].type, numid, numrel);
422 /*-----------------------------------------------------------------*/
426 skip_schema(Repodata *data, Id *keyp, Repokey *keys, unsigned int numid, unsigned int numrel)
429 while ((key = *keyp++) != 0)
430 skip_item(data, keys[key].type, numid, numrel);
433 /*-----------------------------------------------------------------*/
436 incore_add_id(Repodata *data, Id x)
439 /* make sure we have at least 5 bytes free */
440 if (data->incoredatafree < 5)
442 data->incoredata = sat_realloc(data->incoredata, data->incoredatalen + 1024);
443 data->incoredatafree = 1024;
445 dp = data->incoredata + data->incoredatalen;
451 *dp++ = (x >> 28) | 128;
453 *dp++ = (x >> 21) | 128;
454 *dp++ = (x >> 14) | 128;
457 *dp++ = (x >> 7) | 128;
459 data->incoredatafree -= dp - (data->incoredata + data->incoredatalen);
460 data->incoredatalen = dp - data->incoredata;
464 incore_add_u32(Repodata *data, unsigned int x)
467 /* make sure we have at least 4 bytes free */
468 if (data->incoredatafree < 4)
470 data->incoredata = sat_realloc(data->incoredata, data->incoredatalen + 1024);
471 data->incoredatafree = 1024;
473 dp = data->incoredata + data->incoredatalen;
478 data->incoredatafree -= 4;
479 data->incoredatalen += 4;
483 incore_add_u8(Repodata *data, unsigned int x)
486 /* make sure we have at least 1 byte free */
487 if (data->incoredatafree < 1)
489 data->incoredata = sat_realloc(data->incoredata, data->incoredatalen + 1024);
490 data->incoredatafree = 1024;
492 dp = data->incoredata + data->incoredatalen;
494 data->incoredatafree--;
495 data->incoredatalen++;
500 // ----------------------------------------------
504 * read repo from .solv file
509 repo_add_solv_parent(Repo *repo, FILE *fp, Repodata *parent)
511 Pool *pool = repo->pool;
513 unsigned int numid, numrel, numdir, numsolv;
514 unsigned int numkeys, numschemata, numinfo;
517 Offset *str; /* map Id -> Offset into string space */
518 char *strsp; /* repo string space */
519 char *sp; /* pointer into string space */
520 Id *idmap; /* map of repo Ids to pool Ids */
522 unsigned int hashmask, h;
528 unsigned int size_idarray;
529 Id *idarraydatap, *idarraydataend;
532 unsigned int solvflags;
533 unsigned int solvversion;
535 Id *schemadata, *schemadatap, *schemadataend;
538 unsigned oldnrepodata;
540 struct _Stringpool *spool;
544 memset(&data, 0, sizeof(data));
550 if (read_u32(&data) != ('S' << 24 | 'O' << 16 | 'L' << 8 | 'V'))
552 pool_debug(pool, SAT_ERROR, "not a SOLV file\n");
553 return SOLV_ERROR_NOT_SOLV;
555 solvversion = read_u32(&data);
565 pool_debug(pool, SAT_ERROR, "unsupported SOLV version\n");
566 return SOLV_ERROR_UNSUPPORTED;
569 pool_freeidhashes(pool);
571 numid = read_u32(&data);
572 numrel = read_u32(&data);
573 if (solvversion >= SOLV_VERSION_4)
574 numdir = read_u32(&data);
577 numsolv = read_u32(&data);
578 numkeys = read_u32(&data);
579 numschemata = read_u32(&data);
580 numinfo = read_u32(&data);
581 solvflags = read_u32(&data);
583 if (solvversion < SOLV_VERSION_5)
586 if (numdir && numdir < 2)
588 pool_debug(pool, SAT_ERROR, "bad number of dirs\n");
589 return SOLV_ERROR_CORRUPT;
591 if (numinfo && solvversion < SOLV_VERSION_3)
593 pool_debug(pool, SAT_ERROR, "unsupported SOLV format (has info)\n");
594 return SOLV_ERROR_UNSUPPORTED;
601 pool_debug(pool, SAT_ERROR, "relations are forbidden in a store\n");
602 return SOLV_ERROR_CORRUPT;
604 if (parent->end - parent->start != numsolv)
606 pool_debug(pool, SAT_ERROR, "unequal number of solvables in a store\n");
607 return SOLV_ERROR_CORRUPT;
611 pool_debug(pool, SAT_ERROR, "info blocks are forbidden in a store\n");
612 return SOLV_ERROR_CORRUPT;
616 /******* Part 1: string IDs *****************************************/
618 sizeid = read_u32(&data); /* size of string+Id space */
621 * read strings and Ids
636 spool->stringspace = sat_malloc(7);
637 strcpy(spool->stringspace, "<NULL>");
642 /* alloc string buffer */
643 spool->stringspace = sat_realloc(spool->stringspace, spool->sstrings + sizeid + 1);
644 /* alloc string offsets (Id -> Offset into string space) */
645 spool->strings = sat_realloc2(spool->strings, spool->nstrings + numid, sizeof(Offset));
647 strsp = spool->stringspace;
648 str = spool->strings; /* array of offsets into strsp, indexed by Id */
650 /* point to _BEHIND_ already allocated string/Id space */
651 strsp += spool->sstrings;
655 * read new repo at end of pool
658 if ((solvflags & SOLV_FLAG_PREFIX_POOL) == 0)
660 if (sizeid && fread(strsp, sizeid, 1, fp) != 1)
662 pool_debug(pool, SAT_ERROR, "read error while reading strings\n");
663 return SOLV_ERROR_EOF;
668 unsigned int pfsize = read_u32(&data);
669 char *prefix = sat_malloc(pfsize);
673 if (pfsize && fread(prefix, pfsize, 1, fp) != 1)
675 pool_debug(pool, SAT_ERROR, "read error while reading strings\n");
677 return SOLV_ERROR_EOF;
679 for (i = 1; i < numid; i++)
681 int same = (unsigned char)*pp++;
682 size_t len = strlen (pp) + 1;
684 memcpy(dest, old_str, same);
685 memcpy(dest + same, pp, len);
692 strsp[sizeid] = 0; /* make string space \0 terminated */
697 /* no shared pool, thus no idmap and no unification */
699 spool->nstrings = numid;
701 for (i = 1; i < spool->nstrings; i++)
703 if (sp >= strsp + sizeid)
705 pool_debug(pool, SAT_ERROR, "not enough strings\n");
706 return SOLV_ERROR_OVERFLOW;
708 str[i] = sp - spool->stringspace;
709 sp += strlen(sp) + 1;
711 spool->sstrings = sp - spool->stringspace;
716 /* alloc id map for name and rel Ids. this maps ids in the solv files
717 * to the ids in our pool */
718 idmap = sat_calloc(numid + numrel, sizeof(Id));
721 * build hashes for all read strings
725 hashmask = mkmask(spool->nstrings + numid);
728 POOL_DEBUG(SAT_DEBUG_STATS, "read %d strings\n", numid);
729 POOL_DEBUG(SAT_DEBUG_STATS, "string hash buckets: %d\n", hashmask + 1);
733 * create hashtable with strings already in pool
736 hashtbl = sat_calloc(hashmask + 1, sizeof(Id));
737 for (i = 1; i < spool->nstrings; i++) /* leave out our dummy zero id */
739 h = strhash(spool->stringspace + spool->strings[i]) & hashmask;
740 hh = HASHCHAIN_START;
742 h = HASHCHAIN_NEXT(h, hh, hashmask);
747 * run over string space, calculate offsets
749 * build id map (maps solv Id -> pool Id)
752 for (i = 1; i < numid; i++)
754 if (sp >= strsp + sizeid)
758 pool_debug(pool, SAT_ERROR, "not enough strings\n");
759 return SOLV_ERROR_OVERFLOW;
761 if (!*sp) /* empty string */
769 h = strhash(sp) & hashmask;
770 hh = HASHCHAIN_START;
776 if (!strcmp(spool->stringspace + spool->strings[id], sp))
777 break; /* existing string */
778 h = HASHCHAIN_NEXT(h, hh, hashmask);
781 /* length == offset to next string */
783 if (id == ID_NULL) /* end of hash chain -> new string */
785 id = spool->nstrings++;
787 str[id] = spool->sstrings; /* save Offset */
788 if (sp != spool->stringspace + spool->sstrings) /* not at end-of-buffer */
789 memmove(spool->stringspace + spool->sstrings, sp, l); /* append to pool buffer */
790 spool->sstrings += l;
792 idmap[i] = id; /* repo relative -> pool relative */
793 sp += l; /* next string */
797 pool_shrink_strings(pool); /* vacuum */
800 /******* Part 2: Relation IDs ***************************************/
810 pool->rels = sat_realloc2(pool->rels, pool->nrels + numrel, sizeof(Reldep));
813 hashmask = mkmask(pool->nrels + numrel);
815 POOL_DEBUG(SAT_DEBUG_STATS, "read %d rels\n", numrel);
816 POOL_DEBUG(SAT_DEBUG_STATS, "rel hash buckets: %d\n", hashmask + 1);
819 * prep hash table with already existing RelDeps
822 hashtbl = sat_calloc(hashmask + 1, sizeof(Id));
823 for (i = 1; i < pool->nrels; i++)
825 h = relhash(ran[i].name, ran[i].evr, ran[i].flags) & hashmask;
826 hh = HASHCHAIN_START;
828 h = HASHCHAIN_NEXT(h, hh, hashmask);
833 * read RelDeps from repo
836 for (i = 0; i < numrel; i++)
838 name = read_id(&data, i + numid); /* read (repo relative) Ids */
839 evr = read_id(&data, i + numid);
840 flags = read_u8(&data);
841 name = idmap[name]; /* map to (pool relative) Ids */
843 h = relhash(name, evr, flags) & hashmask;
844 hh = HASHCHAIN_START;
848 if (id == ID_NULL) /* end of hash chain */
850 if (ran[id].name == name && ran[id].evr == evr && ran[id].flags == flags)
852 h = HASHCHAIN_NEXT(h, hh, hashmask);
854 if (id == ID_NULL) /* new RelDep */
860 ran[id].flags = flags;
862 idmap[i + numid] = MAKERELDEP(id); /* fill Id map */
865 pool_shrink_rels(pool); /* vacuum */
869 /******* Part 3: Dirs ***********************************************/
872 data.dirpool.dirs = sat_malloc2(numdir, sizeof(Id));
873 data.dirpool.ndirs = numdir;
874 data.dirpool.dirs[0] = 0; /* dir 0: virtual root */
875 data.dirpool.dirs[1] = 1; /* dir 1: / */
876 for (i = 2; i < numdir; i++)
878 id = read_id(&data, i + numid);
880 data.dirpool.dirs[i] = -(id - numid);
882 data.dirpool.dirs[i] = idmap[id];
884 data.dirpool.dirs[i] = id;
888 /******* Part 4: Keys ***********************************************/
890 keys = sat_calloc(numkeys, sizeof(*keys));
891 /* keys start at 1 */
892 for (i = 1; i < numkeys; i++)
894 id = read_id(&data, numid);
898 id = str2id(pool, stringpool_id2str(spool, id), 1);
900 keys[i].type = read_id(&data, 0);
901 keys[i].size = read_id(&data, 0);
903 fprintf (stderr, "key %d %s %d %d\n", i, id2str(pool,id), keys[i].type,
906 if (solvversion >= SOLV_VERSION_5)
908 keys[i].storage = read_id(&data, 0);
911 keys[i].storage = KEY_STORAGE_DROPPED;
914 keys[i].storage = KEY_STORAGE_INCORE;
917 switch (keys[i].type)
923 case TYPE_DIRNUMNUMARRAY:
924 keys[i].storage = KEY_STORAGE_INCORE;
932 case SOLVABLE_VENDOR:
933 keys[i].storage = KEY_STORAGE_SOLVABLE;
936 keys[i].storage = KEY_STORAGE_INCORE;
941 case TYPE_REL_IDARRAY:
942 if (id >= INTERESTED_START && id <= INTERESTED_END)
943 keys[i].storage = KEY_STORAGE_SOLVABLE;
945 keys[i].storage = KEY_STORAGE_INCORE;
948 if (id == RPM_RPMDBID)
949 keys[i].storage = KEY_STORAGE_SOLVABLE;
951 keys[i].storage = KEY_STORAGE_INCORE;
958 have_xdata = parent ? 1 : 0;
959 for (i = 1; i < numkeys; i++)
960 if (keys[i].storage == KEY_STORAGE_INCORE || keys[i].storage == KEY_STORAGE_VERTICAL_OFFSET)
964 data.nkeys = numkeys;
966 /******* Part 5: Schemata ********************************************/
968 id = read_id(&data, 0);
969 schemadata = sat_calloc(id + 1, sizeof(Id));
970 schemadatap = schemadata + 1;
971 schemadataend = schemadatap + id;
972 schemata = sat_calloc(numschemata, sizeof(Id));
973 for (i = 1; i < numschemata; i++)
975 schemata[i] = schemadatap - schemadata;
976 schemadatap = read_idarray(&data, numid, 0, schemadatap, schemadataend, 0);
978 Id *sp = schemadata + schemata[i];
979 fprintf (stderr, "schema %d:", i);
981 fprintf (stderr, " %d", *sp);
982 fprintf (stderr, "\n");
985 data.schemata = schemata;
986 data.nschemata = numschemata;
987 data.schemadata = schemadata;
988 data.schemadatalen = schemadataend - data.schemadata;
991 /******* Part 6: Info ***********************************************/
992 oldnrepodata = repo->nrepodata;
993 for (i = 0; i < numinfo; i++)
995 /* for now we're just interested in data that starts with
996 * the repodata_external id
999 id = read_id(&data, numschemata);
1000 if (solvversion < SOLV_VERSION_5)
1002 keyp = schemadata + schemata[id];
1004 if (keys[key].name == REPODATA_EXTERNAL && keys[key].type == TYPE_VOID)
1006 /* external data for some ids */
1007 parse_repodata(&data, keyp, keys, idmap, numid, numrel, repo);
1010 skip_schema(&data, keyp, keys, numid, numrel);
1014 /******* Part 7: packed sizes (optional) ****************************/
1016 if ((solvflags & SOLV_FLAG_PACKEDSIZES) != 0)
1018 exists = sat_malloc (numsolv);
1019 for (i = 0; i < numsolv; i++)
1020 exists[i] = read_id(&data, 0) != 0;
1024 /******* Part 8: item data *******************************************/
1026 /* calculate idarray size */
1028 for (i = 1; i < numkeys; i++)
1031 if ((keys[i].type == TYPE_IDARRAY || keys[i].type == TYPE_REL_IDARRAY)
1032 && id >= INTERESTED_START && id <= INTERESTED_END)
1033 size_idarray += keys[i].size;
1036 /* allocate needed space in repo */
1039 repo_reserve_ids(repo, 0, size_idarray);
1040 idarraydatap = repo->idarraydata + repo->idarraysize;
1041 repo->idarraysize += size_idarray;
1042 idarraydataend = idarraydatap + size_idarray;
1051 /* read solvables */
1054 data.start = parent->start;
1055 data.end = parent->end;
1056 s = pool_id2solvable(pool, data.start);
1060 s = pool_id2solvable(pool, repo_add_solvable_block(repo, numsolv));
1061 /* store start and end of our id block */
1062 data.start = s - pool->solvables;
1063 data.end = data.start + numsolv;
1064 /* In case we have subfiles, make them refer to our part of the
1066 for (i = oldnrepodata; i < repo->nrepodata; i++)
1068 repo->repodata[i].start = data.start;
1069 repo->repodata[i].end = data.end;
1076 data.incoreoffset = sat_calloc(numsolv, sizeof(Id));
1077 for (i = 0; i < numsolv; i++, s++)
1082 if (exists && !exists[i])
1084 id = read_id(&data, numschemata);
1085 if (solvversion < SOLV_VERSION_5)
1089 data.incoreoffset[i] = data.incoredatalen;
1090 incore_add_id(&data, id);
1092 keyp = schemadata + schemata[id];
1093 while ((key = *keyp++) != 0)
1095 id = keys[key].name;
1097 fprintf(stderr, "solv %d name %d type %d class %d\n", i, id, keys[key].type, keys[key].storage);
1099 if (keys[key].storage == KEY_STORAGE_VERTICAL_OFFSET)
1101 /* copy offset/length into incore */
1102 did = read_id(&data, 0);
1103 incore_add_id(&data, did);
1104 did = read_id(&data, 0);
1105 incore_add_id(&data, did);
1108 switch (keys[key].type)
1114 did = read_id(&data, numid + numrel);
1117 if (id == SOLVABLE_NAME)
1119 else if (id == SOLVABLE_ARCH)
1121 else if (id == SOLVABLE_EVR)
1123 else if (id == SOLVABLE_VENDOR)
1125 else if (keys[key].storage == KEY_STORAGE_INCORE)
1126 incore_add_id(&data, did);
1128 POOL_DEBUG(SAT_DEBUG_STATS, "%s -> %s\n", id2str(pool, id), id2str(pool, did));
1132 did = read_id(&data, 0);
1133 if (keys[key].storage == KEY_STORAGE_INCORE)
1134 incore_add_id(&data, did);
1136 POOL_DEBUG(SAT_DEBUG_STATS, "%s -> %d\n", id2str(pool, id), did);
1140 h = read_u32(&data);
1142 POOL_DEBUG(SAT_DEBUG_STATS, "%s -> %u\n", id2str(pool, id), h);
1144 if (id == RPM_RPMDBID)
1147 repo->rpmdbid = sat_calloc(numsolv, sizeof(Id));
1148 repo->rpmdbid[i] = h;
1150 else if (keys[key].storage == KEY_STORAGE_INCORE)
1151 incore_add_u32(&data, h);
1154 if (keys[key].storage == KEY_STORAGE_INCORE)
1156 while ((h = read_u8(&data)) != 0)
1157 incore_add_u8(&data, h);
1158 incore_add_u8(&data, 0);
1162 while (read_u8(&data) != 0)
1167 case TYPE_REL_IDARRAY:
1168 if (id < INTERESTED_START || id > INTERESTED_END)
1170 if (keys[key].storage == KEY_STORAGE_INCORE)
1174 Id old = 0, rel = keys[key].type == TYPE_REL_IDARRAY ? SOLVABLE_PREREQMARKER : 0;
1177 did = read_id(&data, 0);
1179 did = (did & 0x3f) | ((did >> 1) & ~0x3f);
1193 if (did >= numid + numrel)
1196 did = ((did & ~0x3f) << 1) | h;
1197 incore_add_id(&data, did);
1203 while (((h = read_u8(&data)) & 0xc0) != 0)
1204 incore_add_u8(&data, h);
1210 while ((read_u8(&data) & 0xc0) != 0)
1216 ido = idarraydatap - repo->idarraydata;
1217 idarraydatap = read_idarray(&data, numid + numrel, idmap, idarraydatap, idarraydataend, keys[key].type == TYPE_REL_IDARRAY);
1218 if (id == SOLVABLE_PROVIDES)
1220 else if (id == SOLVABLE_OBSOLETES)
1222 else if (id == SOLVABLE_CONFLICTS)
1224 else if (id == SOLVABLE_REQUIRES)
1226 else if (id == SOLVABLE_RECOMMENDS)
1228 else if (id == SOLVABLE_SUPPLEMENTS)
1229 s->supplements = ido;
1230 else if (id == SOLVABLE_SUGGESTS)
1232 else if (id == SOLVABLE_ENHANCES)
1234 else if (id == SOLVABLE_FRESHENS)
1237 POOL_DEBUG(SAT_DEBUG_STATS, "%s ->\n", id2str(pool, id));
1238 for (; repo->idarraydata[ido]; ido++)
1239 POOL_DEBUG(SAT_DEBUG_STATS," %s\n", dep2str(pool, repo->idarraydata[ido]));
1242 case TYPE_DIRNUMNUMARRAY:
1246 did = read_id(&data, numdir);
1247 num = read_id(&data, 0);
1248 num2 = read_id(&data, 0);
1249 if (keys[key].storage == KEY_STORAGE_INCORE)
1252 POOL_DEBUG(SAT_DEBUG_STATS, "%s -> %d %d %d\n", id2str(pool, id), did, num, num2);
1254 incore_add_id(&data, did);
1255 incore_add_id(&data, num);
1256 incore_add_id(&data, num2);
1264 skip_item(&data, keys[key].type, numid, numrel);
1271 /* free solvables */
1272 repo_free_solvable_block(repo, data.start, data.end - data.start, 1);
1274 repo->idarraysize -= size_idarray;
1275 /* free incore data */
1276 data.incoredata = sat_free(data.incoredata);
1277 data.incoredatalen = data.incoredatafree = 0;
1280 if (data.incoredatafree)
1282 /* shrink excess size */
1283 data.incoredata = sat_realloc(data.incoredata, data.incoredatalen);
1284 data.incoredatafree = 0;
1287 for (i = 1; i < numkeys; i++)
1288 if (keys[i].storage == KEY_STORAGE_VERTICAL_OFFSET)
1290 if (i < numkeys && !data.error)
1293 unsigned int pagesize;
1295 /* we have vertical data, make it available */
1296 data.verticaloffset = sat_calloc(numkeys, sizeof(Id));
1297 for (i = 1; i < numkeys; i++)
1298 if (keys[i].storage == KEY_STORAGE_VERTICAL_OFFSET)
1300 data.verticaloffset[i] = fileoffset;
1301 fileoffset += keys[i].size;
1303 data.lastverticaloffset = fileoffset;
1304 pagesize = read_u32(&data);
1305 repodata_read_or_setup_pages(&data, pagesize, fileoffset);
1309 /* no longer needed */
1316 sat_free(parent->schemata);
1317 sat_free(parent->schemadata);
1318 sat_free(parent->keys);
1321 else if (data.incoredatalen || data.fp)
1323 /* we got some data, make it available */
1324 repo->repodata = sat_realloc2(repo->repodata, repo->nrepodata + 1, sizeof(data));
1325 repo->repodata[repo->nrepodata++] = data;
1330 sat_free(data.dirpool.dirs);
1331 sat_free(data.incoreoffset);
1333 sat_free(schemadata);
1344 repo_add_solv(Repo *repo, FILE *fp)
1346 return repo_add_solv_parent(repo, fp, 0);
1350 repodata_load_solv(Repodata *data)
1353 Pool *pool = data->repo->pool;
1354 if (!pool->loadcallback)
1356 data->state = REPODATA_ERROR;
1359 fp = pool->loadcallback(pool, data, pool->loadcallbackdata);
1363 data->state = REPODATA_ERROR;
1366 if (repo_add_solv_parent(data->repo, fp, data))
1367 data->state = REPODATA_ERROR;
1369 data->state = REPODATA_AVAILABLE;