dddb46dd43b0bd2221de83d862f772918792b58d
[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 #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 *)sat_calloc(1, sizeof(*pool));
44
45   stringpool_init (&pool->ss, initpool_data);
46
47   /* alloc space for RelDep 0 */
48   pool->rels = sat_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 = sat_extend_resize(0, 2, sizeof(Solvable), SOLVABLE_BLOCK);
54   pool->nsolvables = 2;
55   memset(pool->solvables, 0, 2 * sizeof(Solvable));
56   s = pool->solvables + SYSTEMSOLVABLE;
57   s->name = SYSTEM_SYSTEM;
58   s->arch = ARCH_NOARCH;
59   s->evr = ID_EMPTY;
60
61   queue_init(&pool->vendormap);
62
63   pool->debugmask = SAT_DEBUG_RESULT;   /* FIXME */
64   return pool;
65 }
66
67
68 /* free all the resources of our pool */
69 void
70 pool_free(Pool *pool)
71 {
72   int i;
73
74   pool_freewhatprovides(pool);
75   pool_freeidhashes(pool);
76   repo_freeallrepos(pool, 1);
77   sat_free(pool->id2arch);
78   sat_free(pool->solvables);
79   stringpool_free(&pool->ss);
80   sat_free(pool->rels);
81   queue_free(&pool->vendormap);
82   for (i = 0; i < POOL_TMPSPACEBUF; i++)
83     sat_free(pool->tmpspacebuf[i]);
84   for (i = 0; i < pool->nlanguages; i++)
85     free((char *)pool->languages[i]);
86   sat_free(pool->languages);
87   sat_free(pool->languagecache);
88   sat_free(pool);
89 }
90
91 Id
92 pool_add_solvable(Pool *pool)
93 {
94   pool->solvables = sat_extend(pool->solvables, pool->nsolvables, 1, sizeof(Solvable), SOLVABLE_BLOCK);
95   memset(pool->solvables + pool->nsolvables, 0, sizeof(Solvable));
96   return pool->nsolvables++;
97 }
98
99 Id
100 pool_add_solvable_block(Pool *pool, int count)
101 {
102   Id nsolvables = pool->nsolvables;
103   if (!count)
104     return nsolvables;
105   pool->solvables = sat_extend(pool->solvables, pool->nsolvables, count, sizeof(Solvable), SOLVABLE_BLOCK);
106   memset(pool->solvables + nsolvables, 0, sizeof(Solvable) * count);
107   pool->nsolvables += count;
108   return nsolvables;
109 }
110
111 void
112 pool_free_solvable_block(Pool *pool, Id start, int count, int reuseids)
113 {
114   if (!count)
115     return;
116   if (reuseids && start + count == pool->nsolvables)
117     {
118       /* might want to shrink solvable array */
119       pool->nsolvables = start;
120       return;
121     }
122   memset(pool->solvables + start, 0, sizeof(Solvable) * count);
123 }
124
125
126 void
127 pool_set_installed(Pool *pool, Repo *installed)
128 {
129   if (pool->installed == installed)
130     return;
131   pool->installed = installed;
132   pool_freewhatprovides(pool);
133 }
134
135 static Pool *pool_shrink_whatprovides_sortcmp_data;
136
137 static int
138 pool_shrink_whatprovides_sortcmp(const void *ap, const void *bp)
139 {
140   int r;
141   Pool *pool = pool_shrink_whatprovides_sortcmp_data;
142   Id oa, ob, *da, *db;
143   oa = pool->whatprovides[*(Id *)ap];
144   ob = pool->whatprovides[*(Id *)bp];
145   if (oa == ob)
146     return *(Id *)ap - *(Id *)bp;
147   if (!oa)
148     return -1;
149   if (!ob)
150     return 1;
151   da = pool->whatprovidesdata + oa;
152   db = pool->whatprovidesdata + ob;
153   while (*db)
154     if ((r = (*da++ - *db++)) != 0)
155       return r;
156   if (*da)
157     return *da;
158   return *(Id *)ap - *(Id *)bp;
159 }
160
161 /*
162  * pool_shrink_whatprovides  - unify whatprovides data
163  *
164  * whatprovides_rel must be empty for this to work!
165  *
166  */
167 static void
168 pool_shrink_whatprovides(Pool *pool)
169 {
170   Id i, id;
171   Id *sorted;
172   Id lastid, *last, *dp, *lp;
173   Offset o;
174   int r;
175
176   if (pool->ss.nstrings < 3)
177     return;
178   sorted = sat_malloc2(pool->ss.nstrings, sizeof(Id));
179   for (id = 0; id < pool->ss.nstrings; id++)
180     sorted[id] = id;
181   pool_shrink_whatprovides_sortcmp_data = pool;
182   qsort(sorted + 1, pool->ss.nstrings - 1, sizeof(Id), pool_shrink_whatprovides_sortcmp);
183   last = 0;
184   lastid = 0;
185   for (i = 1; i < pool->ss.nstrings; i++)
186     {
187       id = sorted[i];
188       o = pool->whatprovides[id];
189       if (o == 0 || o == 1)
190         continue;
191       dp = pool->whatprovidesdata + o;
192       if (last)
193         {
194           lp = last;
195           while (*dp)   
196             if (*dp++ != *lp++)
197               {
198                 last = 0;
199                 break;
200               }
201           if (last && *lp)
202             last = 0;
203           if (last)
204             {
205               pool->whatprovides[id] = -lastid;
206               continue;
207             }
208         }
209       last = pool->whatprovidesdata + o;
210       lastid = id;
211     }
212   sat_free(sorted);
213   dp = pool->whatprovidesdata + 2;
214   for (id = 1; id < pool->ss.nstrings; id++)
215     {
216       o = pool->whatprovides[id];
217       if (o == 0 || o == 1)
218         continue;
219       if ((Id)o < 0)
220         {
221           i = -(Id)o;
222           if (i >= id)
223             abort();
224           pool->whatprovides[id] = pool->whatprovides[i];
225           continue;
226         }
227       lp = pool->whatprovidesdata + o;
228       if (lp < dp)
229         abort();
230       pool->whatprovides[id] = dp - pool->whatprovidesdata;
231       while ((*dp++ = *lp++) != 0)
232         ;
233     }
234   o = dp - pool->whatprovidesdata;
235   POOL_DEBUG(SAT_DEBUG_STATS, "shrunk whatprovidesdata from %d to %d\n", pool->whatprovidesdataoff, o);
236   if (pool->whatprovidesdataoff == o)
237     return;
238   r = pool->whatprovidesdataoff - o;
239   pool->whatprovidesdataoff = o;
240   pool->whatprovidesdata = sat_realloc(pool->whatprovidesdata, (o + pool->whatprovidesdataleft) * sizeof(Id));
241   if (r > pool->whatprovidesdataleft)
242     r = pool->whatprovidesdataleft;
243   memset(pool->whatprovidesdata + o, 0, r * sizeof(Id));
244 }
245
246
247 /*
248  * pool_createwhatprovides()
249  * 
250  * create hashes over pool of solvables to ease provide lookups
251  * 
252  */
253 void
254 pool_createwhatprovides(Pool *pool)
255 {
256   int i, num, np, extra;
257   Offset off;
258   Solvable *s;
259   Id id;
260   Offset *idp, n;
261   Offset *whatprovides;
262   Id *whatprovidesdata, *d;
263   Repo *installed = pool->installed;
264   unsigned int now;
265
266   now = sat_timems(0);
267   POOL_DEBUG(SAT_DEBUG_STATS, "number of solvables: %d\n", pool->nsolvables);
268   POOL_DEBUG(SAT_DEBUG_STATS, "number of ids: %d + %d\n", pool->ss.nstrings, pool->nrels);
269
270   pool_freeidhashes(pool);      /* XXX: should not be here! */
271   pool_freewhatprovides(pool);
272   num = pool->ss.nstrings;
273   pool->whatprovides = whatprovides = sat_calloc_block(num, sizeof(Offset), WHATPROVIDES_BLOCK);
274   pool->whatprovides_rel = sat_calloc_block(pool->nrels, sizeof(Offset), WHATPROVIDES_BLOCK);
275
276   /* count providers for each name */
277   for (i = 1; i < pool->nsolvables; i++)
278     {
279       Id *pp;
280       s = pool->solvables + i;
281       if (!s->provides)
282         continue;
283       /* we always need the installed solvable in the whatprovides data,
284          otherwise obsoletes/conflicts on them won't work */
285       if (s->repo != installed && !pool_installable(pool, s))
286         continue;
287       pp = s->repo->idarraydata + s->provides;
288       while ((id = *pp++) != ID_NULL)
289         {
290           while (ISRELDEP(id))
291             {
292               Reldep *rd = GETRELDEP(pool, id);
293               id = rd->name;
294             }
295           whatprovides[id]++;          /* inc count of providers */
296         }
297     }
298
299   off = 2;      /* first entry is undef, second is empty list */
300   idp = whatprovides;
301   np = 0;                              /* number of names provided */
302   for (i = 0; i < num; i++, idp++)
303     {
304       n = *idp;
305       if (!n)                          /* no providers */
306         continue;
307       *idp = off;                      /* move from counts to offsets into whatprovidesdata */
308       off += n + 1;                    /* make space for all providers + terminating ID_NULL */
309       np++;                            /* inc # of provider 'slots' */
310     }
311
312   POOL_DEBUG(SAT_DEBUG_STATS, "provide ids: %d\n", np);
313
314   /* reserve some space for relation data */
315   extra = 2 * pool->nrels;
316   if (extra < 256)
317     extra = 256;
318
319   POOL_DEBUG(SAT_DEBUG_STATS, "provide space needed: %d + %d\n", off, extra);
320
321   /* alloc space for all providers + extra */
322   whatprovidesdata = sat_calloc(off + extra, sizeof(Id));
323
324   /* now fill data for all provides */
325   for (i = 1; i < pool->nsolvables; i++)
326     {
327       Id *pp;
328       s = pool->solvables + i;
329       if (!s->provides)
330         continue;
331       if (s->repo != installed && !pool_installable(pool, s))
332         continue;
333
334       /* for all provides of this solvable */
335       pp = s->repo->idarraydata + s->provides;
336       while ((id = *pp++) != 0)
337         {
338           while (ISRELDEP(id))
339             {
340               Reldep *rd = GETRELDEP(pool, id);
341               id = rd->name;
342             }
343           d = whatprovidesdata + whatprovides[id];   /* offset into whatprovidesdata */
344           if (*d)
345             {
346               d++;
347               while (*d)               /* find free slot */
348                 d++;
349               if (d[-1] == i)          /* solvable already tacked at end ? */
350                 continue;              /* Y: skip, on to next provides */
351             }
352           *d = i;                      /* put solvable Id into data */
353         }
354     }
355   pool->whatprovidesdata = whatprovidesdata;
356   pool->whatprovidesdataoff = off;
357   pool->whatprovidesdataleft = extra;
358   pool_shrink_whatprovides(pool);
359   POOL_DEBUG(SAT_DEBUG_STATS, "whatprovides memory used: %d K id array, %d K data\n", (pool->ss.nstrings + pool->nrels + WHATPROVIDES_BLOCK) / (1024/sizeof(Id)), (pool->whatprovidesdataoff + pool->whatprovidesdataleft) / (1024/sizeof(Id)));
360   POOL_DEBUG(SAT_DEBUG_STATS, "createwhatprovides took %d ms\n", sat_timems(now));
361 }
362
363 /*
364  * free all of our whatprovides data
365  * be careful, everything internalized with pool_queuetowhatprovides is gone, too
366  */
367 void
368 pool_freewhatprovides(Pool *pool)
369 {
370   pool->whatprovides = sat_free(pool->whatprovides);
371   pool->whatprovides_rel = sat_free(pool->whatprovides_rel);
372   pool->whatprovidesdata = sat_free(pool->whatprovidesdata);
373   pool->whatprovidesdataoff = 0;
374   pool->whatprovidesdataleft = 0;
375 }
376
377
378 /******************************************************************************/
379
380 /*
381  * pool_queuetowhatprovides  - add queue contents to whatprovidesdata
382  * 
383  * on-demand filling of provider information
384  * move queue data into whatprovidesdata
385  * q: queue of Ids
386  * returns: Offset into whatprovides
387  *
388  */
389 Id
390 pool_queuetowhatprovides(Pool *pool, Queue *q)
391 {
392   Offset off;
393   int count = q->count;
394
395   if (count == 0)                      /* queue empty -> 1 */
396     return 1;
397
398   /* extend whatprovidesdata if needed, +1 for ID_NULL-termination */
399   if (pool->whatprovidesdataleft < count + 1)
400     {
401       POOL_DEBUG(SAT_DEBUG_STATS, "growing provides hash data...\n");
402       pool->whatprovidesdata = sat_realloc(pool->whatprovidesdata, (pool->whatprovidesdataoff + count + 4096) * sizeof(Id));
403       pool->whatprovidesdataleft = count + 4096;
404     }
405
406   /* copy queue to next free slot */
407   off = pool->whatprovidesdataoff;
408   memcpy(pool->whatprovidesdata + pool->whatprovidesdataoff, q->elements, count * sizeof(Id));
409
410   /* adapt count and ID_NULL-terminate */
411   pool->whatprovidesdataoff += count;
412   pool->whatprovidesdata[pool->whatprovidesdataoff++] = ID_NULL;
413   pool->whatprovidesdataleft -= count + 1;
414
415   return (Id)off;
416 }
417
418
419 /*************************************************************************/
420
421 /* check if a package's nevr matches a dependency */
422
423 int
424 pool_match_nevr_rel(Pool *pool, Solvable *s, Id d)
425 {
426   Reldep *rd = GETRELDEP(pool, d);
427   Id name = rd->name;
428   Id evr = rd->evr;
429   int flags = rd->flags;
430
431   if (flags > 7)
432     {
433       switch (flags)
434         {
435         case REL_ARCH:
436           if (s->arch != evr)
437             return 0;
438           return pool_match_nevr(pool, s, name);
439         case REL_OR:
440           if (pool_match_nevr(pool, s, name))
441             return 1;
442           return pool_match_nevr(pool, s, evr);
443         case REL_AND:
444         case REL_WITH:
445           if (!pool_match_nevr(pool, s, name))
446             return 0;
447           return pool_match_nevr(pool, s, evr);
448         default:
449           return 0;
450         }
451     }
452   if (!pool_match_nevr(pool, s, name))
453     return 0;
454   if (evr == s->evr)
455     return flags & 2 ? 1 : 0;
456   if (!flags)
457     return 0;
458   if (flags == 7)
459     return 1;
460   if (flags != 2 && flags != 5)
461     flags ^= 5;
462   if ((flags & (1 << (1 + evrcmp(pool, s->evr, evr, EVRCMP_MATCH_RELEASE)))) != 0)
463     return 1;
464   return 0;
465 }
466
467 /*
468  * addrelproviders
469  * 
470  * add packages fulfilling the relation to whatprovides array
471  * no exact providers, do range match
472  * 
473  */
474
475 Id
476 pool_addrelproviders(Pool *pool, Id d)
477 {
478   Reldep *rd = GETRELDEP(pool, d);
479   Reldep *prd;
480   Queue plist;
481   Id buf[16];
482   Id name = rd->name;
483   Id evr = rd->evr;
484   int flags = rd->flags;
485   Id pid, *pidp;
486   Id p, wp, *pp, *pp2, *pp3;
487
488   d = GETRELID(d);
489   queue_init_buffer(&plist, buf, sizeof(buf)/sizeof(*buf));
490   switch (flags)
491     {
492     case REL_AND:
493     case REL_WITH:
494       pp = pool->whatprovidesdata + pool_whatprovides(pool, name);
495       pp2 = pool->whatprovidesdata + pool_whatprovides(pool, evr);
496       while ((p = *pp++) != 0)
497         {
498           for (pp3 = pp2; *pp3;)
499             if (*pp3++ == p)
500               {
501                 queue_push(&plist, p);
502                 break;
503               }
504         }
505       break;
506     case REL_OR:
507       pp = pool->whatprovidesdata + pool_whatprovides(pool, name);
508       while ((p = *pp++) != 0)
509         queue_push(&plist, p);
510       pp = pool->whatprovidesdata + pool_whatprovides(pool, evr);
511       while ((p = *pp++) != 0)
512         queue_pushunique(&plist, p);
513       break;
514     case REL_NAMESPACE:
515       if (name == NAMESPACE_OTHERPROVIDERS)
516         {
517           wp = pool_whatprovides(pool, evr);
518           pool->whatprovides_rel[d] = wp;
519           return wp;
520         }
521       if (pool->nscallback)
522         {
523           /* ask callback which packages provide the dependency
524            * 0:  none
525            * 1:  the system (aka SYSTEMSOLVABLE)
526            * >1: a set of packages, stored as offset on whatprovidesdata
527            */
528           p = pool->nscallback(pool, pool->nscallbackdata, name, evr);
529           if (p > 1)
530             {
531               queue_free(&plist);
532               pool->whatprovides_rel[d] = p;
533               return p;
534             }
535           if (p == 1)
536             queue_push(&plist, SYSTEMSOLVABLE);
537         }
538       break;
539     case REL_ARCH:
540       /* small hack: make it possible to match <pkg>.src
541        * we have to iterate over the solvables as src packages do not
542        * provide anything, thus they are not indexed in our
543        * whatprovides hash */
544       if (evr == ARCH_SRC)
545         {
546           Solvable *s;
547           for (p = 1, s = pool->solvables + p; p < pool->nsolvables; p++, s++)
548             {
549               if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
550                 continue;
551               if (pool_match_nevr(pool, s, name))
552                 queue_push(&plist, p);
553             }
554           break;
555         }
556       wp = pool_whatprovides(pool, name);
557       pp = pool->whatprovidesdata + wp;
558       while ((p = *pp++) != 0)
559         {
560           Solvable *s = pool->solvables + p;
561           if (s->arch == evr)
562             queue_push(&plist, p);
563           else
564             wp = 0;
565         }
566       if (wp)
567         {
568           pool->whatprovides_rel[d] = wp;
569           return wp;
570         }
571       break;
572     default:
573       break;
574     }
575
576   /* convert to whatprovides id */
577 #if 0
578   POOL_DEBUG(SAT_DEBUG_STATS, "addrelproviders: what provides %s?\n", dep2str(pool, name));
579 #endif
580   if (flags && flags < 8)
581     {
582       pp = pool->whatprovidesdata + pool_whatprovides(pool, name);
583       while (ISRELDEP(name))
584         {
585           rd = GETRELDEP(pool, name);
586           name = rd->name;
587         }
588       while ((p = *pp++) != 0)
589         {
590           Solvable *s = pool->solvables + p;
591 #if 0
592           POOL_DEBUG(DEBUG_1, "addrelproviders: checking package %s\n", id2str(pool, s->name));
593 #endif
594           if (!s->provides)
595             {
596               /* no provides - check nevr */
597               if (pool_match_nevr_rel(pool, s, MAKERELDEP(d)))
598                 queue_push(&plist, p);
599               continue;
600             }
601           /* solvable p provides name in some rels */
602           pidp = s->repo->idarraydata + s->provides;
603           while ((pid = *pidp++) != 0)
604             {
605               int pflags;
606               Id pevr;
607
608               if (pid == name)
609                 {
610 #ifdef DEBIAN_SEMANTICS
611                   continue;             /* unversioned provides can
612                                          * never match versioned deps */
613 #else
614                   break;                /* yes, provides all versions */
615 #endif
616                 }
617               if (!ISRELDEP(pid))
618                 continue;               /* wrong provides name */
619               prd = GETRELDEP(pool, pid);
620               if (prd->name != name)
621                 continue;               /* wrong provides name */
622               /* right package, both deps are rels */
623               pflags = prd->flags;
624               if (!pflags)
625                 continue;
626               if (flags == 7 || pflags == 7)
627                 break; /* included */
628               if ((pflags & flags & 5) != 0)
629                 break; /* same direction, match */
630               pevr = prd->evr;
631               if (pevr == evr)
632                 {
633                   if ((pflags & flags & 2) != 0)
634                     break; /* both have =, match */
635                 }
636               else
637                 {
638                   int f = flags == 5 ? 5 : flags == 2 ? pflags : (flags ^ 5) & (pflags | 5);
639                   if ((f & (1 << (1 + evrcmp(pool, pevr, evr, EVRCMP_MATCH_RELEASE)))) != 0)
640                     break;
641                 }
642             }
643           if (!pid)
644             continue;   /* no rel match */
645           queue_push(&plist, p);
646         }
647       /* make our system solvable provide all unknown rpmlib() stuff */
648       if (plist.count == 0 && !strncmp(id2str(pool, name), "rpmlib(", 7))
649         queue_push(&plist, SYSTEMSOLVABLE);
650     }
651   /* add providers to whatprovides */
652 #if 0
653   POOL_DEBUG(SAT_DEBUG_STATS, "addrelproviders: adding %d packages to %d\n", plist.count, d);
654 #endif
655   pool->whatprovides_rel[d] = pool_queuetowhatprovides(pool, &plist);
656   queue_free(&plist);
657
658   return pool->whatprovides_rel[d];
659 }
660
661 /*************************************************************************/
662
663 void
664 pool_debug(Pool *pool, int type, const char *format, ...)
665 {
666   va_list args;
667   char buf[1024];
668
669   if ((type & (SAT_FATAL|SAT_ERROR)) == 0)
670     {
671       if ((pool->debugmask & type) == 0)
672         return;
673     }
674   va_start(args, format);
675   if (!pool->debugcallback)
676     {
677       if ((type & (SAT_FATAL|SAT_ERROR)) == 0)
678         vprintf(format, args);
679       else
680         vfprintf(stderr, format, args);
681       return;
682     }
683   vsnprintf(buf, sizeof(buf), format, args);
684   pool->debugcallback(pool, pool->debugcallbackdata, type, buf);
685 }
686
687 void
688 pool_setdebuglevel(Pool *pool, int level)
689 {
690   int mask = SAT_DEBUG_RESULT;
691   if (level > 0)
692     mask |= SAT_DEBUG_STATS|SAT_DEBUG_ANALYZE|SAT_DEBUG_UNSOLVABLE;
693   if (level > 1)
694     mask |= SAT_DEBUG_JOB|SAT_DEBUG_SOLUTIONS|SAT_DEBUG_POLICY;
695   if (level > 2)
696     mask |= SAT_DEBUG_PROPAGATE;
697   if (level > 3)
698     mask |= SAT_DEBUG_RULE_CREATION;
699   if (level > 4)
700     mask |= SAT_DEBUG_SCHUBI;
701   pool->debugmask = mask;
702 }
703
704 /*************************************************************************/
705
706 struct searchfiles {
707   Id *ids;
708   char **dirs;
709   char **names;
710   int nfiles;
711   Map seen;
712 };
713
714 #define SEARCHFILES_BLOCK 127
715
716 static void
717 pool_addfileprovides_dep(Pool *pool, Id *ida, struct searchfiles *sf, struct searchfiles *isf)
718 {
719   Id dep, sid;
720   const char *s, *sr;
721   struct searchfiles *csf;
722
723   while ((dep = *ida++) != 0)
724     {
725       csf = sf;
726       while (ISRELDEP(dep))
727         {
728           Reldep *rd;
729           sid = pool->ss.nstrings + GETRELID(dep);
730           if (MAPTST(&csf->seen, sid))
731             {
732               dep = 0;
733               break;
734             }
735           MAPSET(&csf->seen, sid);
736           rd = GETRELDEP(pool, dep);
737           if (rd->flags < 8)
738             dep = rd->name;
739           else if (rd->flags == REL_NAMESPACE)
740             {
741               if (rd->name == NAMESPACE_INSTALLED || rd->name == NAMESPACE_SPLITPROVIDES)
742                 {
743                   csf = isf;
744                   if (!csf || MAPTST(&csf->seen, sid))
745                     {
746                       dep = 0;
747                       break;
748                     }
749                   MAPSET(&csf->seen, sid);
750                 }
751               dep = rd->evr;
752             }
753           else
754             {
755               Id ids[2];
756               ids[0] = rd->name;
757               ids[1] = 0;
758               pool_addfileprovides_dep(pool, ids, csf, isf);
759               dep = rd->evr;
760             }
761         }
762       if (!dep)
763         continue;
764       if (MAPTST(&csf->seen, dep))
765         continue;
766       MAPSET(&csf->seen, dep);
767       s = id2str(pool, dep);
768       if (*s != '/')
769         continue;
770       csf->ids = sat_extend(csf->ids, csf->nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
771       csf->dirs = sat_extend(csf->dirs, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
772       csf->names = sat_extend(csf->names, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
773       csf->ids[csf->nfiles] = dep;
774       sr = strrchr(s, '/');
775       csf->names[csf->nfiles] = strdup(sr + 1);
776       csf->dirs[csf->nfiles] = sat_malloc(sr - s + 1);
777       if (sr != s)
778         strncpy(csf->dirs[csf->nfiles], s, sr - s);
779       csf->dirs[csf->nfiles][sr - s] = 0;
780       csf->nfiles++;
781     }
782 }
783
784 struct addfileprovides_cbdata {
785   int nfiles;
786   Id *ids;
787   char **dirs;
788   char **names;
789
790   Repodata *olddata;
791   Id *dids;
792   Map useddirs;
793 };
794
795 static int
796 addfileprovides_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
797 {
798   struct addfileprovides_cbdata *cbd = cbdata;
799   int i;
800
801   if (data != cbd->olddata)
802     {
803       map_free(&cbd->useddirs);
804       map_init(&cbd->useddirs, data->dirpool.ndirs);
805       for (i = 0; i < cbd->nfiles; i++)
806         {
807           Id did = repodata_str2dir(data, cbd->dirs[i], 0);
808           cbd->dids[i] = did;
809           if (did)
810             MAPSET(&cbd->useddirs, did);
811         }
812       cbd->olddata = data;
813     }
814   if (!MAPTST(&cbd->useddirs, value->id))
815     return 0;
816   for (i = 0; i < cbd->nfiles; i++)
817     {
818       if (cbd->dids[i] != value->id)
819         continue;
820       if (!strcmp(cbd->names[i], value->str))
821         break;
822     }
823   if (i == cbd->nfiles)
824     return 0;
825   s->provides = repo_addid_dep(s->repo, s->provides, cbd->ids[i], SOLVABLE_FILEMARKER);
826   return 0;
827 }
828
829 static int
830 addfileprovides_setid_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv)
831 {
832   Map *provideids = cbdata;
833   if (key->type != REPOKEY_TYPE_IDARRAY)
834     return 0;
835   MAPSET(provideids, kv->id);
836   return kv->eof ? SEARCH_NEXT_SOLVABLE : 0;
837 }
838
839
840 static void
841 pool_addfileprovides_search(Pool *pool, struct addfileprovides_cbdata *cbd, struct searchfiles *sf, Repo *repoonly)
842 {
843   Id p, start, end;
844   Solvable *s;
845   Repodata *data = 0, *nextdata;
846   Repo *oldrepo = 0;
847   int dataincludes = 0;
848   int i, j;
849   Map providedids;
850
851   cbd->nfiles = sf->nfiles;
852   cbd->ids = sf->ids;
853   cbd->dirs = sf->dirs;
854   cbd->names = sf->names;
855   cbd->olddata = 0;
856   cbd->dids = sat_realloc2(cbd->dids, sf->nfiles, sizeof(Id));
857   if (repoonly)
858     {
859       start = repoonly->start;
860       end = repoonly->end;
861     }
862   else
863     {
864       start = 2;        /* skip system solvable */
865       end = pool->nsolvables;
866     }
867   for (p = start, s = pool->solvables + p; p < end; p++, s++)
868     {
869       if (!s->repo || (repoonly && s->repo != repoonly))
870         continue;
871       /* check if p is in (oldrepo,data) */
872       if (s->repo != oldrepo || (data && p >= data->end))
873         {
874           data = 0;
875           oldrepo = 0;
876         }
877       if (oldrepo == 0)
878         {
879           /* nope, find new repo/repodata */
880           /* if we don't find a match, set data to the next repodata */
881           nextdata = 0;
882           for (i = 0, data = s->repo->repodata; i < s->repo->nrepodata; i++, data++)
883             {
884               if (p >= data->end)
885                 continue;
886               if (data->state != REPODATA_AVAILABLE)
887                 continue;
888               for (j = 1; j < data->nkeys; j++)
889                 if (data->keys[j].name == REPOSITORY_ADDEDFILEPROVIDES && data->keys[j].type == REPOKEY_TYPE_IDARRAY)
890                   break;
891               if (j == data->nkeys)
892                 continue;
893               /* great, this repodata contains addedfileprovides */
894               if (!nextdata || nextdata->start > data->start)
895                 nextdata = data;
896               if (p >= data->start)
897                 break;
898             }
899           if (i == s->repo->nrepodata)
900             data = nextdata;    /* no direct hit, use next repodata */
901           if (data)
902             {
903               map_init(&providedids, pool->ss.nstrings);
904               repodata_search(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, 0, addfileprovides_setid_cb, &providedids);
905               for (i = 0; i < cbd->nfiles; i++)
906                 if (!MAPTST(&providedids, cbd->ids[i]))
907                   break;
908               map_free(&providedids);
909               dataincludes = i == cbd->nfiles;
910             }
911           oldrepo = s->repo;
912         }
913       if (data && p >= data->start && dataincludes)
914         continue;
915       repo_search(s->repo, p, SOLVABLE_FILELIST, 0, 0, addfileprovides_cb, cbd);
916     }
917 }
918
919 void
920 pool_addfileprovides_ids(Pool *pool, Repo *installed, Id **idp)
921 {
922   Solvable *s;
923   Repo *repo;
924   struct searchfiles sf, isf, *isfp;
925   struct addfileprovides_cbdata cbd;
926   int i;
927
928   memset(&sf, 0, sizeof(sf));
929   map_init(&sf.seen, pool->ss.nstrings + pool->nrels);
930   memset(&isf, 0, sizeof(isf));
931   map_init(&isf.seen, pool->ss.nstrings + pool->nrels);
932
933   isfp = installed ? &isf : 0;
934   for (i = 1, s = pool->solvables + i; i < pool->nsolvables; i++, s++)
935     {
936       repo = s->repo;
937       if (!repo)
938         continue;
939       if (s->obsoletes)
940         pool_addfileprovides_dep(pool, repo->idarraydata + s->obsoletes, &sf, isfp);
941       if (s->conflicts)
942         pool_addfileprovides_dep(pool, repo->idarraydata + s->conflicts, &sf, isfp);
943       if (s->requires)
944         pool_addfileprovides_dep(pool, repo->idarraydata + s->requires, &sf, isfp);
945       if (s->recommends)
946         pool_addfileprovides_dep(pool, repo->idarraydata + s->recommends, &sf, isfp);
947       if (s->suggests)
948         pool_addfileprovides_dep(pool, repo->idarraydata + s->suggests, &sf, isfp);
949       if (s->supplements)
950         pool_addfileprovides_dep(pool, repo->idarraydata + s->supplements, &sf, isfp);
951       if (s->enhances)
952         pool_addfileprovides_dep(pool, repo->idarraydata + s->enhances, &sf, isfp);
953     }
954   map_free(&sf.seen);
955   map_free(&isf.seen);
956   POOL_DEBUG(SAT_DEBUG_STATS, "found %d file dependencies\n", sf.nfiles);
957   POOL_DEBUG(SAT_DEBUG_STATS, "found %d installed file dependencies\n", isf.nfiles);
958   cbd.dids = 0;
959   map_init(&cbd.useddirs, 1);
960   if (idp)
961     *idp = 0;
962   if (sf.nfiles)
963     {
964 #if 0
965       for (i = 0; i < sf.nfiles; i++)
966         POOL_DEBUG(SAT_DEBUG_STATS, "looking up %s in filelist\n", id2str(pool, sf.ids[i]));
967 #endif
968       pool_addfileprovides_search(pool, &cbd, &sf, 0);
969       if (idp)
970         {
971           sf.ids = sat_extend(sf.ids, sf.nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
972           sf.ids[sf.nfiles] = 0;
973           *idp = sf.ids;
974           sf.ids = 0;
975         }
976       sat_free(sf.ids);
977       for (i = 0; i < sf.nfiles; i++)
978         {
979           sat_free(sf.dirs[i]);
980           sat_free(sf.names[i]);
981         }
982       sat_free(sf.dirs);
983       sat_free(sf.names);
984     }
985   if (isf.nfiles)
986     {
987 #if 0
988       for (i = 0; i < isf.nfiles; i++)
989         POOL_DEBUG(SAT_DEBUG_STATS, "looking up %s in installed filelist\n", id2str(pool, isf.ids[i]));
990 #endif
991       if (installed)
992         pool_addfileprovides_search(pool, &cbd, &isf, installed);
993       sat_free(isf.ids);
994       for (i = 0; i < isf.nfiles; i++)
995         {
996           sat_free(isf.dirs[i]);
997           sat_free(isf.names[i]);
998         }
999       sat_free(isf.dirs);
1000       sat_free(isf.names);
1001     }
1002   map_free(&cbd.useddirs);
1003   sat_free(cbd.dids);
1004   pool_freewhatprovides(pool);  /* as we have added provides */
1005 }
1006
1007 void
1008 pool_addfileprovides(Pool *pool)
1009 {
1010   pool_addfileprovides_ids(pool, pool->installed, 0);
1011 }
1012
1013 void
1014 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)
1015 {
1016   if (p)
1017     {
1018       if (pool->solvables[p].repo)
1019         repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1020       return;
1021     }
1022   /* FIXME: obey callback return value! */
1023   for (p = 1; p < pool->nsolvables; p++)
1024     if (pool->solvables[p].repo)
1025       repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1026 }
1027
1028 void
1029 pool_clear_pos(Pool *pool)
1030 {
1031   memset(&pool->pos, 0, sizeof(pool->pos));
1032 }
1033
1034
1035 void
1036 pool_set_languages(Pool *pool, const char **languages, int nlanguages)
1037 {
1038   int i;
1039
1040   pool->languagecache = sat_free(pool->languagecache);
1041   pool->languagecacheother = 0;
1042   if (pool->nlanguages)
1043     {
1044       for (i = 0; i < pool->nlanguages; i++)
1045         free((char *)pool->languages[i]);
1046       free(pool->languages);
1047     }
1048   pool->nlanguages = nlanguages;
1049   if (!nlanguages)
1050     return;
1051   pool->languages = sat_calloc(nlanguages, sizeof(const char **));
1052   for (i = 0; i < pool->nlanguages; i++)
1053     pool->languages[i] = strdup(languages[i]);
1054 }
1055
1056 Id
1057 pool_id2langid(Pool *pool, Id id, const char *lang, int create)
1058 {
1059   const char *n;
1060   char buf[256], *p;
1061   int l;
1062
1063   if (!lang)
1064     return id;
1065   n = id2str(pool, id);
1066   l = strlen(n) + strlen(lang) + 2;
1067   if (l > sizeof(buf))
1068     p = sat_malloc(strlen(n) + strlen(lang) + 2);
1069   else
1070     p = buf;
1071   sprintf(p, "%s:%s", n, lang);
1072   id = str2id(pool, p, create);
1073   if (p != buf)
1074     free(p);
1075   return id;
1076 }
1077
1078 char *
1079 pool_alloctmpspace(Pool *pool, int len)
1080 {
1081   int n = pool->tmpspacen;
1082   if (!len)
1083     return 0;
1084   if (len > pool->tmpspacelen[n])
1085     {
1086       pool->tmpspacebuf[n] = sat_realloc(pool->tmpspacebuf[n], len + 32);
1087       pool->tmpspacelen[n] = len + 32;
1088     }
1089   pool->tmpspacen = (n + 1) % POOL_TMPSPACEBUF;
1090   return pool->tmpspacebuf[n];
1091 }
1092
1093 /*******************************************************************/
1094
1095 struct mptree {
1096   Id sibling;
1097   Id child;
1098   const char *comp;
1099   int compl;
1100   Id mountpoint;
1101 };
1102
1103 struct ducbdata {
1104   DUChanges *mps;
1105   struct mptree *mptree;
1106   int addsub;
1107   int hasdu;
1108
1109   Id *dirmap;
1110   int nmap;
1111   Repodata *olddata;
1112 };
1113
1114
1115 static int
1116 solver_fill_DU_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
1117 {
1118   struct ducbdata *cbd = cbdata;
1119   Id mp;
1120
1121   if (data != cbd->olddata)
1122     {
1123       Id dn, mp, comp, *dirmap, *dirs;
1124       int i, compl;
1125       const char *compstr;
1126       struct mptree *mptree;
1127
1128       /* create map from dir to mptree */
1129       cbd->dirmap = sat_free(cbd->dirmap);
1130       cbd->nmap = 0;
1131       dirmap = sat_calloc(data->dirpool.ndirs, sizeof(Id));
1132       mptree = cbd->mptree;
1133       mp = 0;
1134       for (dn = 2, dirs = data->dirpool.dirs + dn; dn < data->dirpool.ndirs; dn++)
1135         {
1136           comp = *dirs++;
1137           if (comp <= 0)
1138             {
1139               mp = dirmap[-comp];
1140               continue;
1141             }
1142           if (mp < 0)
1143             {
1144               /* unconnected */
1145               dirmap[dn] = mp;
1146               continue;
1147             }
1148           if (!mptree[mp].child)
1149             {
1150               dirmap[dn] = -mp;
1151               continue;
1152             }
1153           if (data->localpool)
1154             compstr = stringpool_id2str(&data->spool, comp);
1155           else
1156             compstr = id2str(data->repo->pool, comp);
1157           compl = strlen(compstr);
1158           for (i = mptree[mp].child; i; i = mptree[i].sibling)
1159             if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1160               break;
1161           dirmap[dn] = i ? i : -mp;
1162         }
1163       /* change dirmap to point to mountpoint instead of mptree */
1164       for (dn = 0; dn < data->dirpool.ndirs; dn++)
1165         {
1166           mp = dirmap[dn];
1167           dirmap[dn] = mptree[mp > 0 ? mp : -mp].mountpoint;
1168         }
1169       cbd->dirmap = dirmap;
1170       cbd->nmap = data->dirpool.ndirs;
1171       cbd->olddata = data;
1172     }
1173   cbd->hasdu = 1;
1174   if (value->id < 0 || value->id >= cbd->nmap)
1175     return 0;
1176   mp = cbd->dirmap[value->id];
1177   if (mp < 0)
1178     return 0;
1179   if (cbd->addsub > 0)
1180     {
1181       cbd->mps[mp].kbytes += value->num;
1182       cbd->mps[mp].files += value->num2;
1183     }
1184   else
1185     {
1186       cbd->mps[mp].kbytes -= value->num;
1187       cbd->mps[mp].files -= value->num2;
1188     }
1189   return 0;
1190 }
1191
1192 static void
1193 propagate_mountpoints(struct mptree *mptree, int pos, Id mountpoint)
1194 {
1195   int i;
1196   if (mptree[pos].mountpoint == -1)
1197     mptree[pos].mountpoint = mountpoint;
1198   else
1199     mountpoint = mptree[pos].mountpoint;
1200   for (i = mptree[pos].child; i; i = mptree[i].sibling)
1201     propagate_mountpoints(mptree, i, mountpoint);
1202 }
1203
1204 #define MPTREE_BLOCK 15
1205
1206 void
1207 pool_calc_duchanges(Pool *pool, Map *installedmap, DUChanges *mps, int nmps)
1208 {
1209   char *p;
1210   const char *path, *compstr;
1211   struct mptree *mptree;
1212   int i, nmptree;
1213   int pos, compl;
1214   int mp;
1215   struct ducbdata cbd;
1216   Solvable *s;
1217   Id sp;
1218   Map ignoredu;
1219   Repo *oldinstalled = pool->installed;
1220
1221   memset(&ignoredu, 0, sizeof(ignoredu));
1222   cbd.mps = mps;
1223   cbd.addsub = 0;
1224   cbd.dirmap = 0;
1225   cbd.nmap = 0;
1226   cbd.olddata = 0;
1227
1228   mptree = sat_extend_resize(0, 1, sizeof(struct mptree), MPTREE_BLOCK);
1229
1230   /* our root node */
1231   mptree[0].sibling = 0;
1232   mptree[0].child = 0;
1233   mptree[0].comp = 0;
1234   mptree[0].compl = 0;
1235   mptree[0].mountpoint = -1;
1236   nmptree = 1;
1237   
1238   /* create component tree */
1239   for (mp = 0; mp < nmps; mp++)
1240     {
1241       mps[mp].kbytes = 0;
1242       mps[mp].files = 0;
1243       pos = 0;
1244       path = mps[mp].path;
1245       while(*path == '/')
1246         path++;
1247       while (*path)
1248         {
1249           if ((p = strchr(path, '/')) == 0)
1250             {
1251               compstr = path;
1252               compl = strlen(compstr);
1253               path += compl;
1254             }
1255           else
1256             {
1257               compstr = path;
1258               compl = p - path;
1259               path = p + 1;
1260               while(*path == '/')
1261                 path++;
1262             }
1263           for (i = mptree[pos].child; i; i = mptree[i].sibling)
1264             if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1265               break;
1266           if (!i)
1267             {
1268               /* create new node */
1269               mptree = sat_extend(mptree, nmptree, 1, sizeof(struct mptree), MPTREE_BLOCK);
1270               i = nmptree++;
1271               mptree[i].sibling = mptree[pos].child;
1272               mptree[i].child = 0;
1273               mptree[i].comp = compstr;
1274               mptree[i].compl = compl;
1275               mptree[i].mountpoint = -1;
1276               mptree[pos].child = i;
1277             }
1278           pos = i;
1279         }
1280       mptree[pos].mountpoint = mp;
1281     }
1282
1283   propagate_mountpoints(mptree, 0, mptree[0].mountpoint);
1284
1285 #if 0
1286   for (i = 0; i < nmptree; i++)
1287     {
1288       printf("#%d sibling: %d\n", i, mptree[i].sibling);
1289       printf("#%d child: %d\n", i, mptree[i].child);
1290       printf("#%d comp: %s\n", i, mptree[i].comp);
1291       printf("#%d compl: %d\n", i, mptree[i].compl);
1292       printf("#%d mountpont: %d\n", i, mptree[i].mountpoint);
1293     }
1294 #endif
1295
1296   cbd.mptree = mptree;
1297   cbd.addsub = 1;
1298   for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
1299     {
1300       if (!s->repo || (oldinstalled && s->repo == oldinstalled))
1301         continue;
1302       if (!MAPTST(installedmap, sp))
1303         continue;
1304       cbd.hasdu = 0;
1305       repo_search(s->repo, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1306       if (!cbd.hasdu && oldinstalled)
1307         {
1308           Id op, opp;
1309           /* no du data available, ignore data of all installed solvables we obsolete */
1310           if (!ignoredu.map)
1311             map_init(&ignoredu, oldinstalled->end - oldinstalled->start);
1312           if (s->obsoletes)
1313             {
1314               Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
1315               while ((obs = *obsp++) != 0)
1316                 FOR_PROVIDES(op, opp, obs)
1317                   if (op >= oldinstalled->start && op < oldinstalled->end)
1318                     MAPSET(&ignoredu, op - oldinstalled->start);
1319             }
1320           FOR_PROVIDES(op, opp, s->name)
1321             if (pool->solvables[op].name == s->name)
1322               if (op >= oldinstalled->start && op < oldinstalled->end)
1323                 MAPSET(&ignoredu, op - oldinstalled->start);
1324         }
1325     }
1326   cbd.addsub = -1;
1327   if (oldinstalled)
1328     {
1329       /* assumes we allways have du data for installed solvables */
1330       FOR_REPO_SOLVABLES(oldinstalled, sp, s)
1331         {
1332           if (MAPTST(installedmap, sp))
1333             continue;
1334           if (ignoredu.map && MAPTST(&ignoredu, sp - oldinstalled->start))
1335             continue;
1336           repo_search(oldinstalled, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1337         }
1338     }
1339   if (ignoredu.map)
1340     map_free(&ignoredu);
1341   sat_free(cbd.dirmap);
1342   sat_free(mptree);
1343 }
1344
1345 int
1346 pool_calc_installsizechange(Pool *pool, Map *installedmap)
1347 {
1348   Id sp;
1349   Solvable *s;
1350   int change = 0;
1351   Repo *oldinstalled = pool->installed;
1352
1353   for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
1354     {
1355       if (!s->repo || (oldinstalled && s->repo == oldinstalled))
1356         continue;
1357       if (!MAPTST(installedmap, sp))
1358         continue;
1359       change += solvable_lookup_num(s, SOLVABLE_INSTALLSIZE, 0);
1360     }
1361   if (oldinstalled)
1362     {
1363       FOR_REPO_SOLVABLES(oldinstalled, sp, s)
1364         {
1365           if (MAPTST(installedmap, sp))
1366             continue;
1367           change -= solvable_lookup_num(s, SOLVABLE_INSTALLSIZE, 0);
1368         }
1369     }
1370   return change;
1371 }
1372
1373 /* map:
1374  *  1: installed
1375  *  2: conflicts with installed
1376  *  8: interesting (only true if installed)
1377  * 16: undecided
1378  */
1379  
1380 static inline Id dep2name(Pool *pool, Id dep)
1381 {
1382   while (ISRELDEP(dep))
1383     {
1384       Reldep *rd = rd = GETRELDEP(pool, dep);
1385       dep = rd->name;
1386     }
1387   return dep;
1388 }
1389
1390 static inline int providedbyinstalled(Pool *pool, unsigned char *map, Id dep)
1391 {
1392   Id p, pp;
1393   int r = 0;
1394   FOR_PROVIDES(p, pp, dep)
1395     {
1396       if (p == SYSTEMSOLVABLE)
1397         return 1;       /* always boring, as never constraining */
1398       if ((map[p] & 9) == 9)
1399         return 9;
1400       r |= map[p] & 17;
1401     }
1402   return r;
1403 }
1404
1405 /*
1406  * pool_trivial_installable - calculate if a set of solvables is
1407  * trivial installable without any other installs/deinstalls of
1408  * packages not belonging to the set.
1409  *
1410  * the state is returned in the result queue:
1411  * 1:  solvable is installable without any other package changes
1412  * 0:  solvable is not installable
1413  * -1: solvable is installable, but doesn't constrain any installed packages
1414  */
1415
1416 void
1417 pool_trivial_installable(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res)
1418 {
1419   int i, r, m, did;
1420   Id p, *dp, con, *conp, req, *reqp;
1421   unsigned char *map;
1422   Solvable *s;
1423
1424   map = sat_calloc(pool->nsolvables, 1);
1425   for (p = 1; p < pool->nsolvables; p++)
1426     {
1427       if (!MAPTST(installedmap, p))
1428         continue;
1429       map[p] |= 9;
1430       s = pool->solvables + p;
1431       if (!s->conflicts)
1432         continue;
1433       conp = s->repo->idarraydata + s->conflicts;
1434       while ((con = *conp++) != 0)
1435         {
1436           dp = pool->whatprovidesdata + pool_whatprovides(pool, con);
1437           for (; *dp; dp++)
1438             map[p] |= 2;        /* XXX: self conflict ? */
1439         }
1440     }
1441   for (i = 0; i < pkgs->count; i++)
1442     map[pkgs->elements[i]] = 16;
1443
1444   for (i = 0, did = 0; did < pkgs->count; i++, did++)
1445     {
1446       if (i == pkgs->count)
1447         i = 0;
1448       p = pkgs->elements[i];
1449       if ((map[p] & 16) == 0)
1450         continue;
1451       if ((map[p] & 2) != 0)
1452         {
1453           map[p] = 2;
1454           continue;
1455         }
1456       s = pool->solvables + p;
1457       m = 1;
1458       if (s->requires)
1459         {
1460           reqp = s->repo->idarraydata + s->requires;
1461           while ((req = *reqp++) != 0)
1462             {
1463               if (req == SOLVABLE_PREREQMARKER)
1464                 continue;
1465               r = providedbyinstalled(pool, map, req);
1466               if (!r)
1467                 {
1468                   /* decided and miss */
1469                   map[p] = 2;
1470                   break;
1471                 }
1472               m |= r;   /* 1 | 9 | 16 | 17 */
1473             }
1474           if (req)
1475             continue;
1476           if ((m & 9) == 9)
1477             m = 9;
1478         }
1479       if (s->conflicts)
1480         {
1481           conp = s->repo->idarraydata + s->conflicts;
1482           while ((con = *conp++) != 0)
1483             {
1484               if ((providedbyinstalled(pool, map, con) & 1) != 0)
1485                 {
1486                   map[p] = 2;
1487                   break;
1488                 }
1489               if ((m == 1 || m == 17) && ISRELDEP(con))
1490                 {
1491                   con = dep2name(pool, con);
1492                   if ((providedbyinstalled(pool, map, con) & 1) != 0)
1493                     m = 9;
1494                 }
1495             }
1496           if (con)
1497             continue;   /* found a conflict */
1498         }
1499 #if 0
1500       if (s->repo && s->repo != oldinstalled)
1501         {
1502           Id p2, obs, *obsp, *pp;
1503           Solvable *s2;
1504           if (s->obsoletes)
1505             {
1506               obsp = s->repo->idarraydata + s->obsoletes;
1507               while ((obs = *obsp++) != 0)
1508                 {
1509                   if ((providedbyinstalled(pool, map, obs) & 1) != 0)
1510                     {
1511                       map[p] = 2;
1512                       break;
1513                     }
1514                 }
1515               if (obs)
1516                 continue;
1517             }
1518           FOR_PROVIDES(p2, pp, s->name)
1519             {
1520               s2 = pool->solvables + p2;
1521               if (s2->name == s->name && (map[p2] & 1) != 0)
1522                 {
1523                   map[p] = 2;
1524                   break;
1525                 }
1526             }
1527           if (p2)
1528             continue;
1529         }
1530 #endif
1531       if (m != map[p])
1532         {
1533           map[p] = m;
1534           did = 0;
1535         }
1536     }
1537   queue_free(res);
1538   queue_clone(res, pkgs);
1539   for (i = 0; i < pkgs->count; i++)
1540     {
1541       m = map[pkgs->elements[i]];
1542       if ((m & 9) == 9)
1543         r = 1;
1544       else if (m & 1)
1545         r = -1;
1546       else
1547         r = 0;
1548       res->elements[i] = r;
1549     }
1550   free(map);
1551 }
1552
1553 // EOF