Support new types for MD5 and SHA1 checksums (stored in binary, but with
[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  * Read the binary dump of a Repo and create a Repo * from it
12  * 
13  *  See
14  *   Repo *pool_addrepo_solv(Pool *pool, FILE *fp)
15  * below
16  * 
17  */
18
19
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include <string.h>
25
26 #include "repo_solv.h"
27 #include "util.h"
28
29 #include "repopack.h"
30
31 #define INTERESTED_START        SOLVABLE_NAME
32 #define INTERESTED_END          SOLVABLE_FRESHENS
33
34 #define SOLV_ERROR_NOT_SOLV     1
35 #define SOLV_ERROR_UNSUPPORTED  2
36 #define SOLV_ERROR_EOF          3
37 #define SOLV_ERROR_ID_RANGE     4
38 #define SOLV_ERROR_OVERFLOW     5
39 #define SOLV_ERROR_CORRUPT      6
40
41 static Pool *mypool;            /* for pool_debug... */
42
43 /*-----------------------------------------------------------------*/
44 /* .solv read functions */
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(mypool, SAT_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(mypool, SAT_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(mypool, SAT_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(mypool, SAT_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(mypool, SAT_ERROR, "read_id: id too long\n");
130   data->error = SOLV_ERROR_CORRUPT;
131   return 0;
132 }
133
134
135 /*
136  * read array of Ids
137  */
138
139 #if 0
140 static Id *
141 read_rel_idarray(Repodata *data, Id max, Id *map, Id *store, Id *end, Id marker)
142 {
143   unsigned int x = 0;
144   int c;
145   Id old = 0;
146
147   if (data->error)
148     return 0;
149   for (;;)
150     {
151       c = getc(data->fp);
152       if (c == EOF)
153         {
154           pool_debug(mypool, SAT_ERROR, "unexpected EOF\n");
155           data->error = SOLV_ERROR_EOF;
156           return 0;
157         }
158       if ((c & 128) != 0)
159         {
160           x = (x << 7) ^ c ^ 128;
161           continue;
162         }
163       x = (x << 6) | (c & 63);
164       if (x == 0)
165         {
166           /* marker hack */
167           if (store == end)
168             {
169               pool_debug(mypool, SAT_ERROR, "read_rel_idarray: array overflow\n");
170               data->error = SOLV_ERROR_OVERFLOW;
171               return 0;
172             }
173           if (c != 0x40)
174             {
175               *store++ = 0;
176               return store;
177             }
178           *store++ = marker;    /* do not map! */
179           old = 0;
180           x = 0;
181           continue;
182         }
183       x = (x - 1) + old;
184       old = x;
185       if (max && x >= max)
186         {
187           pool_debug(mypool, SAT_ERROR, "read_rel_idarray: id too large (%u/%u)\n", x, max);
188           data->error = SOLV_ERROR_ID_RANGE;
189           return 0;
190         }
191       if (map)
192         x = map[x];
193       if (store == end)
194         {
195           pool_debug(mypool, SAT_ERROR, "read_rel_idarray: array overflow\n");
196           return 0;
197         }
198       *store++ = x;
199       if ((c & 64) == 0)
200         {
201           if (x == 0)   /* already have trailing zero? */
202             return store;
203           if (store == end)
204             {
205               pool_debug(mypool, SAT_ERROR, "read_rel_idarray: array overflow\n");
206               data->error = SOLV_ERROR_OVERFLOW;
207               return 0;
208             }
209           *store++ = 0;
210           return store;
211         }
212       x = 0;
213     }
214 }
215 #endif
216
217 static inline unsigned char *
218 data_read_id_max(unsigned char *dp, Id *ret, Id *map, int max, int *error)
219 {
220   Id x;
221   dp = data_read_id(dp, &x);
222   if (max && x >= max)
223     {
224       pool_debug(mypool, SAT_ERROR, "data_read_idarray: id too large (%u/%u)\n", x, max);
225       *error = SOLV_ERROR_ID_RANGE;
226       x = 0;
227     }
228   *ret = map ? map[x] : x;
229   return dp;
230 }
231
232 unsigned char *
233 data_read_idarray(unsigned char *dp, Id **storep, Id *map, int max, int *error)
234 {
235   Id *store = *storep;
236   unsigned int x = 0;
237   int c;
238
239   for (;;)
240     {
241       c = *dp++;
242       if ((c & 128) != 0)
243         {
244           x = (x << 7) ^ c ^ 128;
245           continue;
246         }
247       x = (x << 6) | (c & 63);
248       if (max && x >= max)
249         {
250           pool_debug(mypool, SAT_ERROR, "data_read_idarray: id too large (%u/%u)\n", x, max);
251           *error = SOLV_ERROR_ID_RANGE;
252           break;
253         }
254       *store++ = x;
255       if ((c & 64) == 0)
256         break;
257       x = 0;
258     }
259   *store++ = 0;
260   *storep = store;
261   return dp;
262 }
263
264 unsigned char *
265 data_read_rel_idarray(unsigned char *dp, Id **storep, Id *map, int max, int *error, Id marker)
266 {
267   Id *store = *storep;
268   Id old = 0;
269   unsigned int x = 0;
270   int c;
271
272   for (;;)
273     {
274       c = *dp++;
275       if ((c & 128) != 0)
276         {
277           x = (x << 7) ^ c ^ 128;
278           continue;
279         }
280       x = (x << 6) | (c & 63);
281       if (x == 0)
282         {
283           if (!(c & 64))
284             break;
285           if (marker)
286             *store++ = marker;
287           old = 0;
288           continue;
289         }
290       x = old + (x - 1);
291       old = x;
292       if (max && x >= max)
293         {
294           pool_debug(mypool, SAT_ERROR, "data_read_rel_idarray: id too large (%u/%u)\n", x, max);
295           *error = SOLV_ERROR_ID_RANGE;
296           break;
297         }
298       *store++ = map ? map[x] : x;
299       if (!(c & 64))
300         break;
301       x = 0;
302     }
303   *store++ = 0;
304   *storep = store;
305   return dp;
306 }
307
308
309 static Id *
310 read_idarray(Repodata *data, Id max, Id *map, Id *store, Id *end)
311 {
312   unsigned int x = 0;
313   int c;
314
315   if (data->error)
316     return 0;
317   for (;;)
318     {
319       c = getc(data->fp);
320       if (c == EOF)
321         {
322           pool_debug(mypool, SAT_ERROR, "unexpected EOF\n");
323           data->error = SOLV_ERROR_EOF;
324           return 0;
325         }
326       if ((c & 128) != 0)
327         {
328           x = (x << 7) ^ c ^ 128;
329           continue;
330         }
331       x = (x << 6) | (c & 63);
332       if (max && x >= max)
333         {
334           pool_debug(mypool, SAT_ERROR, "read_idarray: id too large (%u/%u)\n", x, max);
335           data->error = SOLV_ERROR_ID_RANGE;
336           return 0;
337         }
338       if (map)
339         x = map[x];
340       if (store == end)
341         {
342           pool_debug(mypool, SAT_ERROR, "read_idarray: array overflow\n");
343           return 0;
344         }
345       *store++ = x;
346       if ((c & 64) == 0)
347         {
348           if (x == 0)   /* already have trailing zero? */
349             return store;
350           if (store == end)
351             {
352               pool_debug(mypool, SAT_ERROR, "read_idarray: array overflow\n");
353               data->error = SOLV_ERROR_OVERFLOW;
354               return 0;
355             }
356           *store++ = 0;
357           return store;
358         }
359       x = 0;
360     }
361 }
362
363 static void
364 read_str(Repodata *data, char **inbuf, unsigned *len)
365 {
366   unsigned char *buf = (unsigned char*)*inbuf;
367   if (!buf)
368     {
369       buf = sat_malloc(1024);
370       *len = 1024;
371     }
372   int c;
373   unsigned ofs = 0;
374   while((c = getc(data->fp)) != 0)
375     {
376       if (c == EOF)
377         {
378           pool_debug (mypool, SAT_ERROR, "unexpected EOF\n");
379           data->error = SOLV_ERROR_EOF;
380           return;
381         }
382       /* Plus 1 as we also want to add the 0.  */
383       if (ofs + 1 >= *len)
384         {
385           *len += 256;
386           /* Don't realloc on the inbuf, it might be on the stack.  */
387           if (buf == (unsigned char*)*inbuf)
388             {
389               buf = sat_malloc(*len);
390               memcpy(buf, *inbuf, *len - 256);
391             }
392           else
393             buf = sat_realloc(buf, *len);
394         }
395       buf[ofs++] = c;
396     }
397   buf[ofs++] = 0;
398   *inbuf = (char*)buf;
399 }
400
401 static void
402 skip_item(Repodata *data, unsigned type, unsigned numid, unsigned numrel)
403 {
404   switch (type)
405     {
406       case REPOKEY_TYPE_VOID:
407       case REPOKEY_TYPE_CONSTANT:
408       case REPOKEY_TYPE_CONSTANTID:
409         break;
410       case REPOKEY_TYPE_ID:
411         read_id(data, numid + numrel);          /* just check Id */
412         break;
413       case REPOKEY_TYPE_DIR:
414         read_id(data, numid + data->dirpool.ndirs);     /* just check Id */
415         break;
416       case REPOKEY_TYPE_NUM:
417         read_id(data, 0);
418         break;
419       case REPOKEY_TYPE_U32:
420         read_u32(data);
421         break;
422       case REPOKEY_TYPE_STR:
423         while (read_u8(data) != 0)
424           ;
425         break;
426       case REPOKEY_TYPE_MD5:
427         {
428           int i;
429           for (i = 0; i < SIZEOF_MD5; i++)
430             read_u8(data);
431           break;
432         }
433       case REPOKEY_TYPE_SHA1:
434         {
435           int i;
436           for (i = 0; i < SIZEOF_SHA1; i++)
437             read_u8(data);
438           break;
439         }
440       case REPOKEY_TYPE_IDARRAY:
441       case REPOKEY_TYPE_REL_IDARRAY:
442         while ((read_u8(data) & 0xc0) != 0)
443           ;
444         break;
445       case REPOKEY_TYPE_DIRNUMNUMARRAY:
446         for (;;)
447           {
448             read_id(data, numid + data->dirpool.ndirs); /* just check Id */
449             read_id(data, 0);
450             if (!(read_id(data, 0) & 0x40))
451               break;
452           }
453         break;
454       case REPOKEY_TYPE_DIRSTRARRAY:
455         for (;;)
456           {
457             Id id = read_id(data, 0);
458             while (read_u8(data) != 0)
459               ;
460             if (!(id & 0x40))
461               break;
462           }
463         break;
464       default:
465         pool_debug(mypool, SAT_ERROR, "unknown type %d\n", type);
466         data->error = SOLV_ERROR_CORRUPT;
467         break;
468     }
469 }
470
471 static int
472 key_cmp (const void *pa, const void *pb)
473 {
474   Repokey *a = (Repokey *)pa;
475   Repokey *b = (Repokey *)pb;
476   return a->name - b->name;
477 }
478
479 static void repodata_load_solv(Repodata *data);
480
481 static void
482 parse_external_repodata(Repodata *maindata, Id *keyp, Repokey *keys, Id *idmap, unsigned numid, unsigned numrel)
483 {
484   Repo *repo = maindata->repo;
485   Id key, id;
486   Id *ida, *ide;
487   Repodata *data;
488   int i, n;
489
490   repo->repodata = sat_realloc2(repo->repodata, repo->nrepodata + 1, sizeof (*data));
491   data = repo->repodata + repo->nrepodata++;
492   memset(data, 0, sizeof(*data));
493   data->repo = repo;
494   data->pagefd = -1;
495   data->state = REPODATA_STUB;
496   data->loadcallback = repodata_load_solv;
497
498   while ((key = *keyp++) != 0)
499     {
500       id = keys[key].name;
501       switch (keys[key].type)
502         {
503         case REPOKEY_TYPE_IDARRAY:
504           if (id != REPODATA_KEYS)
505             {
506               skip_item(maindata, REPOKEY_TYPE_IDARRAY, numid, numrel);
507               break;
508             }
509           /* read_idarray writes a terminating 0, that's why the + 1 */
510           ida = sat_calloc(keys[key].size + 1, sizeof(Id));
511           ide = read_idarray(maindata, numid, idmap, ida, ida + keys[key].size + 1);
512           n = ide - ida - 1;
513           if (n & 1)
514             {
515               pool_debug (mypool, SAT_ERROR, "invalid attribute data\n");
516               maindata->error = SOLV_ERROR_CORRUPT;
517               return;
518             }
519           data->nkeys = 1 + (n >> 1);
520           data->keys = sat_malloc2(data->nkeys, sizeof(data->keys[0]));
521           memset(data->keys, 0, sizeof(Repokey));
522           for (i = 1, ide = ida; i < data->nkeys; i++)
523             {
524               data->keys[i].name = *ide++;
525               data->keys[i].type = *ide++;
526               data->keys[i].size = 0;
527               data->keys[i].storage = 0;
528             }
529           sat_free(ida);
530           if (data->nkeys > 2)
531             qsort(data->keys + 1, data->nkeys - 1, sizeof(data->keys[0]), key_cmp);
532           break;
533         case REPOKEY_TYPE_STR:
534           if (id != REPODATA_LOCATION)
535             skip_item(maindata, REPOKEY_TYPE_STR, numid, numrel);
536           else
537             {
538               char buf[1024];
539               unsigned len = sizeof(buf);
540               char *filename = buf;
541               read_str(maindata, &filename, &len);
542               data->location = strdup(filename);
543               if (filename != buf)
544                 free(filename);
545             }
546           break;
547         default:
548           skip_item(maindata, keys[key].type, numid, numrel);
549           break;
550         }
551     }
552 }
553
554 static void
555 parse_info_repodata(Repodata *maindata, Id *keyp, Repokey *keys, Id *idmap, unsigned numid, unsigned numrel)
556 {
557   Id key, id;
558   Id *ida;
559   while ((key = *keyp++) != 0)
560     {
561       id = keys[key].name;
562       if (id == REPODATA_ADDEDFILEPROVIDES && keys[key].type == REPOKEY_TYPE_REL_IDARRAY)
563         {
564           Id old = 0;
565           /* + 1 just in case */
566           ida = sat_calloc(keys[key].size + 1, sizeof(Id));
567           read_idarray(maindata, 0, 0, ida, ida + keys[key].size + 1);
568           maindata->addedfileprovides = ida;
569           for (; *ida; ida++)
570             {
571               old += *ida - 1;
572               if (old >= numid)
573                 {
574                   *ida = 0;
575                   break;
576                 }
577               *ida = idmap ? idmap[old] : old;
578             }
579           continue;
580         }
581       skip_item(maindata, keys[key].type, numid, numrel);
582     }
583 }
584
585 /*-----------------------------------------------------------------*/
586
587
588 static void
589 skip_schema(Repodata *data, Id *keyp, Repokey *keys, unsigned int numid, unsigned int numrel)
590 {
591   Id key;
592   while ((key = *keyp++) != 0)
593     skip_item(data, keys[key].type, numid, numrel);
594 }
595
596 /*-----------------------------------------------------------------*/
597
598 static void
599 incore_add_id(Repodata *data, Id x)
600 {
601   unsigned char *dp;
602   /* make sure we have at least 5 bytes free */
603   if (data->incoredatafree < 5)
604     {
605       data->incoredata = sat_realloc(data->incoredata, data->incoredatalen + 1024);
606       data->incoredatafree = 1024;
607     }
608   dp = data->incoredata + data->incoredatalen;
609   if (x < 0)
610     abort();
611   if (x >= (1 << 14))
612     {
613       if (x >= (1 << 28))
614         *dp++ = (x >> 28) | 128;
615       if (x >= (1 << 21))
616         *dp++ = (x >> 21) | 128;
617       *dp++ = (x >> 14) | 128;
618     }
619   if (x >= (1 << 7))
620     *dp++ = (x >> 7) | 128;
621   *dp++ = x & 127;
622   data->incoredatafree -= dp - (data->incoredata + data->incoredatalen);
623   data->incoredatalen = dp - data->incoredata;
624 }
625
626 static void
627 incore_add_blob(Repodata *data, unsigned char *buf, int len)
628 {
629   if (data->incoredatafree < len)
630     {
631       data->incoredata = sat_realloc(data->incoredata, data->incoredatalen + 1024 + len);
632       data->incoredatafree = 1024 + len;
633     }
634   memcpy(data->incoredata + data->incoredatalen, buf, len);
635   data->incoredatafree -= len;
636   data->incoredatalen += len;
637 }
638
639 static void
640 incore_map_idarray(Repodata *data, unsigned char *dp, Id *map, Id max)
641 {
642   /* We have to map the IDs, which might also change
643      the necessary number of bytes, so we can't just copy
644      over the blob and adjust it.  */
645   for (;;)
646     {
647       Id id;
648       int eof;
649       dp = data_read_ideof(dp, &id, &eof);
650       if (max && id >= max)
651         {
652           pool_debug(mypool, SAT_ERROR, "incore_map_idarray: id too large (%u/%u)\n", id, max);
653           data->error = SOLV_ERROR_ID_RANGE;
654           break;
655         }
656       id = map[id];
657       if (id >= 64)
658         id = (id & 63) | ((id & ~63) << 1);
659       incore_add_id(data, eof ? id : id | 64);
660       if (eof)
661         break;
662     }
663 }
664
665 static void
666 incore_add_u32(Repodata *data, unsigned int x)
667 {
668   unsigned char *dp;
669   /* make sure we have at least 4 bytes free */
670   if (data->incoredatafree < 4)
671     {
672       data->incoredata = sat_realloc(data->incoredata, data->incoredatalen + 1024);
673       data->incoredatafree = 1024;
674     }
675   dp = data->incoredata + data->incoredatalen;
676   *dp++ = x >> 24;
677   *dp++ = x >> 16;
678   *dp++ = x >> 8;
679   *dp++ = x;
680   data->incoredatafree -= 4;
681   data->incoredatalen += 4;
682 }
683
684 #if 0
685 static void
686 incore_add_u8(Repodata *data, unsigned int x)
687 {
688   unsigned char *dp;
689   /* make sure we have at least 1 byte free */
690   if (data->incoredatafree < 1)
691     {
692       data->incoredata = sat_realloc(data->incoredata, data->incoredatalen + 1024);
693       data->incoredatafree = 1024;
694     }
695   dp = data->incoredata + data->incoredatalen;
696   *dp++ = x;
697   data->incoredatafree--;
698   data->incoredatalen++;
699 }
700 #endif
701
702
703
704 // ----------------------------------------------
705
706
707 /*
708  * read repo from .solv file
709  *  and add it to pool
710  */
711
712 static int
713 repo_add_solv_parent(Repo *repo, FILE *fp, Repodata *parent)
714 {
715   Pool *pool = repo->pool;
716   int i, l;
717   unsigned int numid, numrel, numdir, numsolv;
718   unsigned int numkeys, numschemata, numinfo;
719
720   Offset sizeid;
721   Offset *str;                         /* map Id -> Offset into string space */
722   char *strsp;                         /* repo string space */
723   char *sp;                            /* pointer into string space */
724   Id *idmap;                           /* map of repo Ids to pool Ids */
725   Id id, type;
726   unsigned int hashmask, h;
727   int hh;
728   Id *hashtbl;
729   Id name, evr, did;
730   int flags;
731   Reldep *ran;
732   unsigned int size_idarray;
733   Id *idarraydatap, *idarraydataend;
734   Offset ido;
735   Solvable *s;
736   unsigned int solvflags;
737   unsigned int solvversion;
738   Repokey *keys;
739   Id *schemadata, *schemadatap, *schemadataend;
740   Id *schemata, key;
741   int have_xdata;
742   unsigned oldnrepodata;
743   int maxsize, allsize;
744   unsigned char *buf, *dp, *dps;
745   int left;
746
747   struct _Stringpool *spool;
748
749   Repodata data;
750
751   memset(&data, 0, sizeof(data));
752   data.repo = repo;
753   data.fp = fp;
754   data.pagefd = -1;
755
756   mypool = pool;
757
758   if (read_u32(&data) != ('S' << 24 | 'O' << 16 | 'L' << 8 | 'V'))
759     {
760       pool_debug(pool, SAT_ERROR, "not a SOLV file\n");
761       return SOLV_ERROR_NOT_SOLV;
762     }
763   solvversion = read_u32(&data);
764   switch (solvversion)
765     {
766       case SOLV_VERSION_6:
767         break;
768       default:
769         pool_debug(pool, SAT_ERROR, "unsupported SOLV version\n");
770         return SOLV_ERROR_UNSUPPORTED;
771     }
772
773   pool_freeidhashes(pool);
774
775   numid = read_u32(&data);
776   numrel = read_u32(&data);
777   numdir = read_u32(&data);
778   numsolv = read_u32(&data);
779   numkeys = read_u32(&data);
780   numschemata = read_u32(&data);
781   numinfo = read_u32(&data);
782   solvflags = read_u32(&data);
783
784   if (numdir && numdir < 2)
785     {
786       pool_debug(pool, SAT_ERROR, "bad number of dirs\n");
787       return SOLV_ERROR_CORRUPT;
788     }
789
790   if (parent)
791     {
792       if (numrel)
793         {
794           pool_debug(pool, SAT_ERROR, "relations are forbidden in a store\n");
795           return SOLV_ERROR_CORRUPT;
796         }
797       if (parent->end - parent->start != numsolv)
798         {
799           pool_debug(pool, SAT_ERROR, "unequal number of solvables in a store\n");
800           return SOLV_ERROR_CORRUPT;
801         }
802       if (numinfo)
803         {
804           pool_debug(pool, SAT_ERROR, "info blocks are forbidden in a store\n");
805           return SOLV_ERROR_CORRUPT;
806         }
807     }
808
809   /*******  Part 1: string IDs  *****************************************/
810
811   sizeid = read_u32(&data);            /* size of string+Id space */
812
813   /*
814    * read strings and Ids
815    * 
816    */
817
818   
819   /*
820    * alloc buffers
821    */
822
823   if (!parent)
824     spool = &pool->ss;
825   else
826     {
827       data.localpool = 1;
828       spool = &data.spool;
829       spool->stringspace = sat_malloc(7);
830       strcpy(spool->stringspace, "<NULL>");
831       spool->sstrings = 7;
832       spool->nstrings = 0;
833     }
834
835   /* alloc string buffer */
836   spool->stringspace = sat_realloc(spool->stringspace, spool->sstrings + sizeid + 1);
837   /* alloc string offsets (Id -> Offset into string space) */
838   spool->strings = sat_realloc2(spool->strings, spool->nstrings + numid, sizeof(Offset));
839
840   strsp = spool->stringspace;
841   str = spool->strings;                /* array of offsets into strsp, indexed by Id */
842
843   /* point to _BEHIND_ already allocated string/Id space */
844   strsp += spool->sstrings;
845
846
847   /*
848    * read new repo at end of pool
849    */
850   
851   if ((solvflags & SOLV_FLAG_PREFIX_POOL) == 0)
852     {
853       if (sizeid && fread(strsp, sizeid, 1, fp) != 1)
854         {
855           pool_debug(pool, SAT_ERROR, "read error while reading strings\n");
856           return SOLV_ERROR_EOF;
857         }
858     }
859   else
860     {
861       unsigned int pfsize = read_u32(&data);
862       char *prefix = sat_malloc(pfsize);
863       char *pp = prefix;
864       char *old_str = 0;
865       char *dest = strsp;
866       int freesp = sizeid;
867
868       if (pfsize && fread(prefix, pfsize, 1, fp) != 1)
869         {
870           pool_debug(pool, SAT_ERROR, "read error while reading strings\n");
871           sat_free(prefix);
872           return SOLV_ERROR_EOF;
873         }
874       for (i = 1; i < numid; i++)
875         {
876           int same = (unsigned char)*pp++;
877           size_t len = strlen(pp) + 1;
878           freesp -= same + len;
879           if (freesp < 0)
880             {
881               pool_debug(pool, SAT_ERROR, "overflow while expanding strings\n");
882               sat_free(prefix);
883               return SOLV_ERROR_OVERFLOW;
884             }
885           if (same)
886             memcpy(dest, old_str, same);
887           memcpy(dest + same, pp, len);
888           pp += len;
889           old_str = dest;
890           dest += same + len;
891         }
892       sat_free(prefix);
893       if (freesp != 0)
894         {
895           pool_debug(pool, SAT_ERROR, "expanding strings size mismatch\n");
896           return SOLV_ERROR_CORRUPT;
897         }
898     }
899   strsp[sizeid] = 0;                   /* make string space \0 terminated */
900   sp = strsp;
901
902   if (parent)
903     {
904       /* no shared pool, thus no idmap and no unification */
905       idmap = 0;
906       spool->nstrings = numid;
907       str[0] = 0;
908       if (*sp)
909         {
910           /* we need the '' for directories */
911           pool_debug(pool, SAT_ERROR, "store strings don't start with ''\n");
912           return SOLV_ERROR_CORRUPT;
913         }
914       for (i = 1; i < spool->nstrings; i++)
915         {
916           if (sp >= strsp + sizeid)
917             {
918               pool_debug(pool, SAT_ERROR, "not enough strings\n");
919               return SOLV_ERROR_OVERFLOW;
920             }
921           str[i] = sp - spool->stringspace;
922           sp += strlen(sp) + 1;
923         }
924       spool->sstrings = sp - spool->stringspace;
925     }
926   else
927     {
928
929       /* alloc id map for name and rel Ids. this maps ids in the solv files
930        * to the ids in our pool */
931       idmap = sat_calloc(numid + numrel, sizeof(Id));
932
933       /*
934        * build hashes for all read strings
935        * 
936        */
937       
938       hashmask = mkmask(spool->nstrings + numid);
939
940 #if 0
941       POOL_DEBUG(SAT_DEBUG_STATS, "read %d strings\n", numid);
942       POOL_DEBUG(SAT_DEBUG_STATS, "string hash buckets: %d\n", hashmask + 1);
943 #endif
944
945       /*
946        * create hashtable with strings already in pool
947        */
948
949       hashtbl = sat_calloc(hashmask + 1, sizeof(Id));
950       for (i = 1; i < spool->nstrings; i++)  /* leave out our dummy zero id */
951         {
952           h = strhash(spool->stringspace + spool->strings[i]) & hashmask;
953           hh = HASHCHAIN_START;
954           while (hashtbl[h])
955             h = HASHCHAIN_NEXT(h, hh, hashmask);
956           hashtbl[h] = i;
957         }
958
959       /*
960        * run over string space, calculate offsets
961        * 
962        * build id map (maps solv Id -> pool Id)
963        */
964       
965       for (i = 1; i < numid; i++)
966         {
967           if (sp >= strsp + sizeid)
968             {
969               sat_free(hashtbl);
970               sat_free(idmap);
971               pool_debug(pool, SAT_ERROR, "not enough strings %d %d\n", i, numid);
972               return SOLV_ERROR_OVERFLOW;
973             }
974           if (!*sp)                            /* empty string */
975             {
976               idmap[i] = ID_EMPTY;
977               sp++;
978               continue;
979             }
980
981           /* find hash slot */
982           h = strhash(sp) & hashmask;
983           hh = HASHCHAIN_START;
984           for (;;)
985             {
986               id = hashtbl[h];
987               if (id == 0)
988                 break;
989               if (!strcmp(spool->stringspace + spool->strings[id], sp))
990                 break;                 /* existing string */
991               h = HASHCHAIN_NEXT(h, hh, hashmask);
992             }
993
994           /* length == offset to next string */
995           l = strlen(sp) + 1;
996           if (id == ID_NULL)           /* end of hash chain -> new string */
997             {
998               id = spool->nstrings++;
999               hashtbl[h] = id;
1000               str[id] = spool->sstrings;    /* save Offset */
1001               if (sp != spool->stringspace + spool->sstrings)   /* not at end-of-buffer */
1002                 memmove(spool->stringspace + spool->sstrings, sp, l);   /* append to pool buffer */
1003               spool->sstrings += l;
1004             }
1005           idmap[i] = id;                       /* repo relative -> pool relative */
1006           sp += l;                             /* next string */
1007         }
1008       sat_free(hashtbl);
1009     }
1010   pool_shrink_strings(pool);           /* vacuum */
1011
1012   
1013   /*******  Part 2: Relation IDs  ***************************************/
1014
1015   /*
1016    * read RelDeps
1017    * 
1018    */
1019   
1020   if (numrel)
1021     {
1022       /* extend rels */
1023       pool->rels = sat_realloc2(pool->rels, pool->nrels + numrel, sizeof(Reldep));
1024       ran = pool->rels;
1025
1026       hashmask = mkmask(pool->nrels + numrel);
1027 #if 0
1028       POOL_DEBUG(SAT_DEBUG_STATS, "read %d rels\n", numrel);
1029       POOL_DEBUG(SAT_DEBUG_STATS, "rel hash buckets: %d\n", hashmask + 1);
1030 #endif
1031       /*
1032        * prep hash table with already existing RelDeps
1033        */
1034       
1035       hashtbl = sat_calloc(hashmask + 1, sizeof(Id));
1036       for (i = 1; i < pool->nrels; i++)
1037         {
1038           h = relhash(ran[i].name, ran[i].evr, ran[i].flags) & hashmask;
1039           hh = HASHCHAIN_START;
1040           while (hashtbl[h])
1041             h = HASHCHAIN_NEXT(h, hh, hashmask);
1042           hashtbl[h] = i;
1043         }
1044
1045       /*
1046        * read RelDeps from repo
1047        */
1048       
1049       for (i = 0; i < numrel; i++)
1050         {
1051           name = read_id(&data, i + numid);     /* read (repo relative) Ids */
1052           evr = read_id(&data, i + numid);
1053           flags = read_u8(&data);
1054           name = idmap[name];           /* map to (pool relative) Ids */
1055           evr = idmap[evr];
1056           h = relhash(name, evr, flags) & hashmask;
1057           hh = HASHCHAIN_START;
1058           for (;;)
1059             {
1060               id = hashtbl[h];
1061               if (id == ID_NULL)        /* end of hash chain */
1062                 break;
1063               if (ran[id].name == name && ran[id].evr == evr && ran[id].flags == flags)
1064                 break;
1065               h = HASHCHAIN_NEXT(h, hh, hashmask);
1066             }
1067           if (id == ID_NULL)            /* new RelDep */
1068             {
1069               id = pool->nrels++;
1070               hashtbl[h] = id;
1071               ran[id].name = name;
1072               ran[id].evr = evr;
1073               ran[id].flags = flags;
1074             }
1075           idmap[i + numid] = MAKERELDEP(id);   /* fill Id map */
1076         }
1077       sat_free(hashtbl);
1078       pool_shrink_rels(pool);           /* vacuum */
1079     }
1080
1081
1082   /*******  Part 3: Dirs  ***********************************************/
1083   if (numdir)
1084     {
1085       data.dirpool.dirs = sat_malloc2(numdir, sizeof(Id));
1086       data.dirpool.ndirs = numdir;
1087       data.dirpool.dirs[0] = 0;         /* dir 0: virtual root */
1088       data.dirpool.dirs[1] = 1;         /* dir 1: / */
1089       for (i = 2; i < numdir; i++)
1090         {
1091           id = read_id(&data, i + numid);
1092           if (id >= numid)
1093             data.dirpool.dirs[i] = -(id - numid);
1094           else if (idmap)
1095             data.dirpool.dirs[i] = idmap[id];
1096           else
1097             data.dirpool.dirs[i] = id;
1098         }
1099     }
1100
1101   /*******  Part 4: Keys  ***********************************************/
1102
1103   keys = sat_calloc(numkeys, sizeof(*keys));
1104   /* keys start at 1 */
1105   for (i = 1; i < numkeys; i++)
1106     {
1107       id = read_id(&data, numid);
1108       if (idmap)
1109         id = idmap[id];
1110       else if (parent)
1111         id = str2id(pool, stringpool_id2str(spool, id), 1);
1112       type = read_id(&data, numid);
1113       if (idmap)
1114         type = idmap[type];
1115       else if (parent)
1116         type = str2id(pool, stringpool_id2str(spool, type), 1);
1117       if (type < REPOKEY_TYPE_VOID || type > REPOKEY_TYPE_SHA1)
1118         {
1119           pool_debug(pool, SAT_ERROR, "unsupported data type '%s'\n", id2str(pool, type));
1120           data.error = SOLV_ERROR_UNSUPPORTED;
1121           type = REPOKEY_TYPE_VOID;
1122         }
1123       keys[i].name = id;
1124       keys[i].type = type;
1125       keys[i].size = read_id(&data, keys[i].type == REPOKEY_TYPE_CONSTANTID ? numid + numrel : 0);
1126       keys[i].storage = read_id(&data, 0);
1127       if (id >= SOLVABLE_NAME && id <= RPM_RPMDBID)
1128         keys[i].storage = KEY_STORAGE_SOLVABLE;
1129       else if (keys[i].storage == KEY_STORAGE_SOLVABLE)
1130         keys[i].storage = KEY_STORAGE_INCORE;
1131       if (keys[i].type == REPOKEY_TYPE_CONSTANTID)
1132         {
1133           if (idmap)
1134             keys[i].size = idmap[keys[i].size];
1135           else if (parent)
1136             keys[i].size = str2id(pool, stringpool_id2str(spool, keys[i].size), 1);
1137         }
1138 #if 0
1139       fprintf(stderr, "key %d %s %s %d %d\n", i, id2str(pool,id), id2str(pool, keys[i].type),
1140                keys[i].size, keys[i].storage);
1141 #endif
1142     }
1143
1144   have_xdata = parent ? 1 : 0;
1145   for (i = 1; i < numkeys; i++)
1146     if (keys[i].storage == KEY_STORAGE_INCORE || keys[i].storage == KEY_STORAGE_VERTICAL_OFFSET)
1147       have_xdata = 1;
1148
1149   data.keys = keys;
1150   data.nkeys = numkeys;
1151
1152   /*******  Part 5: Schemata ********************************************/
1153   
1154   id = read_id(&data, 0);
1155   schemadata = sat_calloc(id + 1, sizeof(Id));
1156   schemadatap = schemadata + 1;
1157   schemadataend = schemadatap + id;
1158   schemata = sat_calloc(numschemata, sizeof(Id));
1159   for (i = 1; i < numschemata; i++)
1160     {
1161       schemata[i] = schemadatap - schemadata;
1162       schemadatap = read_idarray(&data, numid, 0, schemadatap, schemadataend);
1163 #if 0
1164       Id *sp = schemadata + schemata[i];
1165       fprintf (stderr, "schema %d:", i);
1166       for (; *sp; sp++)
1167         fprintf (stderr, " %d", *sp);
1168       fprintf (stderr, "\n");
1169 #endif
1170     }
1171   data.schemata = schemata;
1172   data.nschemata = numschemata;
1173   data.schemadata = schemadata;
1174   data.schemadatalen = schemadataend - data.schemadata;
1175
1176
1177   /*******  Part 6: Info  ***********************************************/
1178   oldnrepodata = repo->nrepodata;
1179   if (numinfo)
1180     {
1181       id = read_id(&data, 0);
1182       id = read_id(&data, 0);
1183     }
1184   for (i = 0; i < numinfo; i++)
1185     {
1186       /* for now we're just interested in data that starts with
1187        * the repodata_external id
1188        */
1189       Id *keyp;
1190       id = read_id(&data, numschemata);
1191       keyp = schemadata + schemata[id];
1192       key = *keyp;
1193       if (keys[key].name == REPODATA_EXTERNAL && keys[key].type == REPOKEY_TYPE_VOID)
1194         {
1195           /* external data for some ids */
1196           parse_external_repodata(&data, keyp, keys, idmap, numid, numrel);
1197         }
1198       else if (keys[key].name == REPODATA_INFO)
1199         {
1200           parse_info_repodata(&data, keyp, keys, idmap, numid, numrel);
1201         }
1202       else
1203         {
1204           skip_schema(&data, keyp, keys, numid, numrel);
1205         }
1206     }
1207
1208
1209   /*******  Part 7: item data *******************************************/
1210
1211   /* calculate idarray size */
1212   size_idarray = 0;
1213   for (i = 1; i < numkeys; i++)
1214     {
1215       id = keys[i].name;
1216       if ((keys[i].type == REPOKEY_TYPE_IDARRAY || keys[i].type == REPOKEY_TYPE_REL_IDARRAY)
1217           && id >= INTERESTED_START && id <= INTERESTED_END)
1218         size_idarray += keys[i].size;
1219     }
1220
1221   if (numsolv)
1222     {
1223       maxsize = read_id(&data, 0);
1224       allsize = read_id(&data, 0);
1225       if (maxsize > allsize)
1226         {
1227           pool_debug(pool, SAT_ERROR, "maxsize %d is greater then allsize %d\n", maxsize, allsize);
1228           data.error = SOLV_ERROR_CORRUPT;
1229         }
1230     }
1231   else
1232     maxsize = allsize = 0;
1233
1234   /* allocate needed space in repo */
1235   /* we add maxsize because it is an upper limit for all idarrays */
1236   repo_reserve_ids(repo, 0, size_idarray + maxsize + 1);
1237   idarraydatap = repo->idarraydata + repo->idarraysize;
1238   repo->idarraysize += size_idarray;
1239   idarraydataend = idarraydatap + size_idarray;
1240   repo->lastoff = 0;
1241
1242   /* read solvables */
1243   if (numsolv)
1244     {
1245       if (parent)
1246         s = pool_id2solvable(pool, parent->start);
1247       else
1248         s = pool_id2solvable(pool, repo_add_solvable_block(repo, numsolv));
1249       /* store start and end of our id block */
1250       data.start = s - pool->solvables;
1251       data.end = data.start + numsolv;
1252       /* In case we have info blocks, make them refer to our part of the 
1253          repository now.  */
1254       for (i = oldnrepodata; i < repo->nrepodata; i++)
1255         {
1256           repo->repodata[i].start = data.start;
1257           repo->repodata[i].end = data.end;
1258         }
1259     }
1260   else
1261     s = 0;
1262
1263   if (have_xdata)
1264     {
1265       /* reserve one byte so that all offsets are not zero */
1266       incore_add_id(&data, 0);
1267       repodata_extend_block(&data, data.start, numsolv);
1268     }
1269
1270   left = 0;
1271   buf = sat_calloc(maxsize + 4, 1);
1272   dp = buf;
1273   for (i = 0; i < numsolv; i++, s++)
1274     {
1275       Id *keyp;
1276       if (data.error)
1277         break;
1278
1279       left -= (dp - buf);
1280       if (left < 0)
1281         {
1282           pool_debug(mypool, SAT_ERROR, "buffer overrun\n");
1283           data.error = SOLV_ERROR_EOF;
1284           break;
1285         }
1286       if (left)
1287         memmove(buf, dp, left);
1288       l = maxsize - left;
1289       if (l > allsize)
1290         l = allsize;
1291       if (l && fread(buf + left, l, 1, data.fp) != 1)
1292         {
1293           pool_debug(mypool, SAT_ERROR, "unexpected EOF\n");
1294           data.error = SOLV_ERROR_EOF;
1295           break;
1296         }
1297       allsize -= l;
1298       left += l;
1299       dp = buf;
1300
1301       dp = data_read_id_max(dp, &id, 0, numschemata, &data.error);
1302       if (have_xdata)
1303         {
1304           data.incoreoffset[i] = data.incoredatalen;
1305           incore_add_id(&data, id);
1306         }
1307       keyp = schemadata + schemata[id];
1308       while ((key = *keyp++) != 0)
1309         {
1310           if (data.error)
1311             break;
1312
1313           id = keys[key].name;
1314 #if 0
1315 fprintf(stderr, "solv %d name %d type %d class %d\n", i, id, keys[key].type, keys[key].storage);
1316 #endif
1317           if (keys[key].storage == KEY_STORAGE_VERTICAL_OFFSET)
1318             {
1319               /* copy offset/length into incore */
1320               dps = dp;
1321               dp = data_skip(dp, REPOKEY_TYPE_ID);
1322               dp = data_skip(dp, REPOKEY_TYPE_ID);
1323               incore_add_blob(&data, dps, dp - dps);
1324               continue;
1325             }
1326           switch (keys[key].type)
1327             {
1328             case REPOKEY_TYPE_ID:
1329               dp = data_read_id_max(dp, &did, idmap, numid + numrel, &data.error);
1330               if (id == SOLVABLE_NAME)
1331                 s->name = did;
1332               else if (id == SOLVABLE_ARCH)
1333                 s->arch = did;
1334               else if (id == SOLVABLE_EVR)
1335                 s->evr = did;
1336               else if (id == SOLVABLE_VENDOR)
1337                 s->vendor = did;
1338               else if (keys[key].storage == KEY_STORAGE_INCORE)
1339                 incore_add_id(&data, did);
1340 #if 0
1341               POOL_DEBUG(SAT_DEBUG_STATS, "%s -> %s\n", id2str(pool, id), id2str(pool, did));
1342 #endif
1343               break;
1344             case REPOKEY_TYPE_U32:
1345               dp = data_read_u32(dp, &h);
1346 #if 0
1347               POOL_DEBUG(SAT_DEBUG_STATS, "%s -> %u\n", id2str(pool, id), h);
1348 #endif
1349               if (id == RPM_RPMDBID)
1350                 {
1351                   if (!repo->rpmdbid)
1352                     repo->rpmdbid = sat_calloc(numsolv, sizeof(Id));
1353                   repo->rpmdbid[i] = h;
1354                 }
1355               else if (keys[key].storage == KEY_STORAGE_INCORE)
1356                 incore_add_u32(&data, h);
1357               break;
1358             case REPOKEY_TYPE_IDARRAY:
1359             case REPOKEY_TYPE_REL_IDARRAY:
1360               if (id < INTERESTED_START || id > INTERESTED_END)
1361                 {
1362                   dps = dp;
1363                   dp = data_skip(dp, REPOKEY_TYPE_IDARRAY);
1364                   if (keys[key].storage != KEY_STORAGE_INCORE)
1365                     break;
1366                   if (idmap)
1367                     incore_map_idarray(&data, dps, idmap, numid);
1368                   else
1369                     incore_add_blob(&data, dps, dp - dps);
1370                   break;
1371                 }
1372               ido = idarraydatap - repo->idarraydata;
1373               if (keys[key].type == REPOKEY_TYPE_IDARRAY)
1374                 dp = data_read_idarray(dp, &idarraydatap, idmap, numid + numrel, &data.error);
1375               else if (id == SOLVABLE_REQUIRES)
1376                 dp = data_read_rel_idarray(dp, &idarraydatap, idmap, numid + numrel, &data.error, SOLVABLE_PREREQMARKER);
1377               else if (id == SOLVABLE_PROVIDES)
1378                 dp = data_read_rel_idarray(dp, &idarraydatap, idmap, numid + numrel, &data.error, SOLVABLE_FILEMARKER);
1379               else
1380                 dp = data_read_rel_idarray(dp, &idarraydatap, idmap, numid + numrel, &data.error, 0);
1381               if (idarraydatap > idarraydataend)
1382                 {
1383                   pool_debug(pool, SAT_ERROR, "idarray overflow\n");
1384                   data.error = SOLV_ERROR_OVERFLOW;
1385                   break;
1386                 }
1387               if (id == SOLVABLE_PROVIDES)
1388                 s->provides = ido;
1389               else if (id == SOLVABLE_OBSOLETES)
1390                 s->obsoletes = ido;
1391               else if (id == SOLVABLE_CONFLICTS)
1392                 s->conflicts = ido;
1393               else if (id == SOLVABLE_REQUIRES)
1394                 s->requires = ido;
1395               else if (id == SOLVABLE_RECOMMENDS)
1396                 s->recommends= ido;
1397               else if (id == SOLVABLE_SUPPLEMENTS)
1398                 s->supplements = ido;
1399               else if (id == SOLVABLE_SUGGESTS)
1400                 s->suggests = ido;
1401               else if (id == SOLVABLE_ENHANCES)
1402                 s->enhances = ido;
1403               else if (id == SOLVABLE_FRESHENS)
1404                 s->freshens = ido;
1405 #if 0
1406               POOL_DEBUG(SAT_DEBUG_STATS, "%s ->\n", id2str(pool, id));
1407               for (; repo->idarraydata[ido]; ido++)
1408                 POOL_DEBUG(SAT_DEBUG_STATS,"  %s\n", dep2str(pool, repo->idarraydata[ido]));
1409 #endif
1410               break;
1411             default:
1412               dps = dp;
1413               dp = data_skip(dp, keys[key].type);
1414               if (keys[key].storage == KEY_STORAGE_INCORE)
1415                 incore_add_blob(&data, dps, dp - dps);
1416               break;
1417             }
1418         }
1419     }
1420
1421   /* should shrink idarraydata again */
1422
1423   if (!data.error)
1424     {
1425       left -= (dp - buf);
1426       if (left < 0)
1427         {
1428           pool_debug(mypool, SAT_ERROR, "buffer overrun\n");
1429           data.error = SOLV_ERROR_EOF;
1430         }
1431     }
1432   sat_free(buf);
1433
1434   if (data.error)
1435     {
1436       /* free solvables */
1437       repo_free_solvable_block(repo, data.start, data.end - data.start, 1);
1438       /* free id array */
1439       repo->idarraysize -= size_idarray;
1440       /* free incore data */
1441       data.incoredata = sat_free(data.incoredata);
1442       data.incoredatalen = data.incoredatafree = 0;
1443     }
1444
1445   if (data.incoredatafree)
1446     {
1447       /* shrink excess size */
1448       data.incoredata = sat_realloc(data.incoredata, data.incoredatalen);
1449       data.incoredatafree = 0;
1450     }
1451
1452   for (i = 1; i < numkeys; i++)
1453     if (keys[i].storage == KEY_STORAGE_VERTICAL_OFFSET)
1454       break;
1455   if (i < numkeys && !data.error)
1456     {
1457       Id fileoffset = 0;
1458       unsigned int pagesize;
1459       
1460       /* we have vertical data, make it available */
1461       data.verticaloffset = sat_calloc(numkeys, sizeof(Id));
1462       for (i = 1; i < numkeys; i++)
1463         if (keys[i].storage == KEY_STORAGE_VERTICAL_OFFSET)
1464           {
1465             data.verticaloffset[i] = fileoffset;
1466             fileoffset += keys[i].size;
1467           }
1468       data.lastverticaloffset = fileoffset;
1469       pagesize = read_u32(&data);
1470       repodata_read_or_setup_pages(&data, pagesize, fileoffset);
1471     }
1472   else
1473     {
1474       /* no longer needed */
1475       data.fp = 0;
1476     }
1477
1478   if (parent && !data.error)
1479     {
1480       /* we're a store */
1481       sat_free(parent->schemata);
1482       sat_free(parent->schemadata);
1483       sat_free(parent->keys);
1484       sat_free(parent->location);
1485       *parent = data;
1486     }
1487   else if ((data.incoredatalen || data.fp) && !data.error)
1488     {
1489       /* we got some data, make it available */
1490       repo->repodata = sat_realloc2(repo->repodata, repo->nrepodata + 1, sizeof(data));
1491       repo->repodata[repo->nrepodata++] = data;
1492     }
1493   else
1494     {
1495       /* discard data */
1496       sat_free(data.dirpool.dirs);
1497       sat_free(data.incoreoffset);
1498       sat_free(schemata);
1499       sat_free(schemadata);
1500       sat_free(keys);
1501     }
1502
1503   sat_free(idmap);
1504   mypool = 0;
1505   return data.error;
1506 }
1507
1508 int
1509 repo_add_solv(Repo *repo, FILE *fp)
1510 {
1511   return repo_add_solv_parent(repo, fp, 0);
1512 }
1513
1514 static void
1515 repodata_load_solv(Repodata *data)
1516 {
1517   FILE *fp;
1518   Pool *pool = data->repo->pool;
1519   if (!pool->loadcallback)
1520     {   
1521       data->state = REPODATA_ERROR;
1522       return;
1523     }   
1524   fp = pool->loadcallback(pool, data, pool->loadcallbackdata);
1525   if (!fp)
1526     {   
1527       data->state = REPODATA_ERROR;
1528       return;
1529     }   
1530   if (repo_add_solv_parent(data->repo, fp, data))
1531     data->state = REPODATA_ERROR;
1532   else
1533     data->state = REPODATA_AVAILABLE;
1534   fclose(fp);
1535 }