- kill stillborn KINDS_SEPARATELY, use getopt() in tools
[platform/upstream/libsolv.git] / ext / repo_susetags.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 #include <sys/types.h>
9 #include <limits.h>
10 #include <fcntl.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14
15 #include "pool.h"
16 #include "repo.h"
17 #include "hash.h"
18 #include "tools_util.h"
19 #include "repo_susetags.h"
20
21 struct parsedata {
22   char *kind;
23   Repo *repo;
24   Repodata *data;
25   int flags;
26   struct parsedata_common common;
27   int last_found_source;
28   char **share_with;
29   int nshare;
30   Id (*dirs)[3]; // dirid, size, nfiles
31   int ndirs;
32   Id langcache[ID_NUM_INTERNAL];
33   int lineno;
34 };
35
36 static char *flagtab[] = {
37   ">",
38   "=",
39   ">=",
40   "<",
41   "!=",
42   "<="
43 };
44
45
46 static Id
47 langtag(struct parsedata *pd, Id tag, const char *language)
48 {
49   if (language && !language[0])
50     language = 0;
51   if (!language || tag >= ID_NUM_INTERNAL)
52     return pool_id2langid(pd->repo->pool, tag, language, 1);
53   return pool_id2langid(pd->repo->pool, tag, language, 1);
54   if (!pd->langcache[tag])
55     pd->langcache[tag] = pool_id2langid(pd->repo->pool, tag, language, 1);
56   return pd->langcache[tag];
57 }
58
59 /*
60  * adddep
61  * create and add dependency
62  */
63
64 static unsigned int
65 adddep(Pool *pool, struct parsedata *pd, unsigned int olddeps, char *line, Id marker, char *kind)
66 {
67   int i, flags;
68   Id id, evrid;
69   char *sp[4];
70
71   if (line[6] == '/')
72     {
73       /* A file dependency. Do not try to parse it */
74       id = str2id(pool, line + 6, 1);
75     }
76   else
77     {
78       i = split(line + 6, sp, 4); /* name, <op>, evr, ? */
79       if (i != 1 && i != 3) /* expect either 'name' or 'name' <op> 'evr' */
80         {
81           pool_debug(pool, SAT_FATAL, "susetags: bad dependency line: %d: %s\n", pd->lineno, line);
82           exit(1);
83         }
84       if (kind)
85         id = str2id(pool, join2(kind, ":", sp[0]), 1);
86       else
87         id = str2id(pool, sp[0], 1);
88       if (i == 3)
89         {
90           evrid = makeevr(pool, sp[2]);
91           for (flags = 0; flags < 6; flags++)
92             if (!strcmp(sp[1], flagtab[flags]))
93               break;
94           if (flags == 6)
95             {
96               pool_debug(pool, SAT_FATAL, "susetags: unknown relation in %d: '%s'\n", pd->lineno, sp[1]);
97               exit(1);
98             }
99           id = rel2id(pool, id, evrid, flags + 1, 1);
100         }
101     }
102   return repo_addid_dep(pd->repo, olddeps, id, marker);
103 }
104
105
106 /*
107  * add_source
108  *
109  */
110
111 static void
112 add_source(struct parsedata *pd, char *line, Solvable *s, Id handle)
113 {
114   Repo *repo = s->repo;
115   Pool *pool = repo->pool;
116   char *sp[5];
117
118   if (split(line, sp, 5) != 4)
119     {
120       pool_debug(pool, SAT_FATAL, "susetags: bad source line: %d: %s\n", pd->lineno, line);
121       exit(1);
122     }
123
124   Id name = str2id(pool, sp[0], 1);
125   Id evr = makeevr(pool, join2(sp[1], "-", sp[2]));
126   Id arch = str2id(pool, sp[3], 1);
127   /* XXX: could record a dep here, depends on where we want to store the data */
128   if (name == s->name)
129     repodata_set_void(pd->data, handle, SOLVABLE_SOURCENAME);
130   else
131     repodata_set_id(pd->data, handle, SOLVABLE_SOURCENAME, name);
132   if (evr == s->evr)
133     repodata_set_void(pd->data, handle, SOLVABLE_SOURCEEVR);
134   else
135     repodata_set_id(pd->data, handle, SOLVABLE_SOURCEEVR, evr);
136   repodata_set_constantid(pd->data, handle, SOLVABLE_SOURCEARCH, arch);
137 }
138
139 /*
140  * add_dirline
141  * add a line with directory information
142  *
143  */
144
145 static void
146 add_dirline(struct parsedata *pd, char *line)
147 {
148   char *sp[6];
149   if (split(line, sp, 6) != 5)
150     return;
151   pd->dirs = sat_extend(pd->dirs, pd->ndirs, 1, sizeof(pd->dirs[0]), 31);
152   long filesz = strtol(sp[1], 0, 0);
153   filesz += strtol(sp[2], 0, 0);
154   long filenum = strtol(sp[3], 0, 0);
155   filenum += strtol(sp[4], 0, 0);
156   /* hack: we know that there's room for a / */
157   if (*sp[0] != '/')
158     *--sp[0] = '/';
159   unsigned dirid = repodata_str2dir(pd->data, sp[0], 1);
160 #if 0
161 fprintf(stderr, "%s -> %d\n", sp[0], dirid);
162 #endif
163   pd->dirs[pd->ndirs][0] = dirid;
164   pd->dirs[pd->ndirs][1] = filesz;
165   pd->dirs[pd->ndirs][2] = filenum;
166   pd->ndirs++;
167 }
168
169 static void
170 set_checksum(struct parsedata *pd, Repodata *data, Id handle, Id keyname, char *line)
171 {
172   char *sp[3];
173   int l;
174   Id type;
175   if (split(line, sp, 3) != 2)
176     {
177       pool_debug(pd->repo->pool, SAT_FATAL, "susetags: bad checksum line: %d: %s\n", pd->lineno, line);
178       exit(1);
179     }
180   if (!strcasecmp(sp[0], "sha1"))
181     l = SIZEOF_SHA1 * 2, type = REPOKEY_TYPE_SHA1;
182   else if (!strcasecmp(sp[0], "sha256"))
183     l = SIZEOF_SHA256 * 2, type = REPOKEY_TYPE_SHA256;
184   else if (!strcasecmp(sp[0], "md5"))
185     l = SIZEOF_MD5 * 2, type = REPOKEY_TYPE_MD5;
186   else
187     {
188       pool_debug(pd->repo->pool, SAT_FATAL, "susetags: unknown checksum type: %d: %s\n", pd->lineno, sp[0]);
189       exit(1);
190     }
191   if (strlen(sp[1]) != l)
192     {
193       pool_debug(pd->repo->pool, SAT_FATAL, "susetags: bad checksum length: %d: for %s: %s\n", pd->lineno, sp[0], sp[1]);
194       exit(1);
195     }
196   repodata_set_checksum(data, handle, keyname, type, sp[1]);
197 }
198
199 /*
200  * id3_cmp
201  * compare
202  *
203  */
204
205 static int
206 id3_cmp(const void *v1, const void *v2, void *dp)
207 {
208   Id *i1 = (Id*)v1;
209   Id *i2 = (Id*)v2;
210   return i1[0] - i2[0];
211 }
212
213
214 /*
215  * commit_diskusage
216  *
217  */
218
219 static void
220 commit_diskusage(struct parsedata *pd, Id handle)
221 {
222   unsigned i;
223   Dirpool *dp = &pd->data->dirpool;
224   /* Now sort in dirid order.  This ensures that parents come before
225      their children.  */
226   if (pd->ndirs > 1)
227     sat_sort(pd->dirs, pd->ndirs, sizeof(pd->dirs[0]), id3_cmp, 0);
228   /* Substract leaf numbers from all parents to make the numbers
229      non-cumulative.  This must be done post-order (i.e. all leafs
230      adjusted before parents).  We ensure this by starting at the end of
231      the array moving to the start, hence seeing leafs before parents.  */
232   for (i = pd->ndirs; i--;)
233     {
234       unsigned p = dirpool_parent(dp, pd->dirs[i][0]);
235       unsigned j = i;
236       for (; p; p = dirpool_parent(dp, p))
237         {
238           for (; j--;)
239             if (pd->dirs[j][0] == p)
240               break;
241           if (j < pd->ndirs)
242             {
243               if (pd->dirs[j][1] < pd->dirs[i][1])
244                 pd->dirs[j][1] = 0;
245               else
246                 pd->dirs[j][1] -= pd->dirs[i][1];
247               if (pd->dirs[j][2] < pd->dirs[i][2])
248                 pd->dirs[j][2] = 0;
249               else
250                 pd->dirs[j][2] -= pd->dirs[i][2];
251             }
252           else
253             /* Haven't found this parent in the list, look further if
254                we maybe find the parents parent.  */
255             j = i;
256         }
257     }
258 #if 0
259   char sbuf[1024];
260   char *buf = sbuf;
261   unsigned slen = sizeof(sbuf);
262   for (i = 0; i < pd->ndirs; i++)
263     {
264       dir2str(attr, pd->dirs[i][0], &buf, &slen);
265       fprintf(stderr, "have dir %d %d %d %s\n", pd->dirs[i][0], pd->dirs[i][1], pd->dirs[i][2], buf);
266     }
267   if (buf != sbuf)
268     free (buf);
269 #endif
270   for (i = 0; i < pd->ndirs; i++)
271     if (pd->dirs[i][1] || pd->dirs[i][2])
272       {
273         repodata_add_dirnumnum(pd->data, handle, SOLVABLE_DISKUSAGE, pd->dirs[i][0], pd->dirs[i][1], pd->dirs[i][2]);
274       }
275   pd->ndirs = 0;
276 }
277
278
279 /* Unfortunately "a"[0] is no constant expression in the C languages,
280    so we need to pass the four characters individually :-/  */
281 #define CTAG(a,b,c,d) ((unsigned)(((unsigned char)a) << 24) \
282  | ((unsigned char)b << 16) \
283  | ((unsigned char)c << 8) \
284  | ((unsigned char)d))
285
286 /*
287  * tag_from_string
288  *
289  */
290
291 static inline unsigned
292 tag_from_string(char *cs)
293 {
294   unsigned char *s = (unsigned char *)cs;
295   return ((s[0] << 24) | (s[1] << 16) | (s[2] << 8) | s[3]);
296 }
297
298
299 /*
300  * repo_add_susetags
301  * Parse susetags file passed in fp, fill solvables into repo
302  *
303  * susetags is key,value based
304  *  for short values
305  *    =key: value
306  *  is used
307  *  for long (multi-line) values,
308  *    +key:
309  *    value
310  *    value
311  *    -key:
312  *  is used
313  *
314  * See http://en.opensuse.org/Standards/YaST2_Repository_Metadata
315  * and http://en.opensuse.org/Standards/YaST2_Repository_Metadata/packages
316  * and http://en.opensuse.org/Standards/YaST2_Repository_Metadata/pattern
317  *
318  * Assumptions:
319  *   All keys have 3 characters and end in ':'
320  */
321
322 static void
323 finish_solvable(struct parsedata *pd, Solvable *s, Id handle, Offset freshens)
324 {
325   Pool *pool = pd->repo->pool;
326
327 #if 1
328   /* move file provides to filelist */
329   /* relies on the fact that rpm inserts self-provides at the end */
330   if (s->provides && (pd->flags & REPO_EXTEND_SOLVABLES) == 0)
331     {
332       Id *p, *lastreal, did;
333       const char *str, *sp;
334       lastreal = pd->repo->idarraydata + s->provides;
335       for (p = lastreal; *p; p++)
336         if (ISRELDEP(*p))
337           lastreal = p + 1;
338       for (p = lastreal; *p; p++)
339         {
340           str = id2str(pool, *p);
341           if (*str != '/')
342             lastreal = p + 1;
343         }
344       if (*lastreal)
345         {
346           for (p = lastreal; *p; p++)
347             {
348               char fname_buf[128];
349               const char *fname;
350               str = id2str(pool, *p);
351               sp = strrchr(str, '/');
352               /* Need to copy filename now, before we add string that could
353                  realloc the stringspace (and hence invalidate str).  */
354               fname = sp + 1;
355               if (strlen(fname) >= 128)
356                 fname = strdup(fname);
357               else
358                 {
359                   memcpy(fname_buf, fname, strlen(fname) + 1);
360                   fname = fname_buf;
361                 }
362               if (sp - str >= 128)
363                 {
364                   char *sdup = strdup(str);
365                   sdup[sp - str] = 0;
366                   did = repodata_str2dir(pd->data, sdup, 1);
367                   free(sdup);
368                 }
369               else
370                 {
371                   char sdup[128];
372                   strncpy(sdup, str, sp - str);
373                   sdup[sp - str] = 0;
374                   did = repodata_str2dir(pd->data, sdup, 1);
375                 }
376               if (!did)
377                 did = repodata_str2dir(pd->data, "/", 1);
378               repodata_add_dirstr(pd->data, handle, SOLVABLE_FILELIST, did, fname);
379               if (fname != fname_buf)
380                 free((char*)fname);
381               *p = 0;
382             }
383         }
384     }
385 #endif
386   /* A self provide, except for source packages.  This is harmless
387      to do twice (in case we see the same package twice).  */
388   if (s->name && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
389     s->provides = repo_addid_dep(pd->repo, s->provides,
390                 rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
391   /* XXX This uses repo_addid_dep internally, so should also be
392      harmless to do twice.  */
393   s->supplements = repo_fix_supplements(pd->repo, s->provides, s->supplements, freshens);
394   s->conflicts = repo_fix_conflicts(pd->repo, s->conflicts);
395   if (pd->ndirs)
396     commit_diskusage(pd, handle);
397 }
398
399 static Hashtable
400 joinhash_init(Repo *repo, Hashmask *hmp)
401 {
402   Hashmask hm = mkmask(repo->nsolvables);
403   Hashtable ht = sat_calloc(hm + 1, sizeof(*ht));
404   Hashval h, hh;
405   Solvable *s;
406   int i;
407
408   FOR_REPO_SOLVABLES(repo, i, s)
409     {
410       hh = HASHCHAIN_START;
411       h = s->name & hm;
412       while (ht[h])
413         h = HASHCHAIN_NEXT(h, hh, hm);
414       ht[h] = i;
415     }
416   *hmp = hm;
417   return ht;
418 }
419
420 static Solvable *
421 joinhash_lookup(Repo *repo, Hashtable ht, Hashmask hm, Id name, Id evr, Id arch)
422 {
423   Hashval h, hh;
424
425   if (!name || !arch || !evr)
426     return 0;
427   hh = HASHCHAIN_START;
428   h = name & hm;
429   while (ht[h])
430     {
431       Solvable *s = repo->pool->solvables + ht[h];
432       if (s->name == name && s->evr == evr && s->arch == arch)
433         return s;
434       h = HASHCHAIN_NEXT(h, hh, hm);
435     }
436   return 0;
437 }
438
439
440 /*
441  * parse susetags
442  *
443  * fp: file to read from
444  * defvendor: default vendor (0 if none)
445  * language: current language (0 if none)
446  * flags: flags
447  */
448
449 void
450 repo_add_susetags(Repo *repo, FILE *fp, Id defvendor, const char *language, int flags)
451 {
452   Pool *pool = repo->pool;
453   char *line, *linep;
454   int aline;
455   Solvable *s;
456   Offset freshens;
457   int intag = 0;
458   int cummulate = 0;
459   int indesc = 0;
460   int last_found_pack = 0;
461   char *sp[5];
462   struct parsedata pd;
463   Repodata *data = 0;
464   Id handle = 0;
465   Hashtable joinhash = 0;
466   Hashmask joinhashm = 0;
467   int createdpkgs = 0;
468
469   if ((flags & (SUSETAGS_EXTEND|REPO_EXTEND_SOLVABLES)) != 0 && repo->nrepodata)
470     {
471       joinhash = joinhash_init(repo, &joinhashm);
472       indesc = 1;
473     }
474
475   data = repo_add_repodata(repo, flags);
476
477   memset(&pd, 0, sizeof(pd));
478   line = malloc(1024);
479   aline = 1024;
480
481   pd.repo = pd.common.repo = repo;
482   pd.data = data;
483   pd.common.pool = pool;
484   pd.flags = flags;
485
486   linep = line;
487   s = 0;
488   freshens = 0;
489
490   /*
491    * read complete file
492    *
493    * collect values in 'struct parsedata pd'
494    * then build .solv (and .attr) file
495    */
496
497   for (;;)
498     {
499       unsigned tag;
500       char *olinep; /* old line pointer */
501       char line_lang[6];
502       int keylen = 3;
503       if (linep - line + 16 > aline)              /* (re-)alloc buffer */
504         {
505           aline = linep - line;
506           line = realloc(line, aline + 512);
507           linep = line + aline;
508           aline += 512;
509         }
510       if (!fgets(linep, aline - (linep - line), fp)) /* read line */
511         break;
512       olinep = linep;
513       linep += strlen(linep);
514       if (linep == line || linep[-1] != '\n')
515         continue;
516       pd.lineno++;
517       *--linep = 0;
518       if (linep == olinep)
519         continue;
520
521       if (intag)
522         {
523           /* check for multi-line value tags (+Key:/-Key:) */
524
525           int is_end = (linep[-intag - keylen + 1] == '-')
526                       && (linep[-1] == ':')
527                       && (linep == line + 1 + intag + 1 + 1 + 1 + intag + 1 || linep[-intag - keylen] == '\n');
528           if (is_end
529               && strncmp(linep - 1 - intag, line + 1, intag))
530             {
531               pool_debug(pool, SAT_ERROR, "susetags: Nonmatching multi-line tags: %d: '%s' '%s' %d\n", pd.lineno, linep - 1 - intag, line + 1, intag);
532             }
533           if (cummulate && !is_end)
534             {
535               *linep++ = '\n';
536               continue;
537             }
538           if (cummulate && is_end)
539             {
540               linep[-intag - keylen + 1] = 0;
541               if (linep[-intag - keylen] == '\n')
542                 linep[-intag - keylen] = 0;
543               linep = line;
544               intag = 0;
545             }
546           if (!cummulate && is_end)
547             {
548               intag = 0;
549               linep = line;
550               continue;
551             }
552           if (!cummulate && !is_end)
553             linep = line + intag + keylen;
554         }
555       else
556         linep = line;
557
558       if (!intag && line[0] == '+' && line[1] && line[1] != ':') /* start of +Key:/-Key: tag */
559         {
560           char *tagend = strchr(line, ':');
561           if (!tagend)
562             {
563               pool_debug(pool, SAT_FATAL, "susetags: bad line: %d: %s\n", pd.lineno, line);
564               exit(1);
565             }
566           intag = tagend - (line + 1);
567           cummulate = 0;
568           switch (tag_from_string(line))       /* check if accumulation is needed */
569             {
570               case CTAG('+', 'D', 'e', 's'):
571               case CTAG('+', 'E', 'u', 'l'):
572               case CTAG('+', 'I', 'n', 's'):
573               case CTAG('+', 'D', 'e', 'l'):
574               case CTAG('+', 'A', 'u', 't'):
575                 if (line[4] == ':')
576                   cummulate = 1;
577                 break;
578               default:
579                 break;
580             }
581           line[0] = '=';                       /* handle lines between +Key:/-Key: as =Key: */
582           line[intag + keylen - 1] = ' ';
583           linep = line + intag + keylen;
584           continue;
585         }
586       if (*line == '#' || !*line)
587         continue;
588       if (! (line[0] && line[1] && line[2] && line[3] && (line[4] == ':' || line[4] == '.')))
589         continue;
590       if (line[4] == '.')
591         {
592           char *endlang;
593           endlang = strchr(line + 5, ':');
594           if (endlang)
595             {
596               keylen = endlang - line - 1;
597               strncpy(line_lang, line + 5, 5);
598               line_lang[endlang - line - 5] = 0;
599             }
600         }
601       else
602         line_lang[0] = 0;
603       tag = tag_from_string(line);
604
605
606       /*
607        * start of (next) package or pattern
608        *
609        * =Pkg: <name> <version> <release> <architecture>
610        * (=Pat: ...)
611        */
612
613       if ((tag == CTAG('=', 'P', 'k', 'g')
614            || tag == CTAG('=', 'P', 'a', 't')))
615         {
616           /* If we have an old solvable, complete it by filling in some
617              default stuff.  */
618           if (s)
619             finish_solvable(&pd, s, handle, freshens);
620
621           /*
622            * define kind
623            */
624
625           pd.kind = 0;
626           if (line[3] == 't')
627             pd.kind = "pattern";
628
629           /*
630            * parse nevra
631            */
632
633           if (split(line + 5, sp, 5) != 4)
634             {
635               pool_debug(pool, SAT_FATAL, "susetags: bad line: %d: %s\n", pd.lineno, line);
636               exit(1);
637             }
638           s = 0;
639           freshens = 0;
640
641           if (joinhash)
642             {
643               /* data join operation. find solvable matching name/arch/evr and
644                * add data to it */
645               Id name, evr, arch;
646               /* we don't use the create flag here as a simple pre-check for existance */
647               if (pd.kind)
648                 name = str2id(pool, join2(pd.kind, ":", sp[0]), 0);
649               else
650                 name = str2id(pool, sp[0], 0);
651               evr = makeevr(pool, join2(sp[1], "-", sp[2]));
652               arch = str2id(pool, sp[3], 0);
653               if (name && arch)
654                 {
655                   if (repo->start + last_found_pack + 1 < repo->end)
656                     {
657                       s = pool->solvables + repo->start + last_found_pack + 1;
658                       if (s->repo != repo || s->name != name || s->evr != evr || s->arch != arch)
659                         s = 0;
660                     }
661                   if (!s)
662                     s = joinhash_lookup(repo, joinhash, joinhashm, name, evr, arch);
663                 }
664               if (!s && (flags & REPO_EXTEND_SOLVABLES) != 0)
665                 continue;
666               /* fallthrough to package creation */
667             }
668           if (!s)
669             {
670               /* normal operation. create a new solvable. */
671               s = pool_id2solvable(pool, repo_add_solvable(repo));
672               if (pd.kind)
673                 s->name = str2id(pool, join2(pd.kind, ":", sp[0]), 1);
674               else
675                 s->name = str2id(pool, sp[0], 1);
676               s->evr = makeevr(pool, join2(sp[1], "-", sp[2]));
677               s->arch = str2id(pool, sp[3], 1);
678               s->vendor = defvendor;
679               createdpkgs = 1;
680             }
681           last_found_pack = (s - pool->solvables) - repo->start;
682           if (data)
683             handle = s - pool->solvables;
684         }
685
686       /* If we have no current solvable to add to, ignore all further lines
687          for it.  Probably invalid input data in the second set of
688          solvables.  */
689       if (indesc >= 2 && !s)
690         {
691 #if 0
692           pool_debug(pool, SAT_ERROR, "susetags: huh %d: %s?\n", pd.lineno, line);
693 #endif
694           continue;
695         }
696       switch (tag)
697         {
698           case CTAG('=', 'P', 'r', 'v'):                                        /* provides */
699             s->provides = adddep(pool, &pd, s->provides, line, 0, pd.kind);
700             continue;
701           case CTAG('=', 'R', 'e', 'q'):                                        /* requires */
702             s->requires = adddep(pool, &pd, s->requires, line, -SOLVABLE_PREREQMARKER, pd.kind);
703             continue;
704           case CTAG('=', 'P', 'r', 'q'):                                        /* pre-requires / packages required */
705             if (pd.kind)
706               {
707                 s->requires = adddep(pool, &pd, s->requires, line, 0, 0);           /* patterns: a required package */
708               }
709             else
710               s->requires = adddep(pool, &pd, s->requires, line, SOLVABLE_PREREQMARKER, 0); /* package: pre-requires */
711             continue;
712           case CTAG('=', 'O', 'b', 's'):                                        /* obsoletes */
713             s->obsoletes = adddep(pool, &pd, s->obsoletes, line, 0, pd.kind);
714             continue;
715           case CTAG('=', 'C', 'o', 'n'):                                        /* conflicts */
716             s->conflicts = adddep(pool, &pd, s->conflicts, line, 0, pd.kind);
717             continue;
718           case CTAG('=', 'R', 'e', 'c'):                                        /* recommends */
719             s->recommends = adddep(pool, &pd, s->recommends, line, 0, pd.kind);
720             continue;
721           case CTAG('=', 'S', 'u', 'p'):                                        /* supplements */
722             s->supplements = adddep(pool, &pd, s->supplements, line, 0, pd.kind);
723             continue;
724           case CTAG('=', 'E', 'n', 'h'):                                        /* enhances */
725             s->enhances = adddep(pool, &pd, s->enhances, line, 0, pd.kind);
726             continue;
727           case CTAG('=', 'S', 'u', 'g'):                                        /* suggests */
728             s->suggests = adddep(pool, &pd, s->suggests, line, 0, pd.kind);
729             continue;
730           case CTAG('=', 'F', 'r', 'e'):                                        /* freshens */
731             freshens = adddep(pool, &pd, freshens, line, 0, pd.kind);
732             continue;
733           case CTAG('=', 'P', 'r', 'c'):                                        /* packages recommended */
734             s->recommends = adddep(pool, &pd, s->recommends, line, 0, 0);
735             continue;
736           case CTAG('=', 'P', 's', 'g'):                                        /* packages suggested */
737             s->suggests = adddep(pool, &pd, s->suggests, line, 0, 0);
738             continue;
739           case CTAG('=', 'P', 'c', 'n'):                                        /* pattern: package conflicts */
740             s->conflicts = adddep(pool, &pd, s->conflicts, line, 0, 0);
741             continue;
742           case CTAG('=', 'P', 'o', 'b'):                                        /* pattern: package obsoletes */
743             s->obsoletes = adddep(pool, &pd, s->obsoletes, line, 0, 0);
744             continue;
745           case CTAG('=', 'P', 'f', 'r'):                                        /* pattern: package freshens */
746             freshens = adddep(pool, &pd, freshens, line, 0, 0);
747             continue;
748           case CTAG('=', 'P', 's', 'p'):                                        /* pattern: package supplements */
749             s->supplements = adddep(pool, &pd, s->supplements, line, 0, 0);
750             continue;
751           case CTAG('=', 'P', 'e', 'n'):                                        /* pattern: package enhances */
752             s->enhances = adddep(pool, &pd, s->enhances, line, 0, 0);
753             continue;
754           case CTAG('=', 'V', 'e', 'r'):                                        /* - version - */
755             last_found_pack = 0;
756             handle = 0;
757             indesc++;
758             if (createdpkgs)
759               {
760                 sat_free(joinhash);
761                 joinhash = joinhash_init(repo, &joinhashm);
762                 createdpkgs = 0;
763               }
764             continue;
765           case CTAG('=', 'V', 'n', 'd'):                                        /* vendor */
766             s->vendor = str2id(pool, line + 6, 1);
767             continue;
768
769         /* From here it's the attribute tags.  */
770           case CTAG('=', 'G', 'r', 'p'):
771             repodata_set_poolstr(data, handle, SOLVABLE_GROUP, line + 6);
772             continue;
773           case CTAG('=', 'L', 'i', 'c'):
774             repodata_set_poolstr(data, handle, SOLVABLE_LICENSE, line + 6);
775             continue;
776           case CTAG('=', 'L', 'o', 'c'):
777             {
778               int i = split(line + 6, sp, 3);
779               if (i != 2 && i != 3)
780                 {
781                   pool_debug(pool, SAT_FATAL, "susetags: bad location line: %d: %s\n", pd.lineno, line);
782                   exit(1);
783                 }
784               repodata_set_location(data, handle, atoi(sp[0]), i == 3 ? sp[2] : id2str(pool, s->arch), sp[1]);
785             }
786             continue;
787           case CTAG('=', 'S', 'r', 'c'):
788             add_source(&pd, line + 6, s, handle);
789             continue;
790           case CTAG('=', 'S', 'i', 'z'):
791             if (split(line + 6, sp, 3) == 2)
792               {
793                 repodata_set_num(data, handle, SOLVABLE_DOWNLOADSIZE, (unsigned int)(atoi(sp[0]) + 1023) / 1024);
794                 repodata_set_num(data, handle, SOLVABLE_INSTALLSIZE, (unsigned int)(atoi(sp[1]) + 1023) / 1024);
795               }
796             continue;
797           case CTAG('=', 'T', 'i', 'm'):
798             {
799               unsigned int t = atoi(line + 6);
800               if (t)
801                 repodata_set_num(data, handle, SOLVABLE_BUILDTIME, t);
802             }
803             continue;
804           case CTAG('=', 'K', 'w', 'd'):
805             repodata_add_poolstr_array(data, handle, SOLVABLE_KEYWORDS, line + 6);
806             continue;
807           case CTAG('=', 'A', 'u', 't'):
808             repodata_set_str(data, handle, SOLVABLE_AUTHORS, line + 6);
809             continue;
810           case CTAG('=', 'S', 'u', 'm'):
811             repodata_set_str(data, handle, langtag(&pd, SOLVABLE_SUMMARY, language ? language : line_lang), line + 3 + keylen );
812             continue;
813           case CTAG('=', 'D', 'e', 's'):
814             repodata_set_str(data, handle, langtag(&pd, SOLVABLE_DESCRIPTION, language ? language : line_lang), line + 3 + keylen );
815             continue;
816           case CTAG('=', 'E', 'u', 'l'):
817             repodata_set_str(data, handle, langtag(&pd, SOLVABLE_EULA, language), line + 6);
818             continue;
819           case CTAG('=', 'I', 'n', 's'):
820             repodata_set_str(data, handle, langtag(&pd, SOLVABLE_MESSAGEINS, language), line + 6);
821             continue;
822           case CTAG('=', 'D', 'e', 'l'):
823             repodata_set_str(data, handle, langtag(&pd, SOLVABLE_MESSAGEDEL, language), line + 6);
824             continue;
825           case CTAG('=', 'V', 'i', 's'):
826             {
827               /* Accept numbers and textual bools.  */
828               unsigned k;
829               k = atoi(line + 6);
830               if (k || !strcasecmp(line + 6, "true"))
831                 repodata_set_void(data, handle, SOLVABLE_ISVISIBLE );
832             }
833             continue;
834           case CTAG('=', 'S', 'h', 'r'):
835             if (last_found_pack >= pd.nshare)
836               {
837                 pd.share_with = sat_realloc2(pd.share_with, last_found_pack + 256, sizeof(*pd.share_with));
838                 memset(pd.share_with + pd.nshare, 0, (last_found_pack + 256 - pd.nshare) * sizeof(*pd.share_with));
839                 pd.nshare = last_found_pack + 256;
840               }
841             pd.share_with[last_found_pack] = strdup(line + 6);
842             continue;
843           case CTAG('=', 'D', 'i', 'r'):
844             add_dirline(&pd, line + 6);
845             continue;
846           case CTAG('=', 'C', 'a', 't'):
847             repodata_set_poolstr(data, handle, langtag(&pd, SOLVABLE_CATEGORY, line_lang), line + 3 + keylen);
848             break;
849           case CTAG('=', 'O', 'r', 'd'):
850             /* Order is a string not a number, so we can retroactively insert
851                new patterns in the middle, i.e. 1 < 15 < 2.  */
852             repodata_set_str(data, handle, SOLVABLE_ORDER, line + 6);
853             break;
854           case CTAG('=', 'I', 'c', 'o'):
855             repodata_set_str(data, handle, SOLVABLE_ICON, line + 6);
856             break;
857           case CTAG('=', 'E', 'x', 't'):
858             repodata_add_poolstr_array(data, handle, SOLVABLE_EXTENDS, join2("pattern", ":", line + 6));
859             break;
860           case CTAG('=', 'I', 'n', 'c'):
861             repodata_add_poolstr_array(data, handle, SOLVABLE_INCLUDES, join2("pattern", ":", line + 6));
862             break;
863           case CTAG('=', 'C', 'k', 's'):
864             set_checksum(&pd, data, handle, SOLVABLE_CHECKSUM, line + 6);
865             break;
866           case CTAG('=', 'L', 'a', 'n'):
867             language = strdup(line + 6);
868             break;
869
870           case CTAG('=', 'F', 'l', 's'):
871             {
872               char *p = strrchr(line + 6, '/');
873               Id did;
874               if (p && p != line + 6 && !p[1])
875                 {
876                   *p = 0;
877                   p = strrchr(line + 6, '/');
878                 }
879               if (p)
880                 {
881                   *p++ = 0;
882                   did = repodata_str2dir(data, line + 6, 1);
883                 }
884               else
885                 {
886                   p = line + 6;
887                   did = 0;
888                 }
889               if (!did)
890                 did = repodata_str2dir(data, "/", 1);
891               repodata_add_dirstr(data, handle, SOLVABLE_FILELIST, did, p);
892               break;
893             }
894           case CTAG('=', 'H', 'd', 'r'):
895             /* rpm header range */
896             if (split(line + 6, sp, 3) == 2)
897               {
898                 /* we ignore the start value */
899                 unsigned int end = (unsigned int)atoi(sp[1]);
900                 if (end)
901                   repodata_set_num(data, handle, SOLVABLE_HEADEREND, end);
902               }
903             break;
904
905           case CTAG('=', 'P', 'a', 't'):
906           case CTAG('=', 'P', 'k', 'g'):
907             break;
908
909           default:
910             pool_debug(pool, SAT_ERROR, "susetags: unknown line: %d: %s\n", pd.lineno, line);
911             break;
912         }
913
914     } /* for(;;) */
915
916   if (s)
917     finish_solvable(&pd, s, handle, freshens);
918
919   /* Shared attributes
920    *  (e.g. multiple binaries built from same source)
921    */
922   if (pd.nshare)
923     {
924       int i, last_found;
925       last_found = 0;
926       Map keyidmap;
927
928       map_init(&keyidmap, data->nkeys);
929       for (i = 1; i < data->nkeys; i++)
930         {
931           Id keyname = data->keys[i].name;
932           if (keyname == SOLVABLE_INSTALLSIZE || keyname == SOLVABLE_DISKUSAGE || keyname == SOLVABLE_FILELIST)
933             continue;
934           if (keyname == SOLVABLE_MEDIADIR || keyname == SOLVABLE_MEDIAFILE || keyname == SOLVABLE_MEDIANR)
935             continue;
936           if (keyname == SOLVABLE_DOWNLOADSIZE || keyname == SOLVABLE_CHECKSUM)
937             continue;
938           if (keyname == SOLVABLE_SOURCENAME || keyname == SOLVABLE_SOURCEARCH || keyname == SOLVABLE_SOURCEEVR)
939             continue;
940           if (keyname == SOLVABLE_PKGID || keyname == SOLVABLE_HDRID || keyname == SOLVABLE_LEADSIGID)
941             continue;
942           MAPSET(&keyidmap, i);
943         }
944       for (i = 0; i < pd.nshare; i++)
945         if (pd.share_with[i])
946           {
947             if (split(pd.share_with[i], sp, 5) != 4)
948               {
949                 pool_debug(pool, SAT_FATAL, "susetags: bad =Shr line: %s\n", pd.share_with[i]);
950                 exit(1);
951               }
952
953             Id name = str2id(pool, sp[0], 1);
954             Id evr = makeevr(pool, join2(sp[1], "-", sp[2]));
955             Id arch = str2id(pool, sp[3], 1);
956             unsigned n, nn;
957             Solvable *found = 0;
958             for (n = repo->start, nn = repo->start + last_found;
959                  n < repo->end; n++, nn++)
960               {
961                 if (nn >= repo->end)
962                   nn = repo->start;
963                 found = pool->solvables + nn;
964                 if (found->repo == repo
965                     && found->name == name
966                     && found->evr == evr
967                     && found->arch == arch)
968                   {
969                     last_found = nn - repo->start;
970                     break;
971                   }
972               }
973             if (n != repo->end)
974               repodata_merge_some_attrs(data, repo->start + i, repo->start + last_found, &keyidmap, 0);
975             free(pd.share_with[i]);
976           }
977       free(pd.share_with);
978       map_free(&keyidmap);
979     }
980
981   sat_free(joinhash);
982   if (!(flags & REPO_NO_INTERNALIZE))
983     repodata_internalize(data);
984
985   if (pd.common.tmp)
986     free(pd.common.tmp);
987   free(line);
988   join_freemem();
989 }