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