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