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