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