implement pool_set_rootdir/REPO_USE_ROOTDIR instead of passing a rootdir to various...
[platform/upstream/libsolv.git] / src / pool.c
1 /*
2  * Copyright (c) 2007-2009, 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 #define KNOWNID_INITIALIZE
33 #include "knownid.h"
34 #undef KNOWNID_INITIALIZE
35
36 /* create pool */
37 Pool *
38 pool_create(void)
39 {
40   Pool *pool;
41   Solvable *s;
42
43   pool = (Pool *)solv_calloc(1, sizeof(*pool));
44
45   stringpool_init (&pool->ss, initpool_data);
46
47   /* alloc space for RelDep 0 */
48   pool->rels = solv_extend_resize(0, 1, sizeof(Reldep), REL_BLOCK);
49   pool->nrels = 1;
50   memset(pool->rels, 0, sizeof(Reldep));
51
52   /* alloc space for Solvable 0 and system solvable */
53   pool->solvables = solv_extend_resize(0, 2, sizeof(Solvable), SOLVABLE_BLOCK);
54   pool->nsolvables = 2;
55   memset(pool->solvables, 0, 2 * sizeof(Solvable));
56
57   queue_init(&pool->vendormap);
58
59 #if defined(DEBIAN)
60   pool->disttype = DISTTYPE_DEB;
61   pool->noarchid = ARCH_ALL;
62 #elif defined(ARCHLINUX)
63   pool->disttype = DISTTYPE_ARCH;
64   pool->noarchid = ARCH_ANY;
65 #else
66   pool->disttype = DISTTYPE_RPM;
67   pool->noarchid = ARCH_NOARCH;
68 #endif
69
70   /* initialize the system solvable */
71   s = pool->solvables + SYSTEMSOLVABLE;
72   s->name = SYSTEM_SYSTEM;
73   s->arch = pool->noarchid;
74   s->evr = ID_EMPTY;
75
76   pool->debugmask = SOLV_DEBUG_RESULT;  /* FIXME */
77 #ifdef FEDORA
78   pool->obsoleteusescolors = 1;
79 #endif
80 #ifdef RPM5
81   pool->forbidselfconflicts = 1;
82   pool->obsoleteusesprovides = 1;
83   pool->implicitobsoleteusesprovides = 1;
84   pool->havedistepoch = 1;
85 #endif
86   return pool;
87 }
88
89
90 /* free all the resources of our pool */
91 void
92 pool_free(Pool *pool)
93 {
94   int i;
95
96   pool_freewhatprovides(pool);
97   pool_freeidhashes(pool);
98   pool_freeallrepos(pool, 1);
99   solv_free(pool->id2arch);
100   solv_free(pool->id2color);
101   solv_free(pool->solvables);
102   stringpool_free(&pool->ss);
103   solv_free(pool->rels);
104   pool_setvendorclasses(pool, 0);
105   queue_free(&pool->vendormap);
106   for (i = 0; i < POOL_TMPSPACEBUF; i++)
107     solv_free(pool->tmpspace.buf[i]);
108   for (i = 0; i < pool->nlanguages; i++)
109     free((char *)pool->languages[i]);
110   solv_free(pool->languages);
111   solv_free(pool->languagecache);
112   solv_free(pool->errstr);
113   solv_free(pool->rootdir);
114   solv_free(pool);
115 }
116
117 void
118 pool_freeallrepos(Pool *pool, int reuseids)
119 {
120   int i;
121
122   pool_freewhatprovides(pool);
123   for (i = 1; i < pool->nrepos; i++) 
124     if (pool->repos[i])
125       repo_freedata(pool->repos[i]);
126   pool->repos = solv_free(pool->repos);
127   pool->nrepos = 0; 
128   pool->urepos = 0; 
129   /* the first two solvables don't belong to a repo */
130   pool_free_solvable_block(pool, 2, pool->nsolvables - 2, reuseids);
131 }
132
133 #ifdef MULTI_SEMANTICS
134 void
135 pool_setdisttype(Pool *pool, int disttype)
136 {
137   pool->disttype = disttype;
138   if (disttype == DISTTYPE_RPM)
139     pool->noarchid = ARCH_NOARCH;
140   if (disttype == DISTTYPE_DEB)
141     pool->noarchid = ARCH_ALL;
142   if (disttype == DISTTYPE_ARCH)
143     pool->noarchid = ARCH_ANY;
144   pool->solvables[SYSTEMSOLVABLE].arch = pool->noarchid;
145 }
146 #endif
147
148 int
149 pool_get_flag(Pool *pool, int flag)
150 {
151   switch (flag)
152     {
153     case POOL_FLAG_PROMOTEEPOCH:
154       return pool->promoteepoch;
155     case POOL_FLAG_FORBIDSELFCONFLICTS:
156       return pool->forbidselfconflicts;
157     case POOL_FLAG_OBSOLETEUSESPROVIDES:
158       return pool->obsoleteusesprovides;
159     case POOL_FLAG_IMPLICITOBSOLETEUSESPROVIDES:
160       return pool->implicitobsoleteusesprovides;
161     case POOL_FLAG_OBSOLETEUSESCOLORS:
162       return pool->obsoleteusescolors;
163     case POOL_FLAG_NOINSTALLEDOBSOLETES:
164       return pool->noinstalledobsoletes;
165     case POOL_FLAG_HAVEDISTEPOCH:
166       return pool->havedistepoch;
167     default:
168       break;
169     }
170   return -1;
171 }
172
173 int
174 pool_set_flag(Pool *pool, int flag, int value)
175 {
176   int old = pool_get_flag(pool, flag);
177   switch (flag)
178     {
179     case POOL_FLAG_PROMOTEEPOCH:
180       pool->promoteepoch = value;
181       break;
182     case POOL_FLAG_FORBIDSELFCONFLICTS:
183       pool->forbidselfconflicts = value;
184       break;
185     case POOL_FLAG_OBSOLETEUSESPROVIDES:
186       pool->obsoleteusesprovides = value;
187       break;
188     case POOL_FLAG_IMPLICITOBSOLETEUSESPROVIDES:
189       pool->implicitobsoleteusesprovides = value;
190       break;
191     case POOL_FLAG_OBSOLETEUSESCOLORS:
192       pool->obsoleteusescolors = value;
193       break;
194     case POOL_FLAG_NOINSTALLEDOBSOLETES:
195       pool->noinstalledobsoletes = value;
196       break;
197     case POOL_FLAG_HAVEDISTEPOCH:
198       pool->havedistepoch = value;
199       break;
200     default:
201       break;
202     }
203   return old;
204 }
205
206
207 Id
208 pool_add_solvable(Pool *pool)
209 {
210   pool->solvables = solv_extend(pool->solvables, pool->nsolvables, 1, sizeof(Solvable), SOLVABLE_BLOCK);
211   memset(pool->solvables + pool->nsolvables, 0, sizeof(Solvable));
212   return pool->nsolvables++;
213 }
214
215 Id
216 pool_add_solvable_block(Pool *pool, int count)
217 {
218   Id nsolvables = pool->nsolvables;
219   if (!count)
220     return nsolvables;
221   pool->solvables = solv_extend(pool->solvables, pool->nsolvables, count, sizeof(Solvable), SOLVABLE_BLOCK);
222   memset(pool->solvables + nsolvables, 0, sizeof(Solvable) * count);
223   pool->nsolvables += count;
224   return nsolvables;
225 }
226
227 void
228 pool_free_solvable_block(Pool *pool, Id start, int count, int reuseids)
229 {
230   if (!count)
231     return;
232   if (reuseids && start + count == pool->nsolvables)
233     {
234       /* might want to shrink solvable array */
235       pool->nsolvables = start;
236       return;
237     }
238   memset(pool->solvables + start, 0, sizeof(Solvable) * count);
239 }
240
241
242 void
243 pool_set_installed(Pool *pool, Repo *installed)
244 {
245   if (pool->installed == installed)
246     return;
247   pool->installed = installed;
248   pool_freewhatprovides(pool);
249 }
250
251 static int
252 pool_shrink_whatprovides_sortcmp(const void *ap, const void *bp, void *dp)
253 {
254   int r;
255   Pool *pool = dp;
256   Id oa, ob, *da, *db;
257   oa = pool->whatprovides[*(Id *)ap];
258   ob = pool->whatprovides[*(Id *)bp];
259   if (oa == ob)
260     return *(Id *)ap - *(Id *)bp;
261   da = pool->whatprovidesdata + oa;
262   db = pool->whatprovidesdata + ob;
263   while (*db)
264     if ((r = (*da++ - *db++)) != 0)
265       return r;
266   if (*da)
267     return *da;
268   return *(Id *)ap - *(Id *)bp;
269 }
270
271 /*
272  * pool_shrink_whatprovides  - unify whatprovides data
273  *
274  * whatprovides_rel must be empty for this to work!
275  *
276  */
277 static void
278 pool_shrink_whatprovides(Pool *pool)
279 {
280   Id i, n, id;
281   Id *sorted;
282   Id lastid, *last, *dp, *lp;
283   Offset o;
284   int r;
285
286   if (pool->ss.nstrings < 3)
287     return;
288   sorted = solv_malloc2(pool->ss.nstrings, sizeof(Id));
289   for (i = id = 0; id < pool->ss.nstrings; id++)
290     if (pool->whatprovides[id] && pool->whatprovides[id] != 1)
291       sorted[i++] = id;
292   n = i;
293   solv_sort(sorted, n, sizeof(Id), pool_shrink_whatprovides_sortcmp, pool);
294   last = 0;
295   lastid = 0;
296   for (i = 0; i < n; i++)
297     {
298       id = sorted[i];
299       o = pool->whatprovides[id];
300       dp = pool->whatprovidesdata + o;
301       if (last)
302         {
303           lp = last;
304           while (*dp)   
305             if (*dp++ != *lp++)
306               {
307                 last = 0;
308                 break;
309               }
310           if (last && *lp)
311             last = 0;
312           if (last)
313             {
314               pool->whatprovides[id] = -lastid;
315               continue;
316             }
317         }
318       last = pool->whatprovidesdata + o;
319       lastid = id;
320     }
321   solv_free(sorted);
322   dp = pool->whatprovidesdata + 2;
323   for (id = 1; id < pool->ss.nstrings; id++)
324     {
325       o = pool->whatprovides[id];
326       if (o == 0 || o == 1)
327         continue;
328       if ((Id)o < 0)
329         {
330           i = -(Id)o;
331           if (i >= id)
332             abort();
333           pool->whatprovides[id] = pool->whatprovides[i];
334           continue;
335         }
336       lp = pool->whatprovidesdata + o;
337       if (lp < dp)
338         abort();
339       pool->whatprovides[id] = dp - pool->whatprovidesdata;
340       while ((*dp++ = *lp++) != 0)
341         ;
342     }
343   o = dp - pool->whatprovidesdata;
344   POOL_DEBUG(SOLV_DEBUG_STATS, "shrunk whatprovidesdata from %d to %d\n", pool->whatprovidesdataoff, o);
345   if (pool->whatprovidesdataoff == o)
346     return;
347   r = pool->whatprovidesdataoff - o;
348   pool->whatprovidesdataoff = o;
349   pool->whatprovidesdata = solv_realloc(pool->whatprovidesdata, (o + pool->whatprovidesdataleft) * sizeof(Id));
350   if (r > pool->whatprovidesdataleft)
351     r = pool->whatprovidesdataleft;
352   memset(pool->whatprovidesdata + o, 0, r * sizeof(Id));
353 }
354
355
356 /*
357  * pool_createwhatprovides()
358  * 
359  * create hashes over pool of solvables to ease provide lookups
360  * 
361  */
362 void
363 pool_createwhatprovides(Pool *pool)
364 {
365   int i, num, np, extra;
366   Offset off;
367   Solvable *s;
368   Id id;
369   Offset *idp, n;
370   Offset *whatprovides;
371   Id *whatprovidesdata, *d;
372   Repo *installed = pool->installed;
373   unsigned int now;
374
375   now = solv_timems(0);
376   POOL_DEBUG(SOLV_DEBUG_STATS, "number of solvables: %d, memory used: %d K\n", pool->nsolvables, pool->nsolvables * (int)sizeof(Solvable) / 1024);
377   POOL_DEBUG(SOLV_DEBUG_STATS, "number of ids: %d + %d\n", pool->ss.nstrings, pool->nrels);
378   POOL_DEBUG(SOLV_DEBUG_STATS, "string memory used: %d K array + %d K data,  rel memory used: %d K array\n", pool->ss.nstrings / (1024 / (int)sizeof(Id)), pool->ss.sstrings / 1024, pool->nrels * (int)sizeof(Reldep) / 1024);
379   if (pool->ss.stringhashmask || pool->relhashmask)
380     POOL_DEBUG(SOLV_DEBUG_STATS, "string hash memory: %d K, rel hash memory : %d K\n", (pool->ss.stringhashmask + 1) / (int)(1024/sizeof(Id)), (pool->relhashmask + 1) / (int)(1024/sizeof(Id)));
381
382   pool_freeidhashes(pool);      /* XXX: should not be here! */
383   pool_freewhatprovides(pool);
384   num = pool->ss.nstrings;
385   pool->whatprovides = whatprovides = solv_calloc_block(num, sizeof(Offset), WHATPROVIDES_BLOCK);
386   pool->whatprovides_rel = solv_calloc_block(pool->nrels, sizeof(Offset), WHATPROVIDES_BLOCK);
387
388   /* count providers for each name */
389   for (i = pool->nsolvables - 1; i > 0; i--)
390     {
391       Id *pp;
392       s = pool->solvables + i;
393       if (!s->provides || !s->repo || s->repo->disabled)
394         continue;
395       /* we always need the installed solvable in the whatprovides data,
396          otherwise obsoletes/conflicts on them won't work */
397       if (s->repo != installed && !pool_installable(pool, s))
398         continue;
399       pp = s->repo->idarraydata + s->provides;
400       while ((id = *pp++) != 0)
401         {
402           while (ISRELDEP(id))
403             {
404               Reldep *rd = GETRELDEP(pool, id);
405               id = rd->name;
406             }
407           whatprovides[id]++;          /* inc count of providers */
408         }
409     }
410
411   off = 2;      /* first entry is undef, second is empty list */
412   np = 0;                              /* number of names provided */
413   for (i = 0, idp = whatprovides; i < num; i++, idp++)
414     {
415       n = *idp;
416       if (!n)                          /* no providers */
417         continue;
418       off += n;                        /* make space for all providers */
419       *idp = off++;                    /* now idp points to terminating zero */
420       np++;                            /* inc # of provider 'slots' for stats */
421     }
422
423   POOL_DEBUG(SOLV_DEBUG_STATS, "provide ids: %d\n", np);
424
425   /* reserve some space for relation data */
426   extra = 2 * pool->nrels;
427   if (extra < 256)
428     extra = 256;
429
430   POOL_DEBUG(SOLV_DEBUG_STATS, "provide space needed: %d + %d\n", off, extra);
431
432   /* alloc space for all providers + extra */
433   whatprovidesdata = solv_calloc(off + extra, sizeof(Id));
434
435   /* now fill data for all provides */
436   for (i = pool->nsolvables - 1; i > 0; i--)
437     {
438       Id *pp;
439       s = pool->solvables + i;
440       if (!s->provides || !s->repo || s->repo->disabled)
441         continue;
442       if (s->repo != installed && !pool_installable(pool, s))
443         continue;
444
445       /* for all provides of this solvable */
446       pp = s->repo->idarraydata + s->provides;
447       while ((id = *pp++) != 0)
448         {
449           while (ISRELDEP(id))
450             {
451               Reldep *rd = GETRELDEP(pool, id);
452               id = rd->name;
453             }
454           d = whatprovidesdata + whatprovides[id];   /* offset into whatprovidesdata */
455           if (*d != i)          /* don't add same solvable twice */
456             {
457               d[-1] = i;
458               whatprovides[id]--;
459             }
460         }
461     }
462   pool->whatprovidesdata = whatprovidesdata;
463   pool->whatprovidesdataoff = off;
464   pool->whatprovidesdataleft = extra;
465   pool_shrink_whatprovides(pool);
466   POOL_DEBUG(SOLV_DEBUG_STATS, "whatprovides memory used: %d K id array, %d K data\n", (pool->ss.nstrings + pool->nrels + WHATPROVIDES_BLOCK) / (int)(1024/sizeof(Id)), (pool->whatprovidesdataoff + pool->whatprovidesdataleft) / (int)(1024/sizeof(Id)));
467   POOL_DEBUG(SOLV_DEBUG_STATS, "createwhatprovides took %d ms\n", solv_timems(now));
468 }
469
470 /*
471  * free all of our whatprovides data
472  * be careful, everything internalized with pool_queuetowhatprovides is
473  * gone, too
474  */
475 void
476 pool_freewhatprovides(Pool *pool)
477 {
478   pool->whatprovides = solv_free(pool->whatprovides);
479   pool->whatprovides_rel = solv_free(pool->whatprovides_rel);
480   pool->whatprovidesdata = solv_free(pool->whatprovidesdata);
481   pool->whatprovidesdataoff = 0;
482   pool->whatprovidesdataleft = 0;
483 }
484
485
486 /******************************************************************************/
487
488 /*
489  * pool_queuetowhatprovides  - add queue contents to whatprovidesdata
490  * 
491  * on-demand filling of provider information
492  * move queue data into whatprovidesdata
493  * q: queue of Ids
494  * returns: Offset into whatprovides
495  *
496  */
497 Id
498 pool_queuetowhatprovides(Pool *pool, Queue *q)
499 {
500   Offset off;
501   int count = q->count;
502
503   if (count == 0)                      /* queue empty -> 1 */
504     return 1;
505
506   /* extend whatprovidesdata if needed, +1 for ID_NULL-termination */
507   if (pool->whatprovidesdataleft < count + 1)
508     {
509       POOL_DEBUG(SOLV_DEBUG_STATS, "growing provides hash data...\n");
510       pool->whatprovidesdata = solv_realloc(pool->whatprovidesdata, (pool->whatprovidesdataoff + count + 4096) * sizeof(Id));
511       pool->whatprovidesdataleft = count + 4096;
512     }
513
514   /* copy queue to next free slot */
515   off = pool->whatprovidesdataoff;
516   memcpy(pool->whatprovidesdata + pool->whatprovidesdataoff, q->elements, count * sizeof(Id));
517
518   /* adapt count and ID_NULL-terminate */
519   pool->whatprovidesdataoff += count;
520   pool->whatprovidesdata[pool->whatprovidesdataoff++] = ID_NULL;
521   pool->whatprovidesdataleft -= count + 1;
522
523   return (Id)off;
524 }
525
526
527 /*************************************************************************/
528
529 #if defined(MULTI_SEMANTICS)
530 # define EVRCMP_DEPCMP (pool->disttype == DISTTYPE_DEB ? EVRCMP_COMPARE : EVRCMP_MATCH_RELEASE)
531 #elif defined(DEBIAN)
532 # define EVRCMP_DEPCMP EVRCMP_COMPARE
533 #else
534 # define EVRCMP_DEPCMP EVRCMP_MATCH_RELEASE
535 #endif
536
537 /* check if a package's nevr matches a dependency */
538
539 int
540 pool_match_nevr_rel(Pool *pool, Solvable *s, Id d)
541 {
542   Reldep *rd = GETRELDEP(pool, d);
543   Id name = rd->name;
544   Id evr = rd->evr;
545   int flags = rd->flags;
546
547   if (flags > 7)
548     {
549       switch (flags)
550         {
551         case REL_ARCH:
552           if (s->arch != evr)
553             return 0;
554           return pool_match_nevr(pool, s, name);
555         case REL_OR:
556           if (pool_match_nevr(pool, s, name))
557             return 1;
558           return pool_match_nevr(pool, s, evr);
559         case REL_AND:
560         case REL_WITH:
561           if (!pool_match_nevr(pool, s, name))
562             return 0;
563           return pool_match_nevr(pool, s, evr);
564         default:
565           return 0;
566         }
567     }
568   if (!pool_match_nevr(pool, s, name))
569     return 0;
570   if (evr == s->evr)
571     return (flags & REL_EQ) ? 1 : 0;
572   if (!flags)
573     return 0;
574   if (flags == 7)
575     return 1;
576   switch (pool_evrcmp(pool, s->evr, evr, EVRCMP_DEPCMP))
577     {
578     case -2:
579       return 1;
580     case -1:
581       return (flags & REL_LT) ? 1 : 0;
582     case 0:
583       return (flags & REL_EQ) ? 1 : 0;
584     case 1:
585       return (flags & REL_GT) ? 1 : 0;
586     case 2:
587       return (flags & REL_EQ) ? 1 : 0;
588     default:
589       break;
590     }
591   return 0;
592 }
593
594 /* match (flags, evr) against provider (pflags, pevr) */
595 static inline int
596 pool_match_flags_evr(Pool *pool, int pflags, Id pevr, int flags, int evr)
597 {
598   if (!pflags || !flags || pflags >= 8 || flags >= 8)
599     return 0;
600   if (flags == 7 || pflags == 7)
601     return 1;           /* rel provides every version */
602   if ((pflags & flags & (REL_LT | REL_GT)) != 0)
603     return 1;           /* both rels show in the same direction */
604   if (pevr == evr)
605     return (flags & pflags & REL_EQ) ? 1 : 0;
606   switch (pool_evrcmp(pool, pevr, evr, EVRCMP_DEPCMP))
607     {
608     case -2:
609       return (pflags & REL_EQ) ? 1 : 0;
610     case -1:
611       return (flags & REL_LT) || (pflags & REL_GT) ? 1 : 0;
612     case 0:
613       return (flags & pflags & REL_EQ) ? 1 : 0;
614     case 1:
615       return (flags & REL_GT) || (pflags & REL_LT) ? 1 : 0;
616     case 2:
617       return (flags & REL_EQ) ? 1 : 0;
618     default:
619       break;
620     }
621   return 0;
622 }
623
624 /* match two dependencies (d1 = provider) */
625
626 int
627 pool_match_dep(Pool *pool, Id d1, Id d2)
628 {
629   Reldep *rd1, *rd2;
630
631   if (d1 == d2)
632     return 1;
633   if (!ISRELDEP(d1))
634     {
635       if (!ISRELDEP(d2))
636         return 0;
637       rd2 = GETRELDEP(pool, d2);
638       return pool_match_dep(pool, d1, rd2->name);
639     }
640   rd1 = GETRELDEP(pool, d1);
641   if (!ISRELDEP(d2))
642     {
643       return pool_match_dep(pool, rd1->name, d2);
644     }
645   rd2 = GETRELDEP(pool, d2);
646   /* first match name */
647   if (!pool_match_dep(pool, rd1->name, rd2->name))
648     return 0;
649   /* name matches, check flags and evr */
650   return pool_match_flags_evr(pool, rd1->flags, rd1->evr, rd2->flags, rd2->evr);
651 }
652
653 /*
654  * addrelproviders
655  * 
656  * add packages fulfilling the relation to whatprovides array
657  * no exact providers, do range match
658  * 
659  */
660
661 Id
662 pool_addrelproviders(Pool *pool, Id d)
663 {
664   Reldep *rd = GETRELDEP(pool, d);
665   Reldep *prd;
666   Queue plist;
667   Id buf[16];
668   Id name = rd->name;
669   Id evr = rd->evr;
670   int flags = rd->flags;
671   Id pid, *pidp;
672   Id p, *pp;
673
674   d = GETRELID(d);
675   queue_init_buffer(&plist, buf, sizeof(buf)/sizeof(*buf));
676
677   if (flags >= 8)
678     {
679       /* special relation */
680       Id wp = 0;
681       Id *pp2, *pp3;
682
683       switch (flags)
684         {
685         case REL_AND:
686         case REL_WITH:
687           wp = pool_whatprovides(pool, name);
688           pp2 = pool_whatprovides_ptr(pool, evr);
689           pp = pool->whatprovidesdata + wp;
690           while ((p = *pp++) != 0)
691             {
692               for (pp3 = pp2; *pp3; pp3++)
693                 if (*pp3 == p)
694                   break;
695               if (*pp3)
696                 queue_push(&plist, p);  /* found it */
697               else
698                 wp = 0;
699             }
700           break;
701         case REL_OR:
702           wp = pool_whatprovides(pool, name);
703           pp = pool->whatprovidesdata + wp;
704           if (!*pp)
705             wp = pool_whatprovides(pool, evr);
706           else
707             {
708               int cnt;
709               while ((p = *pp++) != 0)
710                 queue_push(&plist, p);
711               cnt = plist.count;
712               pp = pool_whatprovides_ptr(pool, evr);
713               while ((p = *pp++) != 0)
714                 queue_pushunique(&plist, p);
715               if (plist.count != cnt)
716                 wp = 0;
717             }
718           break;
719         case REL_NAMESPACE:
720           if (name == NAMESPACE_OTHERPROVIDERS)
721             {
722               wp = pool_whatprovides(pool, evr);
723               break;
724             }
725           if (pool->nscallback)
726             {
727               /* ask callback which packages provide the dependency
728                * 0:  none
729                * 1:  the system (aka SYSTEMSOLVABLE)
730                * >1: set of packages, stored as offset on whatprovidesdata
731                */
732               p = pool->nscallback(pool, pool->nscallbackdata, name, evr);
733               if (p > 1)
734                 wp = p;
735               if (p == 1)
736                 queue_push(&plist, SYSTEMSOLVABLE);
737             }
738           break;
739         case REL_ARCH:
740           /* small hack: make it possible to match <pkg>.src
741            * we have to iterate over the solvables as src packages do not
742            * provide anything, thus they are not indexed in our
743            * whatprovides hash */
744           if (evr == ARCH_SRC)
745             {
746               Solvable *s;
747               for (p = 1, s = pool->solvables + p; p < pool->nsolvables; p++, s++)
748                 {
749                   if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
750                     continue;
751                   if (pool_match_nevr(pool, s, name))
752                     queue_push(&plist, p);
753                 }
754               break;
755             }
756           wp = pool_whatprovides(pool, name);
757           pp = pool->whatprovidesdata + wp;
758           while ((p = *pp++) != 0)
759             {
760               Solvable *s = pool->solvables + p;
761               if (s->arch == evr)
762                 queue_push(&plist, p);
763               else
764                 wp = 0;
765             }
766           break;
767         case REL_FILECONFLICT:
768           pp = pool_whatprovides_ptr(pool, name);
769           while ((p = *pp++) != 0)
770             {
771               Id origd = MAKERELDEP(d);
772               Solvable *s = pool->solvables + p;
773               if (!s->provides)
774                 continue;
775               pidp = s->repo->idarraydata + s->provides;
776               while ((pid = *pidp++) != 0)
777                 if (pid == origd)
778                   break;
779               if (pid)
780                 queue_push(&plist, p);
781             }
782           break;
783         default:
784           break;
785         }
786       if (wp)
787         {
788           /* we can reuse an existing entry */
789           queue_free(&plist);
790           pool->whatprovides_rel[d] = wp;
791           return wp;
792         }
793     }
794   else if (flags)
795     {
796       /* simple version comparison relation */
797 #if 0
798       POOL_DEBUG(SOLV_DEBUG_STATS, "addrelproviders: what provides %s?\n", pool_dep2str(pool, name));
799 #endif
800       pp = pool_whatprovides_ptr(pool, name);
801       while (ISRELDEP(name))
802         {
803           rd = GETRELDEP(pool, name);
804           name = rd->name;
805         }
806       while ((p = *pp++) != 0)
807         {
808           Solvable *s = pool->solvables + p;
809           if (!s->provides)
810             {
811               /* no provides - check nevr */
812               if (pool_match_nevr_rel(pool, s, MAKERELDEP(d)))
813                 queue_push(&plist, p);
814               continue;
815             }
816           /* solvable p provides name in some rels */
817           pidp = s->repo->idarraydata + s->provides;
818           while ((pid = *pidp++) != 0)
819             {
820               if (!ISRELDEP(pid))
821                 {
822                   if (pid != name)
823                     continue;           /* wrong provides name */
824                   if (pool->disttype == DISTTYPE_DEB)
825                     continue;           /* unversioned provides can never match versioned deps */
826                   break;
827                 }
828               prd = GETRELDEP(pool, pid);
829               if (prd->name != name)
830                 continue;               /* wrong provides name */
831               /* right package, both deps are rels. check flags/evr */
832               if (pool_match_flags_evr(pool, prd->flags, prd->evr, flags, evr))
833                 break;  /* matches */
834             }
835           if (!pid)
836             continue;   /* none of the providers matched */
837           queue_push(&plist, p);
838         }
839       /* make our system solvable provide all unknown rpmlib() stuff */
840       if (plist.count == 0 && !strncmp(pool_id2str(pool, name), "rpmlib(", 7))
841         queue_push(&plist, SYSTEMSOLVABLE);
842     }
843   /* add providers to whatprovides */
844 #if 0
845   POOL_DEBUG(SOLV_DEBUG_STATS, "addrelproviders: adding %d packages to %d\n", plist.count, d);
846 #endif
847   pool->whatprovides_rel[d] = pool_queuetowhatprovides(pool, &plist);
848   queue_free(&plist);
849
850   return pool->whatprovides_rel[d];
851 }
852
853 /*************************************************************************/
854
855 void
856 pool_debug(Pool *pool, int type, const char *format, ...)
857 {
858   va_list args;
859   char buf[1024];
860
861   if ((type & (SOLV_FATAL|SOLV_ERROR)) == 0)
862     {
863       if ((pool->debugmask & type) == 0)
864         return;
865     }
866   va_start(args, format);
867   if (!pool->debugcallback)
868     {
869       if ((type & (SOLV_FATAL|SOLV_ERROR)) == 0 && !(pool->debugmask & SOLV_DEBUG_TO_STDERR))
870         vprintf(format, args);
871       else
872         vfprintf(stderr, format, args);
873       return;
874     }
875   vsnprintf(buf, sizeof(buf), format, args);
876   va_end(args);
877   pool->debugcallback(pool, pool->debugcallbackdata, type, buf);
878 }
879
880 int
881 pool_error(Pool *pool, int ret, const char *format, ...)
882 {
883   va_list args;
884   int l;
885   va_start(args, format);
886   if (!pool->errstr)
887     {
888       pool->errstra = 1024;
889       pool->errstr = solv_malloc(pool->errstra);
890     }
891   if (!*format)
892     {
893       *pool->errstr = 0;
894       l = 0;
895     }
896   else
897     l = vsnprintf(pool->errstr, pool->errstra, format, args);
898   va_end(args);
899   if (l >= 0 && l + 1 > pool->errstra)
900     {
901       pool->errstra = l + 256;
902       pool->errstr = solv_realloc(pool->errstr, pool->errstra);
903       va_start(args, format);
904       l = vsnprintf(pool->errstr, pool->errstra, format, args);
905       va_end(args);
906     }
907   if (l < 0)
908     strcpy(pool->errstr, "unknown error");
909   if (pool->debugmask & SOLV_ERROR)
910     pool_debug(pool, SOLV_ERROR, "%s\n", pool->errstr);
911   return ret;
912 }
913
914 char *
915 pool_errstr(Pool *pool)
916 {
917   return pool->errstr ? pool->errstr : "no error";
918 }
919
920 void
921 pool_setdebuglevel(Pool *pool, int level)
922 {
923   int mask = SOLV_DEBUG_RESULT;
924   if (level > 0)
925     mask |= SOLV_DEBUG_STATS|SOLV_DEBUG_ANALYZE|SOLV_DEBUG_UNSOLVABLE|SOLV_DEBUG_SOLVER|SOLV_DEBUG_TRANSACTION|SOLV_ERROR;
926   if (level > 1)
927     mask |= SOLV_DEBUG_JOB|SOLV_DEBUG_SOLUTIONS|SOLV_DEBUG_POLICY;
928   if (level > 2)
929     mask |= SOLV_DEBUG_PROPAGATE;
930   if (level > 3)
931     mask |= SOLV_DEBUG_RULE_CREATION;
932   mask |= pool->debugmask & SOLV_DEBUG_TO_STDERR;       /* keep bit */
933   pool->debugmask = mask;
934 }
935
936 void pool_setdebugcallback(Pool *pool, void (*debugcallback)(struct _Pool *, void *data, int type, const char *str), void *debugcallbackdata)
937 {
938   pool->debugcallback = debugcallback;
939   pool->debugcallbackdata = debugcallbackdata;
940 }
941
942 void pool_setdebugmask(Pool *pool, int mask)
943 {
944   pool->debugmask = mask;
945 }
946
947 void pool_setloadcallback(Pool *pool, int (*cb)(struct _Pool *, struct _Repodata *, void *), void *loadcbdata)
948 {
949   pool->loadcallback = cb;
950   pool->loadcallbackdata = loadcbdata;
951 }
952
953 /*************************************************************************/
954
955 struct searchfiles {
956   Id *ids;
957   char **dirs;
958   char **names;
959   int nfiles;
960   Map seen;
961 };
962
963 #define SEARCHFILES_BLOCK 127
964
965 static void
966 pool_addfileprovides_dep(Pool *pool, Id *ida, struct searchfiles *sf, struct searchfiles *isf)
967 {
968   Id dep, sid;
969   const char *s, *sr;
970   struct searchfiles *csf;
971
972   while ((dep = *ida++) != 0)
973     {
974       csf = sf;
975       while (ISRELDEP(dep))
976         {
977           Reldep *rd;
978           sid = pool->ss.nstrings + GETRELID(dep);
979           if (MAPTST(&csf->seen, sid))
980             {
981               dep = 0;
982               break;
983             }
984           MAPSET(&csf->seen, sid);
985           rd = GETRELDEP(pool, dep);
986           if (rd->flags < 8)
987             dep = rd->name;
988           else if (rd->flags == REL_NAMESPACE)
989             {
990               if (rd->name == NAMESPACE_INSTALLED || rd->name == NAMESPACE_SPLITPROVIDES)
991                 {
992                   csf = isf;
993                   if (!csf || MAPTST(&csf->seen, sid))
994                     {
995                       dep = 0;
996                       break;
997                     }
998                   MAPSET(&csf->seen, sid);
999                 }
1000               dep = rd->evr;
1001             }
1002           else if (rd->flags == REL_FILECONFLICT)
1003             {
1004               dep = 0;
1005               break;
1006             }
1007           else
1008             {
1009               Id ids[2];
1010               ids[0] = rd->name;
1011               ids[1] = 0;
1012               pool_addfileprovides_dep(pool, ids, csf, isf);
1013               dep = rd->evr;
1014             }
1015         }
1016       if (!dep)
1017         continue;
1018       if (MAPTST(&csf->seen, dep))
1019         continue;
1020       MAPSET(&csf->seen, dep);
1021       s = pool_id2str(pool, dep);
1022       if (*s != '/')
1023         continue;
1024       csf->ids = solv_extend(csf->ids, csf->nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
1025       csf->dirs = solv_extend(csf->dirs, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
1026       csf->names = solv_extend(csf->names, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
1027       csf->ids[csf->nfiles] = dep;
1028       sr = strrchr(s, '/');
1029       csf->names[csf->nfiles] = solv_strdup(sr + 1);
1030       csf->dirs[csf->nfiles] = solv_malloc(sr - s + 1);
1031       if (sr != s)
1032         strncpy(csf->dirs[csf->nfiles], s, sr - s);
1033       csf->dirs[csf->nfiles][sr - s] = 0;
1034       csf->nfiles++;
1035     }
1036 }
1037
1038 struct addfileprovides_cbdata {
1039   int nfiles;
1040   Id *ids;
1041   char **dirs;
1042   char **names;
1043
1044   Id *dids;
1045
1046   Map providedids;
1047
1048   Map useddirs;
1049 };
1050
1051 static int
1052 addfileprovides_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
1053 {
1054   struct addfileprovides_cbdata *cbd = cbdata;
1055   int i;
1056
1057   if (!cbd->useddirs.size)
1058     {
1059       map_init(&cbd->useddirs, data->dirpool.ndirs + 1);
1060       for (i = 0; i < cbd->nfiles; i++)
1061         {
1062           Id did;
1063           if (MAPTST(&cbd->providedids, cbd->ids[i]))
1064             {
1065               cbd->dids[i] = 0;
1066               continue;
1067             }
1068           did = repodata_str2dir(data, cbd->dirs[i], 0);
1069           cbd->dids[i] = did;
1070           if (did)
1071             MAPSET(&cbd->useddirs, did);
1072         }
1073       repodata_free_dircache(data);
1074     }
1075   if (value->id >= data->dirpool.ndirs || !MAPTST(&cbd->useddirs, value->id))
1076     return 0;
1077   for (i = 0; i < cbd->nfiles; i++)
1078     {
1079       if (cbd->dids[i] != value->id)
1080         continue;
1081       if (!strcmp(cbd->names[i], value->str))
1082         break;
1083     }
1084   if (i == cbd->nfiles)
1085     return 0;
1086   s->provides = repo_addid_dep(s->repo, s->provides, cbd->ids[i], SOLVABLE_FILEMARKER);
1087   return 0;
1088 }
1089
1090 static void
1091 pool_addfileprovides_search(Pool *pool, struct addfileprovides_cbdata *cbd, struct searchfiles *sf, Repo *repoonly)
1092 {
1093   Id p;
1094   Repodata *data;
1095   Repo *repo;
1096   Queue fileprovidesq;
1097   int i, j, repoid, repodataid;
1098   int provstart, provend;
1099   Map donemap;
1100   int ndone, incomplete;
1101
1102   if (!pool->urepos)
1103     return;
1104
1105   cbd->nfiles = sf->nfiles;
1106   cbd->ids = sf->ids;
1107   cbd->dirs = sf->dirs;
1108   cbd->names = sf->names;
1109   cbd->dids = solv_realloc2(cbd->dids, sf->nfiles, sizeof(Id));
1110   map_init(&cbd->providedids, pool->ss.nstrings);
1111
1112   repoid = 1;
1113   repo = repoonly ? repoonly : pool->repos[repoid];
1114   map_init(&donemap, pool->nsolvables);
1115   queue_init(&fileprovidesq);
1116   provstart = provend = 0;
1117   for (;;)
1118     {
1119       if (!repo || repo->disabled)
1120         {
1121           if (repoonly || ++repoid == pool->nrepos)
1122             break;
1123           repo = pool->repos[repoid];
1124           continue;
1125         }
1126       ndone = 0;
1127       FOR_REPODATAS(repo, repodataid, data)
1128         {
1129           if (ndone >= repo->nsolvables)
1130             break;
1131
1132           if (repodata_lookup_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, &fileprovidesq))
1133             {
1134               map_empty(&cbd->providedids);
1135               for (i = 0; i < fileprovidesq.count; i++)
1136                 MAPSET(&cbd->providedids, fileprovidesq.elements[i]);
1137               provstart = data->start;
1138               provend = data->end;
1139               for (i = 0; i < cbd->nfiles; i++)
1140                 if (!MAPTST(&cbd->providedids, cbd->ids[i]))
1141                   break;
1142               if (i == cbd->nfiles)
1143                 {
1144                   /* great! no need to search files */
1145                   for (p = data->start; p < data->end; p++)
1146                     if (pool->solvables[p].repo == repo)
1147                       {
1148                         if (MAPTST(&donemap, p))
1149                           continue;
1150                         MAPSET(&donemap, p);
1151                         ndone++;
1152                       }
1153                   continue;
1154                 }
1155             }
1156
1157           if (!repodata_has_keyname(data, SOLVABLE_FILELIST))
1158             continue;
1159
1160           if (data->start < provstart || data->end > provend)
1161             {
1162               map_empty(&cbd->providedids);
1163               provstart = provend = 0;
1164             }
1165
1166           /* check if the data is incomplete */
1167           incomplete = 0;
1168           if (data->state == REPODATA_AVAILABLE)
1169             {
1170               for (j = 1; j < data->nkeys; j++)
1171                 if (data->keys[j].name != REPOSITORY_SOLVABLES && data->keys[j].name != SOLVABLE_FILELIST)
1172                   break;
1173               if (j < data->nkeys)
1174                 {
1175 #if 0
1176                   for (i = 0; i < cbd->nfiles; i++)
1177                     if (!MAPTST(&cbd->providedids, cbd->ids[i]) && !repodata_filelistfilter_matches(data, pool_id2str(pool, cbd->ids[i])))
1178                       printf("need complete filelist because of %s\n", pool_id2str(pool, cbd->ids[i]));
1179 #endif
1180                   for (i = 0; i < cbd->nfiles; i++)
1181                     if (!MAPTST(&cbd->providedids, cbd->ids[i]) && !repodata_filelistfilter_matches(data, pool_id2str(pool, cbd->ids[i])))
1182                       break;
1183                   if (i < cbd->nfiles)
1184                     incomplete = 1;
1185                 }
1186             }
1187
1188           /* do the search */
1189           map_init(&cbd->useddirs, 0);
1190           for (p = data->start; p < data->end; p++)
1191             if (pool->solvables[p].repo == repo)
1192               {
1193                 if (MAPTST(&donemap, p))
1194                   continue;
1195                 repodata_search(data, p, SOLVABLE_FILELIST, 0, addfileprovides_cb, cbd);
1196                 if (!incomplete)
1197                   {
1198                     MAPSET(&donemap, p);
1199                     ndone++;
1200                   }
1201               }
1202           map_free(&cbd->useddirs);
1203         }
1204
1205       if (repoonly || ++repoid == pool->nrepos)
1206         break;
1207       repo = pool->repos[repoid];
1208     }
1209   map_free(&donemap);
1210   queue_free(&fileprovidesq);
1211   map_free(&cbd->providedids);
1212 }
1213
1214 void
1215 pool_addfileprovides_queue(Pool *pool, Queue *idq, Queue *idqinst)
1216 {
1217   Solvable *s;
1218   Repo *installed, *repo;
1219   struct searchfiles sf, isf, *isfp;
1220   struct addfileprovides_cbdata cbd;
1221   int i;
1222   unsigned int now;
1223
1224   installed = pool->installed;
1225   now = solv_timems(0);
1226   memset(&sf, 0, sizeof(sf));
1227   map_init(&sf.seen, pool->ss.nstrings + pool->nrels);
1228   memset(&isf, 0, sizeof(isf));
1229   map_init(&isf.seen, pool->ss.nstrings + pool->nrels);
1230
1231   if (idq)
1232     queue_empty(idq);
1233   if (idqinst)
1234     queue_empty(idqinst);
1235   isfp = installed ? &isf : 0;
1236   for (i = 1, s = pool->solvables + i; i < pool->nsolvables; i++, s++)
1237     {
1238       repo = s->repo;
1239       if (!repo)
1240         continue;
1241       if (s->obsoletes)
1242         pool_addfileprovides_dep(pool, repo->idarraydata + s->obsoletes, &sf, isfp);
1243       if (s->conflicts)
1244         pool_addfileprovides_dep(pool, repo->idarraydata + s->conflicts, &sf, isfp);
1245       if (s->requires)
1246         pool_addfileprovides_dep(pool, repo->idarraydata + s->requires, &sf, isfp);
1247       if (s->recommends)
1248         pool_addfileprovides_dep(pool, repo->idarraydata + s->recommends, &sf, isfp);
1249       if (s->suggests)
1250         pool_addfileprovides_dep(pool, repo->idarraydata + s->suggests, &sf, isfp);
1251       if (s->supplements)
1252         pool_addfileprovides_dep(pool, repo->idarraydata + s->supplements, &sf, isfp);
1253       if (s->enhances)
1254         pool_addfileprovides_dep(pool, repo->idarraydata + s->enhances, &sf, isfp);
1255     }
1256   map_free(&sf.seen);
1257   map_free(&isf.seen);
1258   POOL_DEBUG(SOLV_DEBUG_STATS, "found %d file dependencies, %d installed file dependencies\n", sf.nfiles, isf.nfiles);
1259   cbd.dids = 0;
1260   if (sf.nfiles)
1261     {
1262 #if 0
1263       for (i = 0; i < sf.nfiles; i++)
1264         POOL_DEBUG(SOLV_DEBUG_STATS, "looking up %s in filelist\n", pool_id2str(pool, sf.ids[i]));
1265 #endif
1266       pool_addfileprovides_search(pool, &cbd, &sf, 0);
1267       if (idq)
1268         for (i = 0; i < sf.nfiles; i++)
1269           queue_push(idq, sf.ids[i]);
1270       if (idqinst)
1271         for (i = 0; i < sf.nfiles; i++)
1272           queue_push(idqinst, sf.ids[i]);
1273       solv_free(sf.ids);
1274       for (i = 0; i < sf.nfiles; i++)
1275         {
1276           solv_free(sf.dirs[i]);
1277           solv_free(sf.names[i]);
1278         }
1279       solv_free(sf.dirs);
1280       solv_free(sf.names);
1281     }
1282   if (isf.nfiles)
1283     {
1284 #if 0
1285       for (i = 0; i < isf.nfiles; i++)
1286         POOL_DEBUG(SOLV_DEBUG_STATS, "looking up %s in installed filelist\n", pool_id2str(pool, isf.ids[i]));
1287 #endif
1288       if (installed)
1289         pool_addfileprovides_search(pool, &cbd, &isf, installed);
1290       if (installed && idqinst)
1291         for (i = 0; i < isf.nfiles; i++)
1292           queue_pushunique(idqinst, isf.ids[i]);
1293       solv_free(isf.ids);
1294       for (i = 0; i < isf.nfiles; i++)
1295         {
1296           solv_free(isf.dirs[i]);
1297           solv_free(isf.names[i]);
1298         }
1299       solv_free(isf.dirs);
1300       solv_free(isf.names);
1301     }
1302   solv_free(cbd.dids);
1303   pool_freewhatprovides(pool);  /* as we have added provides */
1304   POOL_DEBUG(SOLV_DEBUG_STATS, "addfileprovides took %d ms\n", solv_timems(now));
1305 }
1306
1307 void
1308 pool_addfileprovides(Pool *pool)
1309 {
1310   pool_addfileprovides_queue(pool, 0, 0);
1311 }
1312
1313 void
1314 pool_search(Pool *pool, Id p, Id key, const char *match, int flags, int (*callback)(void *cbdata, Solvable *s, struct _Repodata *data, struct _Repokey *key, struct _KeyValue *kv), void *cbdata)
1315 {
1316   if (p)
1317     {
1318       if (pool->solvables[p].repo)
1319         repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1320       return;
1321     }
1322   /* FIXME: obey callback return value! */
1323   for (p = 1; p < pool->nsolvables; p++)
1324     if (pool->solvables[p].repo)
1325       repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1326 }
1327
1328 void
1329 pool_clear_pos(Pool *pool)
1330 {
1331   memset(&pool->pos, 0, sizeof(pool->pos));
1332 }
1333
1334
1335 void
1336 pool_set_languages(Pool *pool, const char **languages, int nlanguages)
1337 {
1338   int i;
1339
1340   pool->languagecache = solv_free(pool->languagecache);
1341   pool->languagecacheother = 0;
1342   if (pool->nlanguages)
1343     {
1344       for (i = 0; i < pool->nlanguages; i++)
1345         free((char *)pool->languages[i]);
1346       free(pool->languages);
1347     }
1348   pool->nlanguages = nlanguages;
1349   if (!nlanguages)
1350     return;
1351   pool->languages = solv_calloc(nlanguages, sizeof(const char **));
1352   for (i = 0; i < pool->nlanguages; i++)
1353     pool->languages[i] = solv_strdup(languages[i]);
1354 }
1355
1356 Id
1357 pool_id2langid(Pool *pool, Id id, const char *lang, int create)
1358 {
1359   const char *n;
1360   char buf[256], *p;
1361   int l;
1362
1363   if (!lang || !*lang)
1364     return id;
1365   n = pool_id2str(pool, id);
1366   l = strlen(n) + strlen(lang) + 2;
1367   if (l > sizeof(buf))
1368     p = solv_malloc(strlen(n) + strlen(lang) + 2);
1369   else
1370     p = buf;
1371   sprintf(p, "%s:%s", n, lang);
1372   id = pool_str2id(pool, p, create);
1373   if (p != buf)
1374     free(p);
1375   return id;
1376 }
1377
1378 char *
1379 pool_alloctmpspace(Pool *pool, int len)
1380 {
1381   int n = pool->tmpspace.n;
1382   if (!len)
1383     return 0;
1384   if (len > pool->tmpspace.len[n])
1385     {
1386       pool->tmpspace.buf[n] = solv_realloc(pool->tmpspace.buf[n], len + 32);
1387       pool->tmpspace.len[n] = len + 32;
1388     }
1389   pool->tmpspace.n = (n + 1) % POOL_TMPSPACEBUF;
1390   return pool->tmpspace.buf[n];
1391 }
1392
1393 static char *
1394 pool_alloctmpspace_free(Pool *pool, const char *space, int len)
1395 {
1396   if (space)
1397     {
1398       int n, oldn;
1399       n = oldn = pool->tmpspace.n;
1400       for (;;)
1401         {
1402           if (!n--)
1403             n = POOL_TMPSPACEBUF - 1;
1404           if (n == oldn)
1405             break;
1406           if (pool->tmpspace.buf[n] != space)
1407             continue;
1408           if (len > pool->tmpspace.len[n])
1409             {
1410               pool->tmpspace.buf[n] = solv_realloc(pool->tmpspace.buf[n], len + 32);
1411               pool->tmpspace.len[n] = len + 32;
1412             }
1413           return pool->tmpspace.buf[n];
1414         }
1415     }
1416   return 0;
1417 }
1418
1419 void
1420 pool_freetmpspace(Pool *pool, const char *space)
1421 {
1422   int n = pool->tmpspace.n;
1423   if (!space)
1424     return;
1425   n = (n + (POOL_TMPSPACEBUF - 1)) % POOL_TMPSPACEBUF;
1426   if (pool->tmpspace.buf[n] == space)
1427     pool->tmpspace.n = n;
1428 }
1429
1430 char *
1431 pool_tmpjoin(Pool *pool, const char *str1, const char *str2, const char *str3)
1432 {
1433   int l1, l2, l3;
1434   char *s, *str;
1435   l1 = str1 ? strlen(str1) : 0;
1436   l2 = str2 ? strlen(str2) : 0;
1437   l3 = str3 ? strlen(str3) : 0;
1438   s = str = pool_alloctmpspace(pool, l1 + l2 + l3 + 1);
1439   if (l1)
1440     {
1441       strcpy(s, str1);
1442       s += l1;
1443     }
1444   if (l2)
1445     {
1446       strcpy(s, str2);
1447       s += l2;
1448     }
1449   if (l3)
1450     {
1451       strcpy(s, str3);
1452       s += l3;
1453     }
1454   *s = 0;
1455   return str;
1456 }
1457
1458 char *
1459 pool_tmpappend(Pool *pool, const char *str1, const char *str2, const char *str3)
1460 {
1461   int l1, l2, l3;
1462   char *s, *str;
1463
1464   l1 = str1 ? strlen(str1) : 0;
1465   l2 = str2 ? strlen(str2) : 0;
1466   l3 = str3 ? strlen(str3) : 0;
1467   str = pool_alloctmpspace_free(pool, str1, l1 + l2 + l3 + 1);
1468   if (str)
1469     str1 = str;
1470   else
1471     str = pool_alloctmpspace(pool, l1 + l2 + l3 + 1);
1472   s = str;
1473   if (l1)
1474     {
1475       if (s != str1)
1476         strcpy(s, str1);
1477       s += l1;
1478     }
1479   if (l2)
1480     {
1481       strcpy(s, str2);
1482       s += l2;
1483     }
1484   if (l3)
1485     {
1486       strcpy(s, str3);
1487       s += l3;
1488     }
1489   *s = 0;
1490   return str;
1491 }
1492
1493 const char *
1494 pool_bin2hex(Pool *pool, const unsigned char *buf, int len)
1495 {
1496   char *s;
1497   if (!len)
1498     return "";
1499   s = pool_alloctmpspace(pool, 2 * len + 1);
1500   solv_bin2hex(buf, len, s);
1501   return s;
1502 }
1503
1504 /*******************************************************************/
1505
1506 struct mptree {
1507   Id sibling;
1508   Id child;
1509   const char *comp;
1510   int compl;
1511   Id mountpoint;
1512 };
1513
1514 struct ducbdata {
1515   DUChanges *mps;
1516   struct mptree *mptree;
1517   int addsub;
1518   int hasdu;
1519
1520   Id *dirmap;
1521   int nmap;
1522   Repodata *olddata;
1523 };
1524
1525
1526 static int
1527 solver_fill_DU_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
1528 {
1529   struct ducbdata *cbd = cbdata;
1530   Id mp;
1531
1532   if (data != cbd->olddata)
1533     {
1534       Id dn, mp, comp, *dirmap, *dirs;
1535       int i, compl;
1536       const char *compstr;
1537       struct mptree *mptree;
1538
1539       /* create map from dir to mptree */
1540       cbd->dirmap = solv_free(cbd->dirmap);
1541       cbd->nmap = 0;
1542       dirmap = solv_calloc(data->dirpool.ndirs, sizeof(Id));
1543       mptree = cbd->mptree;
1544       mp = 0;
1545       for (dn = 2, dirs = data->dirpool.dirs + dn; dn < data->dirpool.ndirs; dn++)
1546         {
1547           comp = *dirs++;
1548           if (comp <= 0)
1549             {
1550               mp = dirmap[-comp];
1551               continue;
1552             }
1553           if (mp < 0)
1554             {
1555               /* unconnected */
1556               dirmap[dn] = mp;
1557               continue;
1558             }
1559           if (!mptree[mp].child)
1560             {
1561               dirmap[dn] = -mp;
1562               continue;
1563             }
1564           if (data->localpool)
1565             compstr = stringpool_id2str(&data->spool, comp);
1566           else
1567             compstr = pool_id2str(data->repo->pool, comp);
1568           compl = strlen(compstr);
1569           for (i = mptree[mp].child; i; i = mptree[i].sibling)
1570             if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1571               break;
1572           dirmap[dn] = i ? i : -mp;
1573         }
1574       /* change dirmap to point to mountpoint instead of mptree */
1575       for (dn = 0; dn < data->dirpool.ndirs; dn++)
1576         {
1577           mp = dirmap[dn];
1578           dirmap[dn] = mptree[mp > 0 ? mp : -mp].mountpoint;
1579         }
1580       cbd->dirmap = dirmap;
1581       cbd->nmap = data->dirpool.ndirs;
1582       cbd->olddata = data;
1583     }
1584   cbd->hasdu = 1;
1585   if (value->id < 0 || value->id >= cbd->nmap)
1586     return 0;
1587   mp = cbd->dirmap[value->id];
1588   if (mp < 0)
1589     return 0;
1590   if (cbd->addsub > 0)
1591     {
1592       cbd->mps[mp].kbytes += value->num;
1593       cbd->mps[mp].files += value->num2;
1594     }
1595   else
1596     {
1597       cbd->mps[mp].kbytes -= value->num;
1598       cbd->mps[mp].files -= value->num2;
1599     }
1600   return 0;
1601 }
1602
1603 static void
1604 propagate_mountpoints(struct mptree *mptree, int pos, Id mountpoint)
1605 {
1606   int i;
1607   if (mptree[pos].mountpoint == -1)
1608     mptree[pos].mountpoint = mountpoint;
1609   else
1610     mountpoint = mptree[pos].mountpoint;
1611   for (i = mptree[pos].child; i; i = mptree[i].sibling)
1612     propagate_mountpoints(mptree, i, mountpoint);
1613 }
1614
1615 #define MPTREE_BLOCK 15
1616
1617 void
1618 pool_calc_duchanges(Pool *pool, Map *installedmap, DUChanges *mps, int nmps)
1619 {
1620   char *p;
1621   const char *path, *compstr;
1622   struct mptree *mptree;
1623   int i, nmptree;
1624   int pos, compl;
1625   int mp;
1626   struct ducbdata cbd;
1627   Solvable *s;
1628   Id sp;
1629   Map ignoredu;
1630   Repo *oldinstalled = pool->installed;
1631
1632   memset(&ignoredu, 0, sizeof(ignoredu));
1633   cbd.mps = mps;
1634   cbd.addsub = 0;
1635   cbd.dirmap = 0;
1636   cbd.nmap = 0;
1637   cbd.olddata = 0;
1638
1639   mptree = solv_extend_resize(0, 1, sizeof(struct mptree), MPTREE_BLOCK);
1640
1641   /* our root node */
1642   mptree[0].sibling = 0;
1643   mptree[0].child = 0;
1644   mptree[0].comp = 0;
1645   mptree[0].compl = 0;
1646   mptree[0].mountpoint = -1;
1647   nmptree = 1;
1648   
1649   /* create component tree */
1650   for (mp = 0; mp < nmps; mp++)
1651     {
1652       mps[mp].kbytes = 0;
1653       mps[mp].files = 0;
1654       pos = 0;
1655       path = mps[mp].path;
1656       while(*path == '/')
1657         path++;
1658       while (*path)
1659         {
1660           if ((p = strchr(path, '/')) == 0)
1661             {
1662               compstr = path;
1663               compl = strlen(compstr);
1664               path += compl;
1665             }
1666           else
1667             {
1668               compstr = path;
1669               compl = p - path;
1670               path = p + 1;
1671               while(*path == '/')
1672                 path++;
1673             }
1674           for (i = mptree[pos].child; i; i = mptree[i].sibling)
1675             if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1676               break;
1677           if (!i)
1678             {
1679               /* create new node */
1680               mptree = solv_extend(mptree, nmptree, 1, sizeof(struct mptree), MPTREE_BLOCK);
1681               i = nmptree++;
1682               mptree[i].sibling = mptree[pos].child;
1683               mptree[i].child = 0;
1684               mptree[i].comp = compstr;
1685               mptree[i].compl = compl;
1686               mptree[i].mountpoint = -1;
1687               mptree[pos].child = i;
1688             }
1689           pos = i;
1690         }
1691       mptree[pos].mountpoint = mp;
1692     }
1693
1694   propagate_mountpoints(mptree, 0, mptree[0].mountpoint);
1695
1696 #if 0
1697   for (i = 0; i < nmptree; i++)
1698     {
1699       printf("#%d sibling: %d\n", i, mptree[i].sibling);
1700       printf("#%d child: %d\n", i, mptree[i].child);
1701       printf("#%d comp: %s\n", i, mptree[i].comp);
1702       printf("#%d compl: %d\n", i, mptree[i].compl);
1703       printf("#%d mountpont: %d\n", i, mptree[i].mountpoint);
1704     }
1705 #endif
1706
1707   cbd.mptree = mptree;
1708   cbd.addsub = 1;
1709   for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
1710     {
1711       if (!s->repo || (oldinstalled && s->repo == oldinstalled))
1712         continue;
1713       if (!MAPTST(installedmap, sp))
1714         continue;
1715       cbd.hasdu = 0;
1716       repo_search(s->repo, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1717       if (!cbd.hasdu && oldinstalled)
1718         {
1719           Id op, opp;
1720           /* no du data available, ignore data of all installed solvables we obsolete */
1721           if (!ignoredu.map)
1722             map_init(&ignoredu, oldinstalled->end - oldinstalled->start);
1723           if (s->obsoletes)
1724             {
1725               Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
1726               while ((obs = *obsp++) != 0)
1727                 FOR_PROVIDES(op, opp, obs)
1728                   if (op >= oldinstalled->start && op < oldinstalled->end)
1729                     MAPSET(&ignoredu, op - oldinstalled->start);
1730             }
1731           FOR_PROVIDES(op, opp, s->name)
1732             if (pool->solvables[op].name == s->name)
1733               if (op >= oldinstalled->start && op < oldinstalled->end)
1734                 MAPSET(&ignoredu, op - oldinstalled->start);
1735         }
1736     }
1737   cbd.addsub = -1;
1738   if (oldinstalled)
1739     {
1740       /* assumes we allways have du data for installed solvables */
1741       FOR_REPO_SOLVABLES(oldinstalled, sp, s)
1742         {
1743           if (MAPTST(installedmap, sp))
1744             continue;
1745           if (ignoredu.map && MAPTST(&ignoredu, sp - oldinstalled->start))
1746             continue;
1747           repo_search(oldinstalled, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1748         }
1749     }
1750   if (ignoredu.map)
1751     map_free(&ignoredu);
1752   solv_free(cbd.dirmap);
1753   solv_free(mptree);
1754 }
1755
1756 int
1757 pool_calc_installsizechange(Pool *pool, Map *installedmap)
1758 {
1759   Id sp;
1760   Solvable *s;
1761   int change = 0;
1762   Repo *oldinstalled = pool->installed;
1763
1764   for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
1765     {
1766       if (!s->repo || (oldinstalled && s->repo == oldinstalled))
1767         continue;
1768       if (!MAPTST(installedmap, sp))
1769         continue;
1770       change += solvable_lookup_sizek(s, SOLVABLE_INSTALLSIZE, 0);
1771     }
1772   if (oldinstalled)
1773     {
1774       FOR_REPO_SOLVABLES(oldinstalled, sp, s)
1775         {
1776           if (MAPTST(installedmap, sp))
1777             continue;
1778           change -= solvable_lookup_sizek(s, SOLVABLE_INSTALLSIZE, 0);
1779         }
1780     }
1781   return change;
1782 }
1783
1784 /* map:
1785  *  1: installed
1786  *  2: conflicts with installed
1787  *  8: interesting (only true if installed)
1788  * 16: undecided
1789  */
1790  
1791 static inline Id dep2name(Pool *pool, Id dep)
1792 {
1793   while (ISRELDEP(dep))
1794     {
1795       Reldep *rd = rd = GETRELDEP(pool, dep);
1796       dep = rd->name;
1797     }
1798   return dep;
1799 }
1800
1801 static int providedbyinstalled_multiversion(Pool *pool, unsigned char *map, Id n, Id con) 
1802 {
1803   Id p, pp;
1804   Solvable *sn = pool->solvables + n; 
1805
1806   FOR_PROVIDES(p, pp, sn->name)
1807     {    
1808       Solvable *s = pool->solvables + p; 
1809       if (s->name != sn->name || s->arch != sn->arch)
1810         continue;
1811       if ((map[p] & 9) != 9)
1812         continue;
1813       if (pool_match_nevr(pool, pool->solvables + p, con))
1814         continue;
1815       return 1;         /* found installed package that doesn't conflict */
1816     }
1817   return 0;
1818 }
1819
1820 static inline int providedbyinstalled(Pool *pool, unsigned char *map, Id dep, int ispatch, Map *noobsoletesmap)
1821 {
1822   Id p, pp;
1823   int r = 0;
1824   FOR_PROVIDES(p, pp, dep)
1825     {
1826       if (p == SYSTEMSOLVABLE)
1827         return 1;       /* always boring, as never constraining */
1828       if (ispatch && !pool_match_nevr(pool, pool->solvables + p, dep))
1829         continue;
1830       if (ispatch && noobsoletesmap && noobsoletesmap->size && MAPTST(noobsoletesmap, p) && ISRELDEP(dep))
1831         if (providedbyinstalled_multiversion(pool, map, p, dep))
1832           continue;
1833       if ((map[p] & 9) == 9)
1834         return 9;
1835       r |= map[p] & 17;
1836     }
1837   return r;
1838 }
1839
1840 /*
1841  * pool_trivial_installable - calculate if a set of solvables is
1842  * trivial installable without any other installs/deinstalls of
1843  * packages not belonging to the set.
1844  *
1845  * the state is returned in the result queue:
1846  * 1:  solvable is installable without any other package changes
1847  * 0:  solvable is not installable
1848  * -1: solvable is installable, but doesn't constrain any installed packages
1849  */
1850
1851 void
1852 pool_trivial_installable_noobsoletesmap(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res, Map *noobsoletesmap)
1853 {
1854   int i, r, m, did;
1855   Id p, *dp, con, *conp, req, *reqp;
1856   unsigned char *map;
1857   Solvable *s;
1858
1859   map = solv_calloc(pool->nsolvables, 1);
1860   for (p = 1; p < pool->nsolvables; p++)
1861     {
1862       if (!MAPTST(installedmap, p))
1863         continue;
1864       map[p] |= 9;
1865       s = pool->solvables + p;
1866       if (!s->conflicts)
1867         continue;
1868       conp = s->repo->idarraydata + s->conflicts;
1869       while ((con = *conp++) != 0)
1870         {
1871           dp = pool_whatprovides_ptr(pool, con);
1872           for (; *dp; dp++)
1873             map[p] |= 2;        /* XXX: self conflict ? */
1874         }
1875     }
1876   for (i = 0; i < pkgs->count; i++)
1877     map[pkgs->elements[i]] = 16;
1878
1879   for (i = 0, did = 0; did < pkgs->count; i++, did++)
1880     {
1881       if (i == pkgs->count)
1882         i = 0;
1883       p = pkgs->elements[i];
1884       if ((map[p] & 16) == 0)
1885         continue;
1886       if ((map[p] & 2) != 0)
1887         {
1888           map[p] = 2;
1889           continue;
1890         }
1891       s = pool->solvables + p;
1892       m = 1;
1893       if (s->requires)
1894         {
1895           reqp = s->repo->idarraydata + s->requires;
1896           while ((req = *reqp++) != 0)
1897             {
1898               if (req == SOLVABLE_PREREQMARKER)
1899                 continue;
1900               r = providedbyinstalled(pool, map, req, 0, 0);
1901               if (!r)
1902                 {
1903                   /* decided and miss */
1904                   map[p] = 2;
1905                   break;
1906                 }
1907               m |= r;   /* 1 | 9 | 16 | 17 */
1908             }
1909           if (req)
1910             continue;
1911           if ((m & 9) == 9)
1912             m = 9;
1913         }
1914       if (s->conflicts)
1915         {
1916           int ispatch = 0;      /* see solver.c patch handling */
1917
1918           if (!strncmp("patch:", pool_id2str(pool, s->name), 6))
1919             ispatch = 1;
1920           conp = s->repo->idarraydata + s->conflicts;
1921           while ((con = *conp++) != 0)
1922             {
1923               if ((providedbyinstalled(pool, map, con, ispatch, noobsoletesmap) & 1) != 0)
1924                 {
1925                   map[p] = 2;
1926                   break;
1927                 }
1928               if ((m == 1 || m == 17) && ISRELDEP(con))
1929                 {
1930                   con = dep2name(pool, con);
1931                   if ((providedbyinstalled(pool, map, con, ispatch, noobsoletesmap) & 1) != 0)
1932                     m = 9;
1933                 }
1934             }
1935           if (con)
1936             continue;   /* found a conflict */
1937         }
1938 #if 0
1939       if (s->repo && s->repo != oldinstalled)
1940         {
1941           Id p2, obs, *obsp, *pp;
1942           Solvable *s2;
1943           if (s->obsoletes)
1944             {
1945               obsp = s->repo->idarraydata + s->obsoletes;
1946               while ((obs = *obsp++) != 0)
1947                 {
1948                   if ((providedbyinstalled(pool, map, obs, 0, 0) & 1) != 0)
1949                     {
1950                       map[p] = 2;
1951                       break;
1952                     }
1953                 }
1954               if (obs)
1955                 continue;
1956             }
1957           FOR_PROVIDES(p2, pp, s->name)
1958             {
1959               s2 = pool->solvables + p2;
1960               if (s2->name == s->name && (map[p2] & 1) != 0)
1961                 {
1962                   map[p] = 2;
1963                   break;
1964                 }
1965             }
1966           if (p2)
1967             continue;
1968         }
1969 #endif
1970       if (m != map[p])
1971         {
1972           map[p] = m;
1973           did = 0;
1974         }
1975     }
1976   queue_free(res);
1977   queue_init_clone(res, pkgs);
1978   for (i = 0; i < pkgs->count; i++)
1979     {
1980       m = map[pkgs->elements[i]];
1981       if ((m & 9) == 9)
1982         r = 1;
1983       else if (m & 1)
1984         r = -1;
1985       else
1986         r = 0;
1987       res->elements[i] = r;
1988     }
1989   free(map);
1990 }
1991
1992 void
1993 pool_trivial_installable(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res)
1994 {
1995   pool_trivial_installable_noobsoletesmap(pool, installedmap, pkgs, res, 0);
1996 }
1997
1998 const char *
1999 pool_lookup_str(Pool *pool, Id entry, Id keyname)
2000 {
2001   if (entry == SOLVID_POS && pool->pos.repo)
2002     return repodata_lookup_str(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname);
2003   if (entry <= 0)
2004     return 0;
2005   return solvable_lookup_str(pool->solvables + entry, keyname);
2006 }
2007
2008 Id
2009 pool_lookup_id(Pool *pool, Id entry, Id keyname)
2010 {
2011   if (entry == SOLVID_POS && pool->pos.repo)
2012     {
2013       Repodata *data = pool->pos.repo->repodata + pool->pos.repodataid;
2014       Id id = repodata_lookup_id(data, SOLVID_POS, keyname);
2015       return data->localpool ? repodata_globalize_id(data, id, 1) : id;
2016     }
2017   if (entry <= 0)
2018     return 0;
2019   return solvable_lookup_id(pool->solvables + entry, keyname);
2020 }
2021
2022 unsigned long long
2023 pool_lookup_num(Pool *pool, Id entry, Id keyname, unsigned long long notfound)
2024 {
2025   if (entry == SOLVID_POS && pool->pos.repo)
2026     {
2027       unsigned long long value;
2028       if (repodata_lookup_num(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname, &value))
2029         return value;
2030       return notfound;
2031     }
2032   if (entry <= 0)
2033     return notfound;
2034   return solvable_lookup_num(pool->solvables + entry, keyname, notfound);
2035 }
2036
2037 int
2038 pool_lookup_void(Pool *pool, Id entry, Id keyname)
2039 {
2040   if (entry == SOLVID_POS && pool->pos.repo)
2041     return repodata_lookup_void(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname);
2042   if (entry <= 0)
2043     return 0;
2044   return solvable_lookup_void(pool->solvables + entry, keyname);
2045 }
2046
2047 const unsigned char *
2048 pool_lookup_bin_checksum(Pool *pool, Id entry, Id keyname, Id *typep)
2049 {
2050   if (entry == SOLVID_POS && pool->pos.repo)
2051     return repodata_lookup_bin_checksum(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname, typep);
2052   if (entry <= 0)
2053     return 0;
2054   return solvable_lookup_bin_checksum(pool->solvables + entry, keyname, typep);
2055 }
2056
2057 const char *
2058 pool_lookup_checksum(Pool *pool, Id entry, Id keyname, Id *typep)
2059 {
2060   if (entry == SOLVID_POS && pool->pos.repo)
2061     {
2062       const unsigned char *chk = repodata_lookup_bin_checksum(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname, typep);
2063       return chk ? repodata_chk2str(pool->pos.repo->repodata + pool->pos.repodataid, *typep, chk) : 0;
2064     }
2065   if (entry <= 0)
2066     return 0;
2067   return solvable_lookup_checksum(pool->solvables + entry, keyname, typep);
2068 }
2069
2070 void
2071 pool_add_fileconflicts_deps(Pool *pool, Queue *conflicts)
2072 {
2073   int hadhashes = pool->relhashtbl ? 1 : 0;
2074   Solvable *s;
2075   Id fn, p, q, md5;
2076   Id id;
2077   int i;
2078
2079   if (!conflicts->count)
2080     return;
2081   pool_freewhatprovides(pool);
2082   for (i = 0; i < conflicts->count; i += 5)
2083     {
2084       fn = conflicts->elements[i];
2085       p = conflicts->elements[i + 1];
2086       md5 = conflicts->elements[i + 2];
2087       q = conflicts->elements[i + 3];
2088       id = pool_rel2id(pool, fn, md5, REL_FILECONFLICT, 1);
2089       s = pool->solvables + p;
2090       if (!s->repo)
2091         continue;
2092       s->provides = repo_addid_dep(s->repo, s->provides, id, SOLVABLE_FILEMARKER);
2093       s = pool->solvables + q;
2094       if (!s->repo)
2095         continue;
2096       s->conflicts = repo_addid_dep(s->repo, s->conflicts, id, 0);
2097     }
2098   if (!hadhashes)
2099     pool_freeidhashes(pool);
2100 }
2101
2102 char *
2103 pool_prepend_rootdir(Pool *pool, const char *path)
2104 {
2105   if (!path)
2106     return 0;
2107   if (!pool->rootdir)
2108     return solv_strdup(path);
2109   return solv_dupjoin(pool->rootdir, "/", *path == '/' ? path + 1 : path);
2110 }
2111
2112 const char *
2113 pool_prepend_rootdir_tmp(Pool *pool, const char *path)
2114 {
2115   if (!path)
2116     return 0;
2117   if (!pool->rootdir)
2118     return path;
2119   return pool_tmpjoin(pool, pool->rootdir, "/", *path == '/' ? path + 1 : path);
2120 }
2121
2122 void
2123 pool_set_rootdir(Pool *pool, const char *rootdir)
2124 {
2125   solv_free(pool->rootdir);
2126   pool->rootdir = solv_strdup(rootdir);
2127 }
2128
2129 const char *
2130 pool_get_rootdir(Pool *pool)
2131 {
2132   return pool->rootdir;
2133 }
2134
2135 /* EOF */