- incompatible ABI change: switch num over to unsigned long long and store sizes...
[platform/upstream/libsolv.git] / src / repo_solv.c
1 /*
2  * Copyright (c) 2007, Novell Inc.
3  *
4  * This program is licensed under the BSD license, read LICENSE.BSD
5  * for further information
6  */
7
8 /*
9  * repo_solv.c
10  * 
11  * Add a repo in solv format
12  * 
13  */
14
15
16
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <unistd.h>
20 #include <string.h>
21
22 #include "repo_solv.h"
23 #include "util.h"
24
25 #include "repopack.h"
26 #include "repopage.h"
27
28 #include "poolid_private.h"     /* WHATPROVIDES_BLOCK */
29
30 #define INTERESTED_START        SOLVABLE_NAME
31 #define INTERESTED_END          SOLVABLE_ENHANCES
32
33 #define SOLV_ERROR_NOT_SOLV     1
34 #define SOLV_ERROR_UNSUPPORTED  2
35 #define SOLV_ERROR_EOF          3
36 #define SOLV_ERROR_ID_RANGE     4
37 #define SOLV_ERROR_OVERFLOW     5
38 #define SOLV_ERROR_CORRUPT      6
39
40
41
42 /*******************************************************************************
43  * functions to extract data from a file handle
44  */
45
46 /*
47  * read u32
48  */
49
50 static unsigned int
51 read_u32(Repodata *data)
52 {
53   int c, i;
54   unsigned int x = 0;
55
56   if (data->error)
57     return 0;
58   for (i = 0; i < 4; i++)
59     {
60       c = getc(data->fp);
61       if (c == EOF)
62         {
63           pool_debug(data->repo->pool, SOLV_ERROR, "unexpected EOF\n");
64           data->error = SOLV_ERROR_EOF;
65           return 0;
66         }
67       x = (x << 8) | c;
68     }
69   return x;
70 }
71
72
73 /*
74  * read u8
75  */
76
77 static unsigned int
78 read_u8(Repodata *data)
79 {
80   int c;
81
82   if (data->error)
83     return 0;
84   c = getc(data->fp);
85   if (c == EOF)
86     {
87       pool_debug(data->repo->pool, SOLV_ERROR, "unexpected EOF\n");
88       data->error = SOLV_ERROR_EOF;
89       return 0;
90     }
91   return c;
92 }
93
94
95 /*
96  * read Id
97  */
98
99 static Id
100 read_id(Repodata *data, Id max)
101 {
102   unsigned int x = 0;
103   int c, i;
104
105   if (data->error)
106     return 0;
107   for (i = 0; i < 5; i++)
108     {
109       c = getc(data->fp);
110       if (c == EOF)
111         {
112           pool_debug(data->repo->pool, SOLV_ERROR, "unexpected EOF\n");
113           data->error = SOLV_ERROR_EOF;
114           return 0;
115         }
116       if (!(c & 128))
117         {
118           x = (x << 7) | c;
119           if (max && x >= max)
120             {
121               pool_debug(data->repo->pool, SOLV_ERROR, "read_id: id too large (%u/%u)\n", x, max);
122               data->error = SOLV_ERROR_ID_RANGE;
123               return 0;
124             }
125           return x;
126         }
127       x = (x << 7) ^ c ^ 128;
128     }
129   pool_debug(data->repo->pool, SOLV_ERROR, "read_id: id too long\n");
130   data->error = SOLV_ERROR_CORRUPT;
131   return 0;
132 }
133
134
135 static Id *
136 read_idarray(Repodata *data, Id max, Id *map, Id *store, Id *end)
137 {
138   unsigned int x = 0;
139   int c;
140
141   if (data->error)
142     return 0;
143   for (;;)
144     {
145       c = getc(data->fp);
146       if (c == EOF)
147         {
148           pool_debug(data->repo->pool, SOLV_ERROR, "unexpected EOF\n");
149           data->error = SOLV_ERROR_EOF;
150           return 0;
151         }
152       if ((c & 128) != 0)
153         {
154           x = (x << 7) ^ c ^ 128;
155           continue;
156         }
157       x = (x << 6) | (c & 63);
158       if (max && x >= max)
159         {
160           pool_debug(data->repo->pool, SOLV_ERROR, "read_idarray: id too large (%u/%u)\n", x, max);
161           data->error = SOLV_ERROR_ID_RANGE;
162           return 0;
163         }
164       if (map)
165         x = map[x];
166       if (store == end)
167         {
168           pool_debug(data->repo->pool, SOLV_ERROR, "read_idarray: array overflow\n");
169           return 0;
170         }
171       *store++ = x;
172       if ((c & 64) == 0)
173         {
174           if (x == 0)   /* already have trailing zero? */
175             return store;
176           if (store == end)
177             {
178               pool_debug(data->repo->pool, SOLV_ERROR, "read_idarray: array overflow\n");
179               data->error = SOLV_ERROR_OVERFLOW;
180               return 0;
181             }
182           *store++ = 0;
183           return store;
184         }
185       x = 0;
186     }
187 }
188
189
190 /*******************************************************************************
191  * functions to extract data from memory
192  */
193
194 /*
195  * read array of Ids
196  */
197
198 static inline unsigned char *
199 data_read_id_max(unsigned char *dp, Id *ret, Id *map, int max, Repodata *data)
200 {
201   Id x;
202   dp = data_read_id(dp, &x);
203   if (x < 0 || (max && x >= max))
204     {
205       pool_debug(data->repo->pool, SOLV_ERROR, "data_read_id_max: id too large (%u/%u)\n", x, max);
206       data->error = SOLV_ERROR_ID_RANGE;
207       x = 0;
208     }
209   *ret = map ? map[x] : x;
210   return dp;
211 }
212
213 static unsigned char *
214 data_read_idarray(unsigned char *dp, Id **storep, Id *map, int max, Repodata *data)
215 {
216   Id *store = *storep;
217   unsigned int x = 0;
218   int c;
219
220   for (;;)
221     {
222       c = *dp++;
223       if ((c & 128) != 0)
224         {
225           x = (x << 7) ^ c ^ 128;
226           continue;
227         }
228       x = (x << 6) | (c & 63);
229       if (max && x >= max)
230         {
231           pool_debug(data->repo->pool, SOLV_ERROR, "data_read_idarray: id too large (%u/%u)\n", x, max);
232           data->error = SOLV_ERROR_ID_RANGE;
233           break;
234         }
235       *store++ = x;
236       if ((c & 64) == 0)
237         break;
238       x = 0;
239     }
240   *store++ = 0;
241   *storep = store;
242   return dp;
243 }
244
245 static unsigned char *
246 data_read_rel_idarray(unsigned char *dp, Id **storep, Id *map, int max, Repodata *data, Id marker)
247 {
248   Id *store = *storep;
249   Id old = 0;
250   unsigned int x = 0;
251   int c;
252
253   for (;;)
254     {
255       c = *dp++;
256       if ((c & 128) != 0)
257         {
258           x = (x << 7) ^ c ^ 128;
259           continue;
260         }
261       x = (x << 6) | (c & 63);
262       if (x == 0)
263         {
264           if (!(c & 64))
265             break;
266           if (marker)
267             *store++ = marker;
268           old = 0;
269           continue;
270         }
271       x = old + (x - 1);
272       old = x;
273       if (max && x >= max)
274         {
275           pool_debug(data->repo->pool, SOLV_ERROR, "data_read_rel_idarray: id too large (%u/%u)\n", x, max);
276           data->error = SOLV_ERROR_ID_RANGE;
277           break;
278         }
279       *store++ = map ? map[x] : x;
280       if (!(c & 64))
281         break;
282       x = 0;
283     }
284   *store++ = 0;
285   *storep = store;
286   return dp;
287 }
288
289
290
291
292 /*******************************************************************************
293  * functions to add data to our incore memory space
294  */
295
296 #define INCORE_ADD_CHUNK 8192
297 #define DATA_READ_CHUNK 8192
298
299 static void
300 incore_add_id(Repodata *data, Id sx)
301 {
302   unsigned int x = (unsigned int)sx;
303   unsigned char *dp;
304   /* make sure we have at least 5 bytes free */
305   if (data->incoredatafree < 5)
306     {
307       data->incoredata = solv_realloc(data->incoredata, data->incoredatalen + INCORE_ADD_CHUNK);
308       data->incoredatafree = INCORE_ADD_CHUNK;
309     }
310   dp = data->incoredata + data->incoredatalen;
311   if (x >= (1 << 14))
312     {
313       if (x >= (1 << 28))
314         *dp++ = (x >> 28) | 128;
315       if (x >= (1 << 21))
316         *dp++ = (x >> 21) | 128;
317       *dp++ = (x >> 14) | 128;
318     }
319   if (x >= (1 << 7))
320     *dp++ = (x >> 7) | 128;
321   *dp++ = x & 127;
322   data->incoredatafree -= dp - (data->incoredata + data->incoredatalen);
323   data->incoredatalen = dp - data->incoredata;
324 }
325
326 static void
327 incore_add_sizek(Repodata *data, unsigned int sx)
328 {
329   if (sx < (1 << 22))
330     incore_add_id(data, (Id)(sx << 10));
331   else
332     {
333       if ((sx >> 25) != 0)
334         {
335           incore_add_id(data, (Id)(sx >> 25));
336           data->incoredata[data->incoredatalen - 1] |= 128;
337         }
338       incore_add_id(data, (Id)((sx << 10) | 0x80000000));
339       data->incoredata[data->incoredatalen - 5] = (sx >> 18) | 128;
340     }
341 }
342
343 static void
344 incore_add_ideof(Repodata *data, Id sx, int eof)
345 {
346   unsigned int x = (unsigned int)sx;
347   unsigned char *dp;
348   /* make sure we have at least 5 bytes free */
349   if (data->incoredatafree < 5)
350     {
351       data->incoredata = solv_realloc(data->incoredata, data->incoredatalen + INCORE_ADD_CHUNK);
352       data->incoredatafree = INCORE_ADD_CHUNK;
353     }
354   dp = data->incoredata + data->incoredatalen;
355   if (x >= (1 << 13))
356     {
357       if (x >= (1 << 27))
358         *dp++ = (x >> 27) | 128;
359       if (x >= (1 << 20))
360         *dp++ = (x >> 20) | 128;
361       *dp++ = (x >> 13) | 128;
362     }
363   if (x >= (1 << 6))
364     *dp++ = (x >> 6) | 128;
365   *dp++ = eof ? (x & 63) : (x & 63) | 64;
366   data->incoredatafree -= dp - (data->incoredata + data->incoredatalen);
367   data->incoredatalen = dp - data->incoredata;
368 }
369
370 static void
371 incore_add_blob(Repodata *data, unsigned char *buf, int len)
372 {
373   if (data->incoredatafree < len)
374     {
375       data->incoredata = solv_realloc(data->incoredata, data->incoredatalen + INCORE_ADD_CHUNK + len);
376       data->incoredatafree = INCORE_ADD_CHUNK + len;
377     }
378   memcpy(data->incoredata + data->incoredatalen, buf, len);
379   data->incoredatafree -= len;
380   data->incoredatalen += len;
381 }
382
383 static void
384 incore_map_idarray(Repodata *data, unsigned char *dp, Id *map, Id max)
385 {
386   /* We have to map the IDs, which might also change
387      the necessary number of bytes, so we can't just copy
388      over the blob and adjust it.  */
389   for (;;)
390     {
391       Id id;
392       int eof;
393       dp = data_read_ideof(dp, &id, &eof);
394       if (id < 0 || (max && id >= max))
395         {
396           pool_debug(data->repo->pool, SOLV_ERROR, "incore_map_idarray: id too large (%u/%u)\n", id, max);
397           data->error = SOLV_ERROR_ID_RANGE;
398           break;
399         }
400       id = map[id];
401       incore_add_ideof(data, id, eof);
402       if (eof)
403         break;
404     }
405 }
406
407 #if 0
408 static void
409 incore_add_u32(Repodata *data, unsigned int x)
410 {
411   unsigned char *dp;
412   /* make sure we have at least 4 bytes free */
413   if (data->incoredatafree < 4)
414     {
415       data->incoredata = solv_realloc(data->incoredata, data->incoredatalen + INCORE_ADD_CHUNK);
416       data->incoredatafree = INCORE_ADD_CHUNK;
417     }
418   dp = data->incoredata + data->incoredatalen;
419   *dp++ = x >> 24;
420   *dp++ = x >> 16;
421   *dp++ = x >> 8;
422   *dp++ = x;
423   data->incoredatafree -= 4;
424   data->incoredatalen += 4;
425 }
426
427 static void
428 incore_add_u8(Repodata *data, unsigned int x)
429 {
430   unsigned char *dp;
431   /* make sure we have at least 1 byte free */
432   if (data->incoredatafree < 1)
433     {
434       data->incoredata = solv_realloc(data->incoredata, data->incoredatalen + 1024);
435       data->incoredatafree = 1024;
436     }
437   dp = data->incoredata + data->incoredatalen;
438   *dp++ = x;
439   data->incoredatafree--;
440   data->incoredatalen++;
441 }
442 #endif
443
444
445 /*******************************************************************************
446  * our main function
447  */
448
449 /*
450  * read repo from .solv file and add it to pool
451  */
452
453 int
454 repo_add_solv(Repo *repo, FILE *fp, int flags)
455 {
456   Pool *pool = repo->pool;
457   int i, l;
458   unsigned int numid, numrel, numdir, numsolv;
459   unsigned int numkeys, numschemata;
460
461   Offset sizeid;
462   Offset *str;                         /* map Id -> Offset into string space */
463   char *strsp;                         /* repo string space */
464   char *sp;                            /* pointer into string space */
465   Id *idmap;                           /* map of repo Ids to pool Ids */
466   Id id, type;
467   unsigned int hashmask, h;
468   int hh;
469   Id *hashtbl;
470   Id name, evr, did;
471   int relflags;
472   Reldep *ran;
473   unsigned int size_idarray;
474   Id *idarraydatap, *idarraydataend;
475   Offset ido;
476   Solvable *s;
477   unsigned int solvflags;
478   unsigned int solvversion;
479   Repokey *keys;
480   Id *schemadata, *schemadatap, *schemadataend;
481   Id *schemata, key, *keyp;
482   int nentries;
483   int have_xdata;
484   int maxsize, allsize;
485   unsigned char *buf, *bufend, *dp, *dps;
486   Id stack[3 * 5];
487   int keydepth;
488   int needchunk;        /* need a new chunk of data */
489   unsigned int now;
490   int oldnstrings = pool->ss.nstrings;
491   int oldnrels = pool->nrels;
492
493   struct _Stringpool *spool;
494
495   Repodata *parent = 0;
496   Repodata data;
497
498   now = solv_timems(0);
499
500   if ((flags & REPO_USE_LOADING) != 0)
501     {
502       /* this is a stub replace operation */
503       flags |= REPO_EXTEND_SOLVABLES;
504       /* use REPO_REUSE_REPODATA hack so that the old repodata is kept */
505       parent = repo_add_repodata(repo, flags | REPO_REUSE_REPODATA);
506     }
507     
508   memset(&data, 0, sizeof(data));
509   data.repo = repo;
510   data.fp = fp;
511   repopagestore_init(&data.store);
512
513   if (read_u32(&data) != ('S' << 24 | 'O' << 16 | 'L' << 8 | 'V'))
514     {
515       pool_debug(pool, SOLV_ERROR, "not a SOLV file\n");
516       return SOLV_ERROR_NOT_SOLV;
517     }
518   solvversion = read_u32(&data);
519   switch (solvversion)
520     {
521       case SOLV_VERSION_8:
522         break;
523       default:
524         pool_debug(pool, SOLV_ERROR, "unsupported SOLV version\n");
525         return SOLV_ERROR_UNSUPPORTED;
526     }
527
528   numid = read_u32(&data);
529   numrel = read_u32(&data);
530   numdir = read_u32(&data);
531   numsolv = read_u32(&data);
532   numkeys = read_u32(&data);
533   numschemata = read_u32(&data);
534   solvflags = read_u32(&data);
535
536   if (numdir && numdir < 2)
537     {
538       pool_debug(pool, SOLV_ERROR, "bad number of dirs\n");
539       return SOLV_ERROR_CORRUPT;
540     }
541
542   if (numrel && (flags & REPO_LOCALPOOL) != 0)
543     {
544       pool_debug(pool, SOLV_ERROR, "relations are forbidden in a local pool\n");
545       return SOLV_ERROR_CORRUPT;
546     }
547   if (parent && numsolv)
548     {
549       /* make sure that we exactly replace the stub repodata */
550       if (parent->end - parent->start != numsolv)
551         {
552           pool_debug(pool, SOLV_ERROR, "sub-repository solvable number does not match main repository (%d - %d)\n", parent->end - parent->start, numsolv);
553           return SOLV_ERROR_CORRUPT;
554         }
555       for (i = 0; i < numsolv; i++)
556         if (pool->solvables[parent->start + i].repo != repo)
557           {
558             pool_debug(pool, SOLV_ERROR, "main repository contains holes\n");
559             return SOLV_ERROR_CORRUPT;
560           }
561     }
562
563   /*******  Part 1: string IDs  *****************************************/
564
565   sizeid = read_u32(&data);            /* size of string+Id space */
566
567   /*
568    * read strings and Ids
569    * 
570    */
571
572   
573   /*
574    * alloc buffers
575    */
576
577   if (!(flags & REPO_LOCALPOOL))
578     spool = &pool->ss;
579   else
580     {
581       data.localpool = 1;
582       spool = &data.spool;
583       spool->stringspace = solv_malloc(7);
584       strcpy(spool->stringspace, "<NULL>");
585       spool->sstrings = 7;
586       spool->nstrings = 0;
587     }
588
589   /* alloc string buffer */
590   spool->stringspace = solv_realloc(spool->stringspace, spool->sstrings + sizeid + 1);
591   /* alloc string offsets (Id -> Offset into string space) */
592   spool->strings = solv_realloc2(spool->strings, spool->nstrings + numid, sizeof(Offset));
593
594   strsp = spool->stringspace;
595   str = spool->strings;                /* array of offsets into strsp, indexed by Id */
596
597   /* point to _BEHIND_ already allocated string/Id space */
598   strsp += spool->sstrings;
599
600
601   /*
602    * read new repo at end of pool
603    */
604   
605   if ((solvflags & SOLV_FLAG_PREFIX_POOL) == 0)
606     {
607       if (sizeid && fread(strsp, sizeid, 1, fp) != 1)
608         {
609           pool_debug(pool, SOLV_ERROR, "read error while reading strings\n");
610           return SOLV_ERROR_EOF;
611         }
612     }
613   else
614     {
615       unsigned int pfsize = read_u32(&data);
616       char *prefix = solv_malloc(pfsize);
617       char *pp = prefix;
618       char *old_str = 0;
619       char *dest = strsp;
620       int freesp = sizeid;
621
622       if (pfsize && fread(prefix, pfsize, 1, fp) != 1)
623         {
624           pool_debug(pool, SOLV_ERROR, "read error while reading strings\n");
625           solv_free(prefix);
626           return SOLV_ERROR_EOF;
627         }
628       for (i = 1; i < numid; i++)
629         {
630           int same = (unsigned char)*pp++;
631           size_t len = strlen(pp) + 1;
632           freesp -= same + len;
633           if (freesp < 0)
634             {
635               pool_debug(pool, SOLV_ERROR, "overflow while expanding strings\n");
636               solv_free(prefix);
637               return SOLV_ERROR_OVERFLOW;
638             }
639           if (same)
640             memcpy(dest, old_str, same);
641           memcpy(dest + same, pp, len);
642           pp += len;
643           old_str = dest;
644           dest += same + len;
645         }
646       solv_free(prefix);
647       if (freesp != 0)
648         {
649           pool_debug(pool, SOLV_ERROR, "expanding strings size mismatch\n");
650           return SOLV_ERROR_CORRUPT;
651         }
652     }
653   strsp[sizeid] = 0;                   /* make string space \0 terminated */
654   sp = strsp;
655
656   if ((flags & REPO_LOCALPOOL) != 0)
657     {
658       /* no shared pool, thus no idmap and no unification */
659       idmap = 0;
660       spool->nstrings = numid;
661       str[0] = 0;
662       if (*sp)
663         {
664           /* we need the '' for directories */
665           pool_debug(pool, SOLV_ERROR, "store strings don't start with ''\n");
666           return SOLV_ERROR_CORRUPT;
667         }
668       for (i = 1; i < spool->nstrings; i++)
669         {
670           if (sp >= strsp + sizeid)
671             {
672               pool_debug(pool, SOLV_ERROR, "not enough strings\n");
673               return SOLV_ERROR_OVERFLOW;
674             }
675           str[i] = sp - spool->stringspace;
676           sp += strlen(sp) + 1;
677         }
678       spool->sstrings = sp - spool->stringspace;
679     }
680   else
681     {
682       /* alloc id map for name and rel Ids. this maps ids in the solv files
683        * to the ids in our pool */
684       idmap = solv_calloc(numid + numrel, sizeof(Id));
685
686       /* grow hash if needed, otherwise reuse */
687       hashmask = mkmask(spool->nstrings + numid);
688 #if 0
689       POOL_DEBUG(SOLV_DEBUG_STATS, "read %d strings\n", numid);
690       POOL_DEBUG(SOLV_DEBUG_STATS, "string hash buckets: %d, old %d\n", hashmask + 1, spool->stringhashmask + 1);
691 #endif
692       if (hashmask > spool->stringhashmask)
693         {
694           spool->stringhashtbl = solv_free(spool->stringhashtbl);
695           spool->stringhashmask = hashmask;
696           spool->stringhashtbl = hashtbl = solv_calloc(hashmask + 1, sizeof(Id));
697           for (i = 1; i < spool->nstrings; i++)
698             {
699               h = strhash(spool->stringspace + spool->strings[i]) & hashmask;
700               hh = HASHCHAIN_START;
701               while (hashtbl[h])
702                 h = HASHCHAIN_NEXT(h, hh, hashmask);
703               hashtbl[h] = i;
704             }
705         }
706       else
707         {
708           hashtbl = spool->stringhashtbl;
709           hashmask = spool->stringhashmask;
710         }
711
712       /*
713        * run over strings and merge with pool.
714        * also populate id map (maps solv Id -> pool Id)
715        */
716       for (i = 1; i < numid; i++)
717         {
718           if (sp >= strsp + sizeid)
719             {
720               solv_free(hashtbl);
721               solv_free(idmap);
722               pool_debug(pool, SOLV_ERROR, "not enough strings %d %d\n", i, numid);
723               return SOLV_ERROR_OVERFLOW;
724             }
725           if (!*sp)                            /* empty string */
726             {
727               idmap[i] = ID_EMPTY;
728               sp++;
729               continue;
730             }
731
732           /* find hash slot */
733           h = strhash(sp) & hashmask;
734           hh = HASHCHAIN_START;
735           for (;;)
736             {
737               id = hashtbl[h];
738               if (!id)
739                 break;
740               if (!strcmp(spool->stringspace + spool->strings[id], sp))
741                 break;          /* already in pool */
742               h = HASHCHAIN_NEXT(h, hh, hashmask);
743             }
744
745           /* length == offset to next string */
746           l = strlen(sp) + 1;
747           if (!id)             /* end of hash chain -> new string */
748             {
749               id = spool->nstrings++;
750               hashtbl[h] = id;
751               str[id] = spool->sstrings;        /* save offset */
752               if (sp != spool->stringspace + spool->sstrings)
753                 memmove(spool->stringspace + spool->sstrings, sp, l);
754               spool->sstrings += l;
755             }
756           idmap[i] = id;       /* repo relative -> pool relative */
757           sp += l;             /* next string */
758         }
759       if (hashmask > mkmask(spool->nstrings + 8192))
760         {
761           spool->stringhashtbl = solv_free(spool->stringhashtbl);
762           spool->stringhashmask = 0;
763         }
764     }
765   pool_shrink_strings(pool);           /* vacuum */
766
767   
768   /*******  Part 2: Relation IDs  ***************************************/
769
770   /*
771    * read RelDeps
772    * 
773    */
774   
775   if (numrel)
776     {
777       /* extend rels */
778       pool->rels = solv_realloc2(pool->rels, pool->nrels + numrel, sizeof(Reldep));
779       ran = pool->rels;
780
781       /* grow hash if needed, otherwise reuse */
782       hashmask = mkmask(pool->nrels + numrel);
783 #if 0
784       POOL_DEBUG(SOLV_DEBUG_STATS, "read %d rels\n", numrel);
785       POOL_DEBUG(SOLV_DEBUG_STATS, "rel hash buckets: %d, old %d\n", hashmask + 1, pool->relhashmask + 1);
786 #endif
787       if (hashmask > pool->relhashmask)
788         {
789           pool->relhashtbl = solv_free(pool->relhashtbl);
790           pool->relhashmask = hashmask;
791           pool->relhashtbl = hashtbl = solv_calloc(hashmask + 1, sizeof(Id));
792           for (i = 1; i < pool->nrels; i++)
793             {
794               h = relhash(ran[i].name, ran[i].evr, ran[i].flags) & hashmask;
795               hh = HASHCHAIN_START;
796               while (hashtbl[h])
797                 h = HASHCHAIN_NEXT(h, hh, hashmask);
798               hashtbl[h] = i;
799             }
800         }
801       else
802         {
803           hashtbl = pool->relhashtbl;
804           hashmask = pool->relhashmask;
805         }
806
807       /*
808        * read RelDeps from repo
809        */
810       for (i = 0; i < numrel; i++)
811         {
812           name = read_id(&data, i + numid);     /* read (repo relative) Ids */
813           evr = read_id(&data, i + numid);
814           relflags = read_u8(&data);
815           name = idmap[name];           /* map to (pool relative) Ids */
816           evr = idmap[evr];
817           h = relhash(name, evr, relflags) & hashmask;
818           hh = HASHCHAIN_START;
819           for (;;)
820             {
821               id = hashtbl[h];
822               if (!id)          /* end of hash chain reached */
823                 break;
824               if (ran[id].name == name && ran[id].evr == evr && ran[id].flags == relflags)
825                 break;
826               h = HASHCHAIN_NEXT(h, hh, hashmask);
827             }
828           if (!id)              /* new RelDep */
829             {
830               id = pool->nrels++;
831               hashtbl[h] = id;
832               ran[id].name = name;
833               ran[id].evr = evr;
834               ran[id].flags = relflags;
835             }
836           idmap[i + numid] = MAKERELDEP(id);   /* fill Id map */
837         }
838       if (hashmask > mkmask(pool->nrels + 4096))
839         {
840           pool->relhashtbl = solv_free(pool->relhashtbl);
841           pool->relhashmask = 0;
842         }
843       pool_shrink_rels(pool);           /* vacuum */
844     }
845
846   /* if we added ids/rels, make room in our whatprovide arrays */
847   if (!(flags & REPO_LOCALPOOL))
848     {
849       if (pool->whatprovides && oldnstrings != pool->ss.nstrings)
850         {
851           int newlen = (pool->ss.nstrings + WHATPROVIDES_BLOCK) & ~WHATPROVIDES_BLOCK;
852           pool->whatprovides = solv_realloc2(pool->whatprovides, newlen, sizeof(Offset));
853           memset(pool->whatprovides + oldnstrings, 0, (newlen - oldnstrings) * sizeof(Offset));
854         }
855       if (pool->whatprovides_rel && oldnrels != pool->nrels)
856         {
857           int newlen = (pool->nrels + WHATPROVIDES_BLOCK) & ~WHATPROVIDES_BLOCK;
858           pool->whatprovides_rel = solv_realloc2(pool->whatprovides_rel, newlen, sizeof(Offset));
859           memset(pool->whatprovides_rel + oldnrels, 0, (newlen - oldnrels) * sizeof(Offset));
860         }
861     }
862
863   /*******  Part 3: Dirs  ***********************************************/
864   if (numdir)
865     {
866       data.dirpool.dirs = solv_malloc2(numdir, sizeof(Id));
867       data.dirpool.ndirs = numdir;
868       data.dirpool.dirs[0] = 0;         /* dir 0: virtual root */
869       data.dirpool.dirs[1] = 1;         /* dir 1: / */
870       for (i = 2; i < numdir; i++)
871         {
872           id = read_id(&data, i + numid);
873           if (id >= numid)
874             data.dirpool.dirs[i] = -(id - numid);
875           else if (idmap)
876             data.dirpool.dirs[i] = idmap[id];
877           else
878             data.dirpool.dirs[i] = id;
879         }
880     }
881
882   /*******  Part 4: Keys  ***********************************************/
883
884   keys = solv_calloc(numkeys, sizeof(*keys));
885   /* keys start at 1 */
886   for (i = 1; i < numkeys; i++)
887     {
888       id = read_id(&data, numid);
889       if (idmap)
890         id = idmap[id];
891       else if ((flags & REPO_LOCALPOOL) != 0)
892         id = pool_str2id(pool, stringpool_id2str(spool, id), 1);
893       type = read_id(&data, numid);
894       if (idmap)
895         type = idmap[type];
896       else if ((flags & REPO_LOCALPOOL) != 0)
897         type = pool_str2id(pool, stringpool_id2str(spool, type), 1);
898       if (type < REPOKEY_TYPE_VOID || type > REPOKEY_TYPE_FLEXARRAY)
899         {
900           pool_debug(pool, SOLV_ERROR, "unsupported data type '%s'\n", pool_id2str(pool, type));
901           data.error = SOLV_ERROR_UNSUPPORTED;
902           type = REPOKEY_TYPE_VOID;
903         }
904       keys[i].name = id;
905       keys[i].type = type;
906       keys[i].size = read_id(&data, keys[i].type == REPOKEY_TYPE_CONSTANTID ? numid + numrel : 0);
907       keys[i].storage = read_id(&data, 0);
908       /* old versions used SOLVABLE for main solvable data */
909       if (keys[i].storage == KEY_STORAGE_SOLVABLE)
910         keys[i].storage = KEY_STORAGE_INCORE;
911       if (keys[i].storage != KEY_STORAGE_INCORE && keys[i].storage != KEY_STORAGE_VERTICAL_OFFSET)
912         {
913           pool_debug(pool, SOLV_ERROR, "unsupported storage type %d\n", keys[i].storage);
914           data.error = SOLV_ERROR_UNSUPPORTED;
915         }
916       if (id >= SOLVABLE_NAME && id <= RPM_RPMDBID)
917         {
918           if (keys[i].storage != KEY_STORAGE_INCORE)
919             {
920               pool_debug(pool, SOLV_ERROR, "main solvable data must use incore storage%d\n", keys[i].storage);
921               data.error = SOLV_ERROR_UNSUPPORTED;
922             }
923           keys[i].storage = KEY_STORAGE_SOLVABLE;
924         }
925       /* cannot handle rel idarrays in incore/vertical */
926       if (type == REPOKEY_TYPE_REL_IDARRAY && keys[i].storage != KEY_STORAGE_SOLVABLE)
927         {
928           pool_debug(pool, SOLV_ERROR, "type REL_IDARRAY is only supported for STORAGE_SOLVABLE\n");
929           data.error = SOLV_ERROR_UNSUPPORTED;
930         }
931       /* cannot handle mapped ids in vertical */
932       if (!(flags & REPO_LOCALPOOL) && keys[i].storage == KEY_STORAGE_VERTICAL_OFFSET && (type == REPOKEY_TYPE_ID || type == REPOKEY_TYPE_IDARRAY))
933         {
934           pool_debug(pool, SOLV_ERROR, "mapped ids are not supported for STORAGE_VERTICAL_OFFSET\n");
935           data.error = SOLV_ERROR_UNSUPPORTED;
936         }
937  
938       if (keys[i].type == REPOKEY_TYPE_CONSTANTID && idmap)
939         keys[i].size = idmap[keys[i].size];
940 #if 0
941       fprintf(stderr, "key %d %s %s %d %d\n", i, pool_id2str(pool,id), pool_id2str(pool, keys[i].type),
942                keys[i].size, keys[i].storage);
943 #endif
944     }
945
946   have_xdata = parent ? 1 : 0;
947   for (i = 1; i < numkeys; i++)
948     if (keys[i].storage == KEY_STORAGE_INCORE || keys[i].storage == KEY_STORAGE_VERTICAL_OFFSET)
949       have_xdata = 1;
950
951   data.keys = keys;
952   data.nkeys = numkeys;
953   for (i = 1; i < numkeys; i++)
954     {
955       id = keys[i].name;
956       data.keybits[(id >> 3) & (sizeof(data.keybits) - 1)] |= 1 << (id & 7);
957     }
958
959   /*******  Part 5: Schemata ********************************************/
960   
961   id = read_id(&data, 0);
962   schemadata = solv_calloc(id + 1, sizeof(Id));
963   schemadatap = schemadata + 1;
964   schemadataend = schemadatap + id;
965   schemata = solv_calloc(numschemata, sizeof(Id));
966   for (i = 1; i < numschemata; i++)
967     {
968       schemata[i] = schemadatap - schemadata;
969       schemadatap = read_idarray(&data, numid, 0, schemadatap, schemadataend);
970 #if 0
971       Id *sp = schemadata + schemata[i];
972       fprintf(stderr, "schema %d:", i);
973       for (; *sp; sp++)
974         fprintf(stderr, " %d", *sp);
975       fprintf(stderr, "\n");
976 #endif
977     }
978   data.schemata = schemata;
979   data.nschemata = numschemata;
980   data.schemadata = schemadata;
981   data.schemadatalen = schemadataend - data.schemadata;
982
983   /*******  Part 6: Data ********************************************/
984
985   idarraydatap = idarraydataend = 0;
986   size_idarray = 0;
987
988   maxsize = read_id(&data, 0);
989   allsize = read_id(&data, 0);
990   maxsize += 5; /* so we can read the next schema of an array */
991   if (maxsize > allsize)
992     maxsize = allsize;
993
994   buf = solv_calloc(maxsize + DATA_READ_CHUNK + 4, 1);  /* 4 extra bytes to detect overflows */
995   bufend = buf;
996   dp = buf;
997
998   l = maxsize;
999   if (l < DATA_READ_CHUNK)
1000     l = DATA_READ_CHUNK;
1001   if (l > allsize)
1002     l = allsize;
1003   if (!l || fread(buf, l, 1, data.fp) != 1)
1004     {
1005       pool_debug(pool, SOLV_ERROR, "unexpected EOF\n");
1006       data.error = SOLV_ERROR_EOF;
1007       id = 0;
1008     }
1009   else
1010     {
1011       bufend = buf + l;
1012       allsize -= l;
1013       dp = data_read_id_max(dp, &id, 0, numschemata, &data);
1014     }
1015
1016   incore_add_id(&data, 0);      /* XXX? */
1017   incore_add_id(&data, id);
1018   keyp = schemadata + schemata[id];
1019   data.mainschema = id;
1020   for (i = 0; keyp[i]; i++)
1021     ;
1022   if (i)
1023     data.mainschemaoffsets = solv_calloc(i, sizeof(Id));
1024
1025   nentries = 0;
1026   keydepth = 0;
1027   s = 0;
1028   needchunk = 1;
1029   for(;;)
1030     {
1031       /* make sure we have enough room */
1032       if (keydepth == 0 || needchunk)
1033         {
1034           int left = bufend - dp;
1035           /* read data chunk to dp */
1036           if (data.error)
1037             break;
1038           if (left < 0)
1039             {
1040               pool_debug(pool, SOLV_ERROR, "buffer overrun\n");
1041               data.error = SOLV_ERROR_EOF;
1042               break;
1043             }
1044           if (left < maxsize)
1045             {
1046               if (left)
1047                 memmove(buf, dp, left);
1048               l = maxsize - left;
1049               if (l < DATA_READ_CHUNK)
1050                 l = DATA_READ_CHUNK;
1051               if (l > allsize)
1052                 l = allsize;
1053               if (l && fread(buf + left, l, 1, data.fp) != 1)
1054                 {
1055                   pool_debug(pool, SOLV_ERROR, "unexpected EOF\n");
1056                   data.error = SOLV_ERROR_EOF;
1057                   break;
1058                 }
1059               allsize -= l;
1060               left += l;
1061               bufend = buf + left;
1062               if (allsize + left < maxsize)
1063                 maxsize = allsize + left;
1064               dp = buf;
1065             }
1066           needchunk = 0;
1067         }
1068
1069       key = *keyp++;
1070 #if 0
1071 printf("key %d at %d\n", key, (int)(keyp - 1 - schemadata));
1072 #endif
1073       if (!key)
1074         {
1075           if (keydepth <= 3)
1076             needchunk = 1;
1077           if (nentries)
1078             {
1079               if (s && keydepth == 3)
1080                 {
1081                   s++;  /* next solvable */
1082                   if (have_xdata)
1083                     data.incoreoffset[(s - pool->solvables) - data.start] = data.incoredatalen;
1084                 }
1085               id = stack[keydepth - 1];
1086               if (!id)
1087                 {
1088                   dp = data_read_id_max(dp, &id, 0, numschemata, &data);
1089                   incore_add_id(&data, id);
1090                 }
1091               keyp = schemadata + schemata[id];
1092               nentries--;
1093               continue;
1094             }
1095           if (!keydepth)
1096             break;
1097           --keydepth;
1098           keyp = schemadata + stack[--keydepth];
1099           nentries = stack[--keydepth];
1100 #if 0
1101 printf("pop flexarray %d %d\n", keydepth, nentries);
1102 #endif
1103           if (!keydepth && s)
1104             s = 0;      /* back from solvables */
1105           continue;
1106         }
1107
1108       if (keydepth == 0)
1109         data.mainschemaoffsets[keyp - 1 - (schemadata + schemata[data.mainschema])] = data.incoredatalen;
1110
1111 #if 0
1112 printf("=> %s %s %p\n", pool_id2str(pool, keys[key].name), pool_id2str(pool, keys[key].type), s);
1113 #endif
1114       id = keys[key].name;
1115       if (keys[key].storage == KEY_STORAGE_VERTICAL_OFFSET)
1116         {
1117           dps = dp;
1118           dp = data_skip(dp, REPOKEY_TYPE_ID);
1119           dp = data_skip(dp, REPOKEY_TYPE_ID);
1120           incore_add_blob(&data, dps, dp - dps);        /* just record offset/size */
1121           continue;
1122         }
1123       switch (keys[key].type)
1124         {
1125         case REPOKEY_TYPE_ID:
1126           dp = data_read_id_max(dp, &did, idmap, numid + numrel, &data);
1127           if (s && id == SOLVABLE_NAME)
1128             s->name = did; 
1129           else if (s && id == SOLVABLE_ARCH)
1130             s->arch = did; 
1131           else if (s && id == SOLVABLE_EVR)
1132             s->evr = did; 
1133           else if (s && id == SOLVABLE_VENDOR)
1134             s->vendor = did; 
1135           else if (keys[key].storage == KEY_STORAGE_INCORE)
1136             incore_add_id(&data, did);
1137 #if 0
1138           POOL_DEBUG(SOLV_DEBUG_STATS, "%s -> %s\n", pool_id2str(pool, id), pool_id2str(pool, did));
1139 #endif
1140           break;
1141         case REPOKEY_TYPE_IDARRAY:
1142         case REPOKEY_TYPE_REL_IDARRAY:
1143           if (!s || id < INTERESTED_START || id > INTERESTED_END)
1144             {
1145               dps = dp;
1146               dp = data_skip(dp, REPOKEY_TYPE_IDARRAY);
1147               if (keys[key].storage != KEY_STORAGE_INCORE)
1148                 break;
1149               if (idmap)
1150                 incore_map_idarray(&data, dps, idmap, numid + numrel);
1151               else
1152                 incore_add_blob(&data, dps, dp - dps);
1153               break;
1154             }
1155           ido = idarraydatap - repo->idarraydata;
1156           if (keys[key].type == REPOKEY_TYPE_IDARRAY)
1157             dp = data_read_idarray(dp, &idarraydatap, idmap, numid + numrel, &data);
1158           else if (id == SOLVABLE_REQUIRES)
1159             dp = data_read_rel_idarray(dp, &idarraydatap, idmap, numid + numrel, &data, SOLVABLE_PREREQMARKER);
1160           else if (id == SOLVABLE_PROVIDES)
1161             dp = data_read_rel_idarray(dp, &idarraydatap, idmap, numid + numrel, &data, SOLVABLE_FILEMARKER);
1162           else
1163             dp = data_read_rel_idarray(dp, &idarraydatap, idmap, numid + numrel, &data, 0);
1164           if (idarraydatap > idarraydataend)
1165             {
1166               pool_debug(pool, SOLV_ERROR, "idarray overflow\n");
1167               data.error = SOLV_ERROR_OVERFLOW;
1168               break;
1169             }
1170           if (id == SOLVABLE_PROVIDES)
1171             s->provides = ido;
1172           else if (id == SOLVABLE_OBSOLETES)
1173             s->obsoletes = ido;
1174           else if (id == SOLVABLE_CONFLICTS)
1175             s->conflicts = ido;
1176           else if (id == SOLVABLE_REQUIRES)
1177             s->requires = ido;
1178           else if (id == SOLVABLE_RECOMMENDS)
1179             s->recommends= ido;
1180           else if (id == SOLVABLE_SUPPLEMENTS)
1181             s->supplements = ido;
1182           else if (id == SOLVABLE_SUGGESTS)
1183             s->suggests = ido;
1184           else if (id == SOLVABLE_ENHANCES)
1185             s->enhances = ido;
1186 #if 0
1187           POOL_DEBUG(SOLV_DEBUG_STATS, "%s ->\n", pool_id2str(pool, id));
1188           for (; repo->idarraydata[ido]; ido++)
1189             POOL_DEBUG(SOLV_DEBUG_STATS,"  %s\n", pool_dep2str(pool, repo->idarraydata[ido]));
1190 #endif
1191           break;
1192         case REPOKEY_TYPE_FIXARRAY:
1193         case REPOKEY_TYPE_FLEXARRAY:
1194           if (!keydepth)
1195             needchunk = 1;
1196           if (keydepth == sizeof(stack)/sizeof(*stack))
1197             {
1198               pool_debug(pool, SOLV_ERROR, "array stack overflow\n");
1199               data.error = SOLV_ERROR_CORRUPT;
1200               break;
1201             }
1202           stack[keydepth++] = nentries;
1203           stack[keydepth++] = keyp - schemadata;
1204           stack[keydepth++] = 0;
1205           dp = data_read_id_max(dp, &nentries, 0, 0, &data);
1206           incore_add_id(&data, nentries);
1207           if (!nentries)
1208             {
1209               /* zero size array? */
1210               keydepth -= 2;
1211               nentries = stack[--keydepth];
1212               break;
1213             }
1214           if (keydepth == 3 && id == REPOSITORY_SOLVABLES)
1215             {
1216               /* horray! here come the solvables */
1217               if (nentries != numsolv)
1218                 {
1219                   pool_debug(pool, SOLV_ERROR, "inconsistent number of solvables: %d %d\n", nentries, numsolv);
1220                   data.error = SOLV_ERROR_CORRUPT;
1221                   break;
1222                 }
1223               if (idarraydatap)
1224                 {
1225                   pool_debug(pool, SOLV_ERROR, "more than one solvable block\n");
1226                   data.error = SOLV_ERROR_CORRUPT;
1227                   break;
1228                 }
1229               if (parent)
1230                 s = pool_id2solvable(pool, parent->start);
1231               else
1232                 s = pool_id2solvable(pool, repo_add_solvable_block(repo, numsolv));
1233               data.start = s - pool->solvables;
1234               data.end = data.start + numsolv;
1235               repodata_extend_block(&data, data.start, numsolv);
1236               for (i = 1; i < numkeys; i++)
1237                 {
1238                   id = keys[i].name;
1239                   if ((keys[i].type == REPOKEY_TYPE_IDARRAY || keys[i].type == REPOKEY_TYPE_REL_IDARRAY)
1240                       && id >= INTERESTED_START && id <= INTERESTED_END)
1241                     size_idarray += keys[i].size;
1242                 }
1243               /* allocate needed space in repo */
1244               /* we add maxsize because it is an upper limit for all idarrays, thus we can't overflow */
1245               repo_reserve_ids(repo, 0, size_idarray + maxsize + 1);
1246               idarraydatap = repo->idarraydata + repo->idarraysize;
1247               repo->idarraysize += size_idarray;
1248               idarraydataend = idarraydatap + size_idarray;
1249               repo->lastoff = 0;
1250               if (have_xdata)
1251                 data.incoreoffset[(s - pool->solvables) - data.start] = data.incoredatalen;
1252             }
1253           nentries--;
1254           dp = data_read_id_max(dp, &id, 0, numschemata, &data);
1255           incore_add_id(&data, id);
1256           if (keys[key].type == REPOKEY_TYPE_FIXARRAY)
1257             {
1258               if (!id)
1259                 {
1260                   pool_debug(pool, SOLV_ERROR, "illegal fixarray\n");
1261                   data.error = SOLV_ERROR_CORRUPT;
1262                 }
1263               stack[keydepth - 1] = id;
1264             }
1265           keyp = schemadata + schemata[id];
1266           break;
1267         case REPOKEY_TYPE_NUM:
1268           if (!(solvflags & SOLV_FLAG_SIZE_BYTES) && keys[key].storage == KEY_STORAGE_INCORE &&
1269                 (id == SOLVABLE_INSTALLSIZE || id == SOLVABLE_DOWNLOADSIZE || id == DELTA_DOWNLOADSIZE))
1270             {
1271               /* old solv file with sizes in kilos. transcode. */
1272               dp = data_read_id(dp, &id);
1273               incore_add_sizek(&data, (unsigned int)id);
1274               break;
1275             }
1276           /* FALLTHROUGH */
1277         default:
1278           if (id == RPM_RPMDBID && s && (keys[key].type == REPOKEY_TYPE_U32 || keys[key].type == REPOKEY_TYPE_NUM))
1279             {
1280               if (keys[key].type == REPOKEY_TYPE_U32)
1281                 dp = data_read_u32(dp, (unsigned int *)&id);
1282               else
1283                 dp = data_read_id_max(dp, &id, 0, 0, &data);
1284               if (!repo->rpmdbid)
1285                 repo->rpmdbid = repo_sidedata_create(repo, sizeof(Id));
1286               repo->rpmdbid[(s - pool->solvables) - repo->start] = id;
1287               break;
1288             }
1289           dps = dp;
1290           dp = data_skip(dp, keys[key].type);
1291           if (keys[key].storage == KEY_STORAGE_INCORE)
1292             incore_add_blob(&data, dps, dp - dps);
1293           break;
1294         }
1295     }
1296   /* should shrink idarraydata again */
1297
1298   if (keydepth)
1299     {
1300       pool_debug(pool, SOLV_ERROR, "unexpected EOF, depth = %d\n", keydepth);
1301       data.error = SOLV_ERROR_CORRUPT;
1302     }
1303   if (!data.error)
1304     {
1305       if (dp > bufend)
1306         {
1307           pool_debug(pool, SOLV_ERROR, "buffer overrun\n");
1308           data.error = SOLV_ERROR_EOF;
1309         }
1310     }
1311   solv_free(buf);
1312
1313   if (data.error)
1314     {
1315       /* free solvables */
1316       repo_free_solvable_block(repo, data.start, data.end - data.start, 1);
1317       /* free id array */
1318       repo->idarraysize -= size_idarray;
1319       /* free incore data */
1320       data.incoredata = solv_free(data.incoredata);
1321       data.incoredatalen = data.incoredatafree = 0;
1322     }
1323
1324   if (data.incoredatafree)
1325     {
1326       /* shrink excess size */
1327       data.incoredata = solv_realloc(data.incoredata, data.incoredatalen);
1328       data.incoredatafree = 0;
1329     }
1330
1331   for (i = 1; i < numkeys; i++)
1332     if (keys[i].storage == KEY_STORAGE_VERTICAL_OFFSET)
1333       break;
1334   if (i < numkeys && !data.error)
1335     {
1336       Id fileoffset = 0;
1337       unsigned int pagesize;
1338       
1339       /* we have vertical data, make it available */
1340       data.verticaloffset = solv_calloc(numkeys, sizeof(Id));
1341       for (i = 1; i < numkeys; i++)
1342         if (keys[i].storage == KEY_STORAGE_VERTICAL_OFFSET)
1343           {
1344             data.verticaloffset[i] = fileoffset;
1345             fileoffset += keys[i].size;
1346           }
1347       data.lastverticaloffset = fileoffset;
1348       pagesize = read_u32(&data);
1349       data.error = repopagestore_read_or_setup_pages(&data.store, data.fp, pagesize, fileoffset);
1350     }
1351   else
1352     {
1353       /* no longer needed */
1354       data.fp = 0;
1355     }
1356   solv_free(idmap);
1357
1358   if (data.error)
1359     {
1360       /* XXX: free repodata? */
1361       return data.error;
1362     }
1363
1364   if (parent)
1365     {
1366       /* overwrite stub repodata */
1367       repodata_freedata(parent);
1368       data.repodataid = parent->repodataid;
1369       *parent = data;
1370     }
1371   else
1372     {
1373       /* make it available as new repodata */
1374       if (!repo->nrepodata)
1375         {
1376           repo->nrepodata = 1;
1377           repo->repodata = solv_calloc(2, sizeof(data));
1378         }
1379       else
1380         repo->repodata = solv_realloc2(repo->repodata, repo->nrepodata + 1, sizeof(data));
1381       data.repodataid = repo->nrepodata;
1382       repo->repodata[repo->nrepodata++] = data;
1383     }
1384
1385   /* create stub repodata entries for all external */
1386   if (!(flags & SOLV_ADD_NO_STUBS) && !parent)
1387     {
1388       for (key = 1 ; key < data.nkeys; key++)
1389         if (data.keys[key].name == REPOSITORY_EXTERNAL && data.keys[key].type == REPOKEY_TYPE_FLEXARRAY)
1390           break;
1391       if (key < data.nkeys)
1392         repodata_create_stubs(repo->repodata + (repo->nrepodata - 1));
1393     }
1394
1395   POOL_DEBUG(SOLV_DEBUG_STATS, "repo_add_solv took %d ms\n", solv_timems(now));
1396   POOL_DEBUG(SOLV_DEBUG_STATS, "repo size: %d solvables\n", repo->nsolvables);
1397   POOL_DEBUG(SOLV_DEBUG_STATS, "repo memory used: %d K incore, %d K idarray\n", data.incoredatalen/1024, repo->idarraysize / (int)(1024/sizeof(Id)));
1398   return 0;
1399 }
1400