- fix support for splitprovides
[platform/upstream/libsolv.git] / src / pool.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  * pool.c
10  * 
11  * The pool contains information about solvables
12  * stored optimized for memory consumption and fast retrieval.
13  */
14
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <stdarg.h>
18 #include <unistd.h>
19 #include <string.h>
20
21 #include "pool.h"
22 #include "repo.h"
23 #include "poolid.h"
24 #include "poolid_private.h"
25 #include "poolarch.h"
26 #include "util.h"
27 #include "bitmap.h"
28 #include "evr.h"
29
30 #define SOLVABLE_BLOCK  255
31
32
33 // list of string constants, so we can do pointer/Id instead of string comparison
34 // index into array matches ID_xxx constants in pool.h
35
36 static const char *initpool_data[] = {
37   "<NULL>",                   // ID_NULL
38   "",                         // ID_EMPTY
39   "solvable:name",
40   "solvable:arch",
41   "solvable:evr",
42   "solvable:vendor",
43   "solvable:provides",
44   "solvable:obsoletes",
45   "solvable:conflicts",
46   "solvable:requires",
47   "solvable:recommends",
48   "solvable:suggests",
49   "solvable:supplements",
50   "solvable:enhances",
51   "solvable:freshens",
52   "rpm:dbid",                          /* direct key into rpmdb */
53   "solvable:prereqmarker",
54   "solvable:filemarker",
55   "namespace:installed",
56   "namespace:modalias",
57   "namespace:splitprovides",
58   "system:system",
59   "src",
60   "nosrc",
61   "noarch",
62   "repodata:external",
63   "repodata:keys",
64   "repodata:location",
65   0
66 };
67
68 /* create pool */
69 Pool *
70 pool_create(void)
71 {
72   Pool *pool;
73   Solvable *s;
74
75   pool = (Pool *)sat_calloc(1, sizeof(*pool));
76
77   stringpool_init (&pool->ss, initpool_data);
78
79   // pre-alloc space for a RelDep
80   pool->rels = (Reldep *)sat_calloc(1 + REL_BLOCK, sizeof(Reldep));
81   pool->nrels = 1;
82
83   // pre-alloc space for a Solvable
84   pool->solvables = (Solvable *)sat_calloc(SOLVABLE_BLOCK + 1, sizeof(Solvable));
85   pool->nsolvables = 2;
86   queue_init(&pool->vendormap);
87   s = pool->solvables + SYSTEMSOLVABLE;
88   s->name = SYSTEM_SYSTEM;
89   s->arch = ARCH_NOARCH;
90   s->evr = ID_EMPTY;
91
92   pool->debugmask = SAT_DEBUG_RESULT;   /* FIXME */
93   return pool;
94 }
95
96
97 /* free all the resources of our pool */
98 void
99 pool_free(Pool *pool)
100 {
101   int i;
102
103   pool_freewhatprovides(pool);
104   pool_freeidhashes(pool);
105   repo_freeallrepos(pool, 1);
106   sat_free(pool->id2arch);
107   sat_free(pool->solvables);
108   sat_free(pool->ss.stringspace);
109   sat_free(pool->ss.strings);
110   sat_free(pool->rels);
111   queue_free(&pool->vendormap);
112   for (i = 0; i < DEP2STRBUF; i++)
113     sat_free(pool->dep2strbuf[i]);
114   sat_free(pool);
115 }
116
117 Id
118 pool_add_solvable(Pool *pool)
119 {
120   if ((pool->nsolvables & SOLVABLE_BLOCK) == 0)
121     pool->solvables = sat_realloc2(pool->solvables, pool->nsolvables + (SOLVABLE_BLOCK + 1), sizeof(Solvable));
122   memset(pool->solvables + pool->nsolvables, 0, sizeof(Solvable));
123   return pool->nsolvables++;
124 }
125
126 Id
127 pool_add_solvable_block(Pool *pool, int count)
128 {
129   Id nsolvables = pool->nsolvables;
130   if (!count)
131     return nsolvables;
132   if (((nsolvables - 1) | SOLVABLE_BLOCK) != ((nsolvables + count - 1) | SOLVABLE_BLOCK))
133     pool->solvables = sat_realloc2(pool->solvables, (nsolvables + count + SOLVABLE_BLOCK) & ~SOLVABLE_BLOCK, sizeof(Solvable));
134   memset(pool->solvables + nsolvables, 0, sizeof(Solvable) * count);
135   pool->nsolvables += count;
136   return nsolvables;
137 }
138
139 void
140 pool_free_solvable_block(Pool *pool, Id start, int count, int reuseids)
141 {
142   if (!count)
143     return;
144   if (reuseids && start + count == pool->nsolvables)
145     {
146       /* might want to shrink solvable array */
147       pool->nsolvables = start;
148       return;
149     }
150   memset(pool->solvables + start, 0, sizeof(Solvable) * count);
151 }
152
153
154 const char *
155 solvable2str(Pool *pool, Solvable *s)
156 {
157   int l, nn = pool->dep2strn;
158   const char *n, *e, *a;
159   n = id2str(pool, s->name);
160   e = id2str(pool, s->evr);
161   a = id2str(pool, s->arch);
162   l = strlen(n) + strlen(e) + strlen(a) + 3;
163   if (l > pool->dep2strlen[nn])
164     {
165       pool->dep2strbuf[nn] = sat_realloc(pool->dep2strbuf[nn], l + 32);
166       pool->dep2strlen[nn] = l + 32;
167     }
168   sprintf(pool->dep2strbuf[nn], "%s-%s.%s", n, e, a);
169   pool->dep2strn = (nn + 1) % DEP2STRBUF;
170   return pool->dep2strbuf[nn];
171 }
172
173 static Pool *pool_shrink_whatprovides_sortcmp_data;
174
175 static int
176 pool_shrink_whatprovides_sortcmp(const void *ap, const void *bp)
177 {
178   int r;
179   Pool *pool = pool_shrink_whatprovides_sortcmp_data;
180   Id oa, ob, *da, *db;
181   oa = pool->whatprovides[*(Id *)ap];
182   ob = pool->whatprovides[*(Id *)bp];
183   if (oa == ob)
184     return *(Id *)ap - *(Id *)bp;
185   if (!oa)
186     return -1;
187   if (!ob)
188     return 1;
189   da = pool->whatprovidesdata + oa;
190   db = pool->whatprovidesdata + ob;
191   while (*db)
192     if ((r = (*da++ - *db++)) != 0)
193       return r;
194   if (*da)
195     return *da;
196   return *(Id *)ap - *(Id *)bp;
197 }
198
199 /*
200  * pool_shrink_whatprovides  - unify whatprovides data
201  *
202  * whatprovides_rel must be empty for this to work!
203  *
204  */
205 static void
206 pool_shrink_whatprovides(Pool *pool)
207 {
208   Id i, id;
209   Id *sorted;
210   Id lastid, *last, *dp, *lp;
211   Offset o;
212   int r;
213
214   if (pool->ss.nstrings < 3)
215     return;
216   sorted = sat_malloc2(pool->ss.nstrings, sizeof(Id));
217   for (id = 0; id < pool->ss.nstrings; id++)
218     sorted[id] = id;
219   pool_shrink_whatprovides_sortcmp_data = pool;
220   qsort(sorted + 1, pool->ss.nstrings - 1, sizeof(Id), pool_shrink_whatprovides_sortcmp);
221   last = 0;
222   lastid = 0;
223   for (i = 1; i < pool->ss.nstrings; i++)
224     {
225       id = sorted[i];
226       o = pool->whatprovides[id];
227       if (o == 0 || o == 1)
228         continue;
229       dp = pool->whatprovidesdata + o;
230       if (last)
231         {
232           lp = last;
233           while (*dp)   
234             if (*dp++ != *lp++)
235               {
236                 last = 0;
237                 break;
238               }
239           if (last && *lp)
240             last = 0;
241           if (last)
242             {
243               pool->whatprovides[id] = -lastid;
244               continue;
245             }
246         }
247       last = pool->whatprovidesdata + o;
248       lastid = id;
249     }
250   sat_free(sorted);
251   dp = pool->whatprovidesdata + 2;
252   for (id = 1; id < pool->ss.nstrings; id++)
253     {
254       o = pool->whatprovides[id];
255       if (o == 0 || o == 1)
256         continue;
257       if ((Id)o < 0)
258         {
259           i = -(Id)o;
260           if (i >= id)
261             abort();
262           pool->whatprovides[id] = pool->whatprovides[i];
263           continue;
264         }
265       lp = pool->whatprovidesdata + o;
266       if (lp < dp)
267         abort();
268       pool->whatprovides[id] = dp - pool->whatprovidesdata;
269       while ((*dp++ = *lp++) != 0)
270         ;
271     }
272   o = dp - pool->whatprovidesdata;
273   POOL_DEBUG(SAT_DEBUG_STATS, "shrunk whatprovidesdata from %d to %d\n", pool->whatprovidesdataoff, o);
274   if (pool->whatprovidesdataoff == o)
275     return;
276   r = pool->whatprovidesdataoff - o;
277   pool->whatprovidesdataoff = o;
278   pool->whatprovidesdata = sat_realloc(pool->whatprovidesdata, (o + pool->whatprovidesdataleft) * sizeof(Id));
279   if (r > pool->whatprovidesdataleft)
280     r = pool->whatprovidesdataleft;
281   memset(pool->whatprovidesdata + o, 0, r * sizeof(Id));
282 }
283
284
285 /*
286  * pool_createwhatprovides()
287  * 
288  * create hashes over pool of solvables to ease provide lookups
289  * 
290  */
291 void
292 pool_createwhatprovides(Pool *pool)
293 {
294   int i, num, np, extra;
295   Offset off;
296   Solvable *s;
297   Id id;
298   Offset *idp, n;
299   Offset *whatprovides;
300   Id *whatprovidesdata, *d;
301
302   POOL_DEBUG(SAT_DEBUG_STATS, "number of solvables: %d\n", pool->nsolvables);
303   POOL_DEBUG(SAT_DEBUG_STATS, "number of ids: %d + %d\n", pool->ss.nstrings, pool->nrels);
304
305   pool_freeidhashes(pool);      /* XXX: should not be here! */
306   pool_freewhatprovides(pool);
307   num = pool->ss.nstrings;
308   pool->whatprovides = whatprovides = sat_calloc((num + WHATPROVIDES_BLOCK) & ~WHATPROVIDES_BLOCK, sizeof(Offset));
309   pool->whatprovides_rel = sat_calloc((pool->nrels + WHATPROVIDES_BLOCK) & ~WHATPROVIDES_BLOCK, sizeof(Offset));
310
311   /* count providers for each name */
312   for (i = 1; i < pool->nsolvables; i++)
313     {
314       Id *pp;
315       s = pool->solvables + i;
316       if (!s->provides)
317         continue;
318       if (!pool_installable(pool, s))
319         continue;
320       pp = s->repo->idarraydata + s->provides;
321       while ((id = *pp++) != ID_NULL)
322         {
323           while (ISRELDEP(id))
324             {
325               Reldep *rd = GETRELDEP(pool, id);
326               id = rd->name;
327             }
328           whatprovides[id]++;          /* inc count of providers */
329         }
330     }
331
332   off = 2;      /* first entry is undef, second is empty list */
333   idp = whatprovides;
334   np = 0;                              /* number of names provided */
335   for (i = 0; i < num; i++, idp++)
336     {
337       n = *idp;
338       if (!n)                          /* no providers */
339         continue;
340       *idp = off;                      /* move from counts to offsets into whatprovidesdata */
341       off += n + 1;                    /* make space for all providers + terminating ID_NULL */
342       np++;                            /* inc # of provider 'slots' */
343     }
344
345   POOL_DEBUG(SAT_DEBUG_STATS, "provide ids: %d\n", np);
346
347   /* reserve some space for relation data */
348   extra = 2 * pool->nrels;
349   if (extra < 256)
350     extra = 256;
351
352   POOL_DEBUG(SAT_DEBUG_STATS, "provide space needed: %d + %d\n", off, extra);
353
354   /* alloc space for all providers + extra */
355   whatprovidesdata = sat_calloc(off + extra, sizeof(Id));
356
357   /* now fill data for all provides */
358   for (i = 1; i < pool->nsolvables; i++)
359     {
360       Id *pp;
361       s = pool->solvables + i;
362       if (!s->provides)
363         continue;
364       if (!pool_installable(pool, s))
365         continue;
366
367       /* for all provides of this solvable */
368       pp = s->repo->idarraydata + s->provides;
369       while ((id = *pp++) != 0)
370         {
371           while (ISRELDEP(id))
372             {
373               Reldep *rd = GETRELDEP(pool, id);
374               id = rd->name;
375             }
376           d = whatprovidesdata + whatprovides[id];   /* offset into whatprovidesdata */
377           if (*d)
378             {
379               d++;
380               while (*d)               /* find free slot */
381                 d++;
382               if (d[-1] == i)
383                 continue;
384             }
385           *d = i;                      /* put solvable Id into data */
386         }
387     }
388   pool->whatprovidesdata = whatprovidesdata;
389   pool->whatprovidesdataoff = off;
390   pool->whatprovidesdataleft = extra;
391   pool_shrink_whatprovides(pool);
392 }
393
394 /*
395  * free all of our whatprovides data
396  * be careful, everything internalized with pool_queuetowhatprovides is gone, too
397  */
398 void
399 pool_freewhatprovides(Pool *pool)
400 {
401   pool->whatprovides = sat_free(pool->whatprovides);
402   pool->whatprovides_rel = sat_free(pool->whatprovides_rel);
403   pool->whatprovidesdata = sat_free(pool->whatprovidesdata);
404   pool->whatprovidesdataoff = 0;
405   pool->whatprovidesdataleft = 0;
406 }
407
408
409 /******************************************************************************/
410
411 /*
412  * pool_queuetowhatprovides  - add queue contents to whatprovidesdata
413  * 
414  * on-demand filling of provider information
415  * move queue data into whatprovidesdata
416  * q: queue of Ids
417  * returns: Offset into whatprovides
418  *
419  */
420 Id
421 pool_queuetowhatprovides(Pool *pool, Queue *q)
422 {
423   Offset off;
424   int count = q->count;
425
426   if (count == 0)                      /* queue empty -> ID_EMPTY */
427     return ID_EMPTY;
428
429   /* extend whatprovidesdata if needed, +1 for ID_NULL-termination */
430   if (pool->whatprovidesdataleft < count + 1)
431     {
432       POOL_DEBUG(SAT_DEBUG_STATS, "growing provides hash data...\n");
433       pool->whatprovidesdata = sat_realloc(pool->whatprovidesdata, (pool->whatprovidesdataoff + count + 4096) * sizeof(Id));
434       pool->whatprovidesdataleft = count + 4096;
435     }
436
437   /* copy queue to next free slot */
438   off = pool->whatprovidesdataoff;
439   memcpy(pool->whatprovidesdata + pool->whatprovidesdataoff, q->elements, count * sizeof(Id));
440
441   /* adapt count and ID_NULL-terminate */
442   pool->whatprovidesdataoff += count;
443   pool->whatprovidesdata[pool->whatprovidesdataoff++] = ID_NULL;
444   pool->whatprovidesdataleft -= count + 1;
445
446   return (Id)off;
447 }
448
449
450 /*************************************************************************/
451
452 /*
453  * addrelproviders
454  * 
455  * add packages fulfilling the relation to whatprovides array
456  * no exact providers, do range match
457  * 
458  */
459
460 Id *
461 pool_addrelproviders(Pool *pool, Id d)
462 {
463   Reldep *rd = GETRELDEP(pool, d);
464   Reldep *prd;
465   Queue plist;
466   Id buf[16];
467   Id name = rd->name;
468   Id evr = rd->evr;
469   int flags = rd->flags;
470   Id pid, *pidp;
471   Id p, *pp, *pp2, *pp3;
472
473   d = GETRELID(d);
474   queue_init_buffer(&plist, buf, sizeof(buf)/sizeof(*buf));
475   switch (flags)
476     {
477     case REL_AND:
478     case REL_WITH:
479       pp = pool_whatprovides(pool, name);
480       pp2 = pool_whatprovides(pool, evr);
481       while ((p = *pp++) != 0)
482         {
483           for (pp3 = pp2; *pp3;)
484             if (*pp3++ == p)
485               {
486                 queue_push(&plist, p);
487                 break;
488               }
489         }
490       break;
491     case REL_OR:
492       pp = pool_whatprovides(pool, name);
493       while ((p = *pp++) != 0)
494         queue_push(&plist, p);
495       pp = pool_whatprovides(pool, evr);
496       while ((p = *pp++) != 0)
497         queue_pushunique(&plist, p);
498       break;
499     case REL_NAMESPACE:
500       if (pool->nscallback)
501         {
502           p = pool->nscallback(pool, pool->nscallbackdata, name, evr);
503           if (p > 1)
504             {
505               queue_free(&plist);
506               pool->whatprovides_rel[d] = p;
507               return pool->whatprovidesdata + p;
508             }
509           if (p == 1)
510             queue_push(&plist, SYSTEMSOLVABLE);
511         }
512       break;
513     default:
514       break;
515     }
516
517   /* convert to whatprovides id */
518 #if 0
519   POOL_DEBUG(DEBUG_1, "addrelproviders: what provides %s?\n", id2str(pool, name));
520 #endif
521   if (flags && flags < 8)
522     {
523       FOR_PROVIDES(p, pp, name)
524         {
525 #if 0
526           POOL_DEBUG(DEBUG_1, "addrelproviders: checking package %s\n", id2str(pool, pool->p[p].name));
527 #endif
528           /* solvable p provides name in some rels */
529           pidp = pool->solvables[p].repo->idarraydata + pool->solvables[p].provides;
530           while ((pid = *pidp++) != 0)
531             {
532               int pflags;
533               Id pevr;
534
535               if (pid == name)
536                 {
537 #ifdef DEBIAN_SEMANTICS
538                   continue;             /* unversioned provides can
539                                          * never match versioned deps */
540 #else
541                   break;                /* yes, provides all versions */
542 #endif
543                 }
544               if (!ISRELDEP(pid))
545                 continue;               /* wrong provides name */
546               prd = GETRELDEP(pool, pid);
547               if (prd->name != name)
548                 continue;               /* wrong provides name */
549               /* right package, both deps are rels */
550               pflags = prd->flags;
551               if (!pflags)
552                 continue;
553               if (flags == 7 || pflags == 7)
554                 break; /* included */
555               if ((pflags & flags & 5) != 0)
556                 break; /* same direction, match */
557               pevr = prd->evr;
558               if (pevr == evr)
559                 {
560                   if ((pflags & flags & 2) != 0)
561                     break; /* both have =, match */
562                 }
563               else
564                 {
565                   int f = flags == 5 ? 5 : flags == 2 ? pflags : (flags ^ 5) & (pflags | 5);
566                   if ((f & (1 << (1 + evrcmp(pool, pevr, evr, EVRCMP_MATCH_RELEASE)))) != 0)
567                     break;
568                 }
569             }
570           if (!pid)
571             continue;   /* no rel match */
572           queue_push(&plist, p);
573         }
574       /* make our system solvable provide all unknown rpmlib() stuff */
575       if (plist.count == 0 && !strncmp(id2str(pool, name), "rpmlib(", 7))
576         queue_push(&plist, SYSTEMSOLVABLE);
577     }
578   /* add providers to whatprovides */
579 #if 0
580   POOL_DEBUG(DEBUG_1, "addrelproviders: adding %d packages to %d\n", plist.count, d);
581 #endif
582   pool->whatprovides_rel[d] = pool_queuetowhatprovides(pool, &plist);
583   queue_free(&plist);
584
585   return pool->whatprovidesdata + pool->whatprovides_rel[d];
586 }
587
588 /*************************************************************************/
589
590 void
591 pool_debug(Pool *pool, int type, const char *format, ...)
592 {
593   va_list args;
594   char buf[1024];
595
596   if ((type & SAT_FATAL) == 0)
597     {
598       if ((pool->debugmask & type) == 0)
599         return;
600     }
601   va_start(args, format);
602   if (!pool->debugcallback)
603     {
604       if ((type & (SAT_FATAL|SAT_ERROR)) == 0)
605         vprintf(format, args);
606       else
607         vfprintf(stderr, format, args);
608       return;
609     }
610   vsnprintf(buf, sizeof(buf), format, args);
611   pool->debugcallback(pool, pool->debugcallbackdata, type, buf);
612 }
613
614 void
615 pool_setdebuglevel(Pool *pool, int level)
616 {
617   int mask = SAT_DEBUG_RESULT;
618   if (level > 0)
619     mask |= SAT_DEBUG_STATS|SAT_DEBUG_ANALYZE|SAT_DEBUG_UNSOLVABLE;
620   if (level > 1)
621     mask |= SAT_DEBUG_JOB|SAT_DEBUG_SOLUTIONS|SAT_DEBUG_POLICY;
622   if (level > 2)
623     mask |= SAT_DEBUG_PROPAGATE;
624   if (level > 3)
625     mask |= SAT_DEBUG_RULE_CREATION;
626   if (level > 4)
627     mask |= SAT_DEBUG_SCHUBI;
628   pool->debugmask = mask;
629 }
630
631 /*************************************************************************/
632
633 struct searchfiles {
634   const char **files;
635   int nfiles;
636   Map seen;
637 };
638
639 #define SEARCHFILES_BLOCK 127
640
641 static void
642 pool_addfileprovides_dep(Pool *pool, Id *ida, struct searchfiles *sf, struct searchfiles *isf)
643 {
644   Id dep, sid;
645   const char *s;
646
647   while ((dep = *ida++) != 0)
648     {
649       while (ISRELDEP(dep))
650         {
651           Reldep *rd;
652           sid = pool->ss.nstrings + GETRELID(dep);
653           if (MAPTST(&sf->seen, sid))
654             {
655               dep = 0;
656               break;
657             }
658           MAPSET(&sf->seen, sid);
659           rd = GETRELDEP(pool, dep);
660           if (rd->flags < 8)
661             dep = rd->name;
662           else if (rd->flags == REL_NAMESPACE)
663             {
664               if (isf && (rd->name == NAMESPACE_INSTALLED || rd->name == NAMESPACE_SPLITPROVIDES))
665                 {
666                   sf = isf;
667                   isf = 0;
668                   if (MAPTST(&sf->seen, sid))
669                     {
670                       dep = 0;
671                       break;
672                     }
673                   MAPSET(&sf->seen, sid);
674                 }
675               dep = rd->evr;
676             }
677           else
678             {
679               Id ids[2];
680               ids[0] = rd->name;
681               ids[1] = 0;
682               pool_addfileprovides_dep(pool, ids, sf, isf);
683               dep = rd->evr;
684             }
685         }
686       if (!dep)
687         continue;
688       if (MAPTST(&sf->seen, dep))
689         continue;
690       MAPSET(&sf->seen, dep);
691       s = id2str(pool, dep);
692       if (*s != '/')
693         continue;
694       if ((sf->nfiles & SEARCHFILES_BLOCK) == 0)
695         sf->files = sat_realloc2(sf->files, sf->nfiles + (SEARCHFILES_BLOCK + 1), sizeof(const char *));
696       sf->files[sf->nfiles++] = strdup(s);
697     }
698 }
699
700 #if 0
701 static int
702 addfileprovides_cb(void *data, Solvable *s, Id key, const char *str)
703 {
704   Pool *pool = s->repo->pool;
705   Id id;
706   id = str2id(pool, str, 0);
707   if (!id)
708     return 0;   /* can't happen */
709   s->provides = repo_addid_dep(s->repo, s->provides, id, SOLVABLE_FILEMARKER);
710   return 0;
711 }
712 #endif
713
714 void
715 pool_addfileprovides(Pool *pool, Repo *installed)
716 {
717   Solvable *s;
718   Repo *repo;
719   struct searchfiles sf, isf;
720   int i;
721
722   memset(&sf, 0, sizeof(sf));
723   map_init(&sf.seen, pool->ss.nstrings + pool->nrels);
724   memset(&isf, 0, sizeof(isf));
725   map_init(&isf.seen, pool->ss.nstrings + pool->nrels);
726
727   for (i = 1, s = pool->solvables + i; i < pool->nsolvables; i++, s++)
728     {
729       repo = s->repo;
730       if (!repo)
731         continue;
732       if (s->obsoletes)
733         pool_addfileprovides_dep(pool, repo->idarraydata + s->obsoletes, &sf, &isf);
734       if (s->conflicts)
735         pool_addfileprovides_dep(pool, repo->idarraydata + s->conflicts, &sf, &isf);
736       if (s->requires)
737         pool_addfileprovides_dep(pool, repo->idarraydata + s->requires, &sf, &isf);
738       if (s->recommends)
739         pool_addfileprovides_dep(pool, repo->idarraydata + s->recommends, &sf, &isf);
740       if (s->suggests)
741         pool_addfileprovides_dep(pool, repo->idarraydata + s->suggests, &sf, &isf);
742       if (s->supplements)
743         pool_addfileprovides_dep(pool, repo->idarraydata + s->supplements, &sf, &isf);
744       if (s->enhances)
745         pool_addfileprovides_dep(pool, repo->idarraydata + s->enhances, &sf, &isf);
746       if (s->freshens)
747         pool_addfileprovides_dep(pool, repo->idarraydata + s->freshens, &sf, &isf);
748     }
749   map_free(&sf.seen);
750   map_free(&isf.seen);
751   POOL_DEBUG(SAT_DEBUG_STATS, "found %d file dependencies\n", sf.nfiles);
752   POOL_DEBUG(SAT_DEBUG_STATS, "found %d installed file dependencies\n", isf.nfiles);
753   if (sf.nfiles)
754     {
755 #if 0
756       for (i = 0; i < sf.nfiles; i++)
757         POOL_DEBUG(SAT_DEBUG_STATS, "looking up %s in filelist\n", sf.files[i]);
758 #endif
759       if ((sf.nfiles & SEARCHFILES_BLOCK) == 0)
760         sf.files = sat_realloc2(sf.files, sf.nfiles + (SEARCHFILES_BLOCK + 1), sizeof(const char *));
761       sf.files[sf.nfiles++] = 0;
762 #if 0
763       pool_search(0, SOLVABLE_FILELIST, (const char *)sf.files, SEARCH_STRING|SEARCH_MULTIPLE, addfileprovides_cb, 0);
764 #endif
765       sat_free(sf.files);
766     }
767   if (isf.nfiles && installed)
768     {
769 #if 0
770       for (i = 0; i < isf.nfiles; i++)
771         POOL_DEBUG(SAT_DEBUG_STATS, "looking up %s in installed filelist\n", isf.files[i]);
772 #endif
773       if ((isf.nfiles & SEARCHFILES_BLOCK) == 0)
774         isf.files = sat_realloc2(isf.files, isf.nfiles + (SEARCHFILES_BLOCK + 1), sizeof(const char *));
775       isf.files[isf.nfiles++] = 0;
776 #if 0
777       repo_search(installed, 0, SOLVABLE_FILELIST, (const char *)isf.files, SEARCH_STRING|SEARCH_MULTIPLE, addfileprovides_cb, 0);
778 #endif
779       sat_free(isf.files);
780     }
781   pool_freewhatprovides(pool);  /* as we have added provides */
782 }
783
784 #if 0
785
786 struct mountpoint {
787   const char *path;
788   int kbytes;
789   int files;
790 };
791
792 struct mptree {
793   Id sibling;
794   Id child;
795   const char *comp;
796   int compl;
797   Id mountpoint;
798 };
799
800 struct cbdata {
801   struct mountpoint *mps;
802   Id *dirmap;
803   int nmap;
804 };
805
806 static int
807 pool_fill_DU_add_cb(void *data, Solvable *s, Id key, const char *str)
808 {
809   struct cbdata *cbdata = data;
810   Id mp, dirnum, kbytes, files;
811
812   dp = data_read_id(dp, &dirnum);
813   dp = data_read_id(dp, &kbytes);
814   data_read_id(dp, &files);
815   if (dirnum < 0 || dirnum > cbdata->nmap)
816     return 0;
817   mp = cbdata->dirmap[dirnum];
818   if (mp >= 0)
819     {
820       cbdata->mps[mp].kbytes += kbytes;
821       cbdata->mps[mp].files += files;
822     }
823   return 0;
824 }
825
826 static int
827 pool_fill_DU_sub_cb(void *data, Solvable *s, Id key, const char *str)
828 {
829   struct cbdata *cbdata = data;
830   Id mp, dirnum, kbytes, files;
831
832   dp = data_read_id(dp, &dirnum);
833   dp = data_read_id(dp, &kbytes);
834   data_read_id(dp, &files);
835   if (dirnum < 0 || dirnum > cbdata->nmap)
836     return 0;
837   mp = cbdata->dirmap[dirnum];
838   if (mp >= 0)
839     {
840       cbdata->mps[mp].kbytes -= kbytes;
841       cbdata->mps[mp].files -= files;
842     }
843   return 0;
844 }
845
846 static void
847 propagate_mountpoints(struct mptree *mptree, int pos, Id mountpoint)
848 {
849   int i;
850   if (mptree[pos].mountpoint == -1)
851     mptree[pos].mountpoint = mountpoint;
852   else
853     mountpoint = mptree[pos].mountpoint;
854   for (i = mptree[pos].child; i; i = mptree[i].sibling)
855     propagate_mountpoints(mptree, i, mountpoint);
856 }
857
858 void
859 pool_fill_DU(Pool *pool, struct mountpoint *mps, int nmps)
860 {
861   char *path, *p;
862   Id *dirmap;
863   struct mptree *mptree;
864   int nmptree;
865   int pos;
866   int mp;
867
868   struct matchdata md;
869   struct cbdata cbdata;
870
871   memset(&md, 0, sizeof(md));
872   md.pool = 0;
873   md.matchstr = 0;
874   md.flags = 0;
875   md.callback = 0;
876   md.callback_data = &cbdata
877
878   cbdata.mps = mps;
879   cbdata.dirmap = 0;
880   cbdata.nmap = 0;
881
882   mptree = sat_malloc2(16, sizeof(mptree));
883
884   /* our root node */
885   mptree[0].sibling = 0;
886   mptree[0].child = 0;
887   mptree[0].comp = 0;
888   mptree[0].compl = 0;
889   mptree[0].mountpoint = -1;
890   nmptree = 1;
891   
892   /* create component tree */
893   for (mp = 0; mp < nmps; mp++)
894     {
895       pos = 0;
896       path = mps[mp].path;
897       while(*path == '/')
898         path++;
899       while (*path)
900         {
901           if ((p = strchr('/', path)) == 0)
902             {
903               comp = path;
904               compl = strlen(comp);
905               path += compl;
906             }
907           else
908             {
909               comp = path;
910               compl = p - path;
911               path = p + 1;
912               while(*path == '/')
913                 path++;
914             }
915           for (i = mptree[pos].child; i; i = mptree[i].sibling)
916             if (mptree[i].compl == compl && !strncmp(mptree[i].comp, comp, compl))
917               break;
918           if (!i)
919             {
920               /* create new node */
921               if ((nmptree & 15) == 0)
922                 mptree = sat_realloc2(mptree, nmptree + 16, sizeof(mptree));
923               i = nmptree++;
924               mptree[i].sibling = mptree[pos].child;
925               mptree[i].child = 0;
926               mptree[i].comp = comp;
927               mptree[i].compl = compl;
928               mptree[i].mountpoint = -1;
929               mptree[pos].child = i;
930             }
931           pos = i;
932         }
933       mptree[pos].mountpoint = mp;
934     }
935   propagate_mountpoints(mptree, 0, mptree[0].mountpoint);
936
937   for_all_repos
938     {
939       for_all_repodatas_containing_DU
940         {
941           dirmap = xcalloc2(data->ndirs, sizeof(Id));
942           dirnum = 0;
943           for (;;)
944             {
945               parent = readid();
946               mp = parent ? dirmap[parent] : 0;
947               while (id = readid())
948                 {
949                   if (mp < 0)
950                     {
951                       /* unconnected */
952                       dirmap[dirnum++] = mp;
953                       continue;
954                     }
955                   if (!mptree[mp].child)
956                     {
957                       dirmap[dirnum++] = -mp;
958                       continue;
959                     }
960                   comp = id2str(pool, id);
961                   compl = strlen(comp);
962                   for (i = mptree[mp].child; i; i = mptree[i].sibling)
963                     if (mptree[i].compl == compl && !strncmp(mptree[i].comp, comp, compl))
964                       break;
965                   dirmap[dirnum++] = i ? i : -mp;
966                 }
967             }
968           for (i = 0; i < dirnum; i++)
969             {
970               mp = dirmap[i];
971               dirmap[i] = mptree[mp > 0 ? mp : -mp].mountpoint;
972             }
973           cbdata.nmap = dirnum;
974           cbdata.dirmap = dirmap;
975
976           md.callback = pool_fill_DU_add_cb;
977           for_solvables_to_be_installed()
978             {
979               if (p < data->start || p >= data->end)
980                 continue;
981               repodata_search(data, p - data->start, SOLVABLE_DUDATA, &md);
982             }
983           md.callback = pool_fill_DU_sub_cb;
984           for_solvables_to_be_erased()
985             {
986               if (p < data->start || p >= data->end)
987                 continue;
988               repodata_search(data, p - data->start, SOLVABLE_DUDATA, &md);
989             }
990
991           cbdata.dirmap = 0;
992           cbdata.nmap = 0;
993           sat_free(dirmap);
994         }
995     }
996 }
997
998 #endif
999
1000 // EOF