Imported Upstream version 0.6.35
[platform/upstream/libsolv.git] / src / pool.c
index 01f95e6..60cc0f4 100644 (file)
@@ -44,7 +44,7 @@ pool_create(void)
 
   pool = (Pool *)solv_calloc(1, sizeof(*pool));
 
-  stringpool_init (&pool->ss, initpool_data);
+  stringpool_init(&pool->ss, initpool_data);
 
   /* alloc space for RelDep 0 */
   pool->rels = solv_extend_resize(0, 1, sizeof(Reldep), REL_BLOCK);
@@ -82,7 +82,7 @@ pool_create(void)
   s->evr = ID_EMPTY;
 
   pool->debugmask = SOLV_DEBUG_RESULT; /* FIXME */
-#ifdef FEDORA
+#if defined(FEDORA) || defined(MAGEIA)
   pool->implicitobsoleteusescolors = 1;
 #endif
 #ifdef RPM5
@@ -118,7 +118,7 @@ pool_free(Pool *pool)
     solv_free(pool->tmpspace.buf[i]);
   for (i = 0; i < pool->nlanguages; i++)
     free((char *)pool->languages[i]);
-  solv_free(pool->languages);
+  solv_free((void *)pool->languages);
   solv_free(pool->languagecache);
   solv_free(pool->errstr);
   solv_free(pool->rootdir);
@@ -141,22 +141,33 @@ pool_freeallrepos(Pool *pool, int reuseids)
   pool_free_solvable_block(pool, 2, pool->nsolvables - 2, reuseids);
 }
 
-#ifdef MULTI_SEMANTICS
-void
+int
 pool_setdisttype(Pool *pool, int disttype)
 {
+#ifdef MULTI_SEMANTICS
+  int olddisttype = pool->disttype;
+  switch(disttype)
+    {
+    case DISTTYPE_RPM:
+      pool->noarchid = ARCH_NOARCH;
+      break;
+    case DISTTYPE_DEB:
+      pool->noarchid = ARCH_ALL;
+      break;
+    case DISTTYPE_ARCH:
+    case DISTTYPE_HAIKU:
+      pool->noarchid = ARCH_ANY;
+      break;
+    default:
+      return -1;
+    }
   pool->disttype = disttype;
-  if (disttype == DISTTYPE_RPM)
-    pool->noarchid = ARCH_NOARCH;
-  if (disttype == DISTTYPE_DEB)
-    pool->noarchid = ARCH_ALL;
-  if (disttype == DISTTYPE_ARCH)
-    pool->noarchid = ARCH_ANY;
-  if (disttype == DISTTYPE_HAIKU)
-    pool->noarchid = ARCH_ANY;
   pool->solvables[SYSTEMSOLVABLE].arch = pool->noarchid;
-}
+  return olddisttype;
+#else
+  return pool->disttype == disttype ? disttype : -1;
 #endif
+}
 
 int
 pool_get_flag(Pool *pool, int flag)
@@ -183,6 +194,8 @@ pool_get_flag(Pool *pool, int flag)
       return pool->noobsoletesmultiversion;
     case POOL_FLAG_ADDFILEPROVIDESFILTERED:
       return pool->addfileprovidesfiltered;
+    case POOL_FLAG_NOWHATPROVIDESAUX:
+      return pool->nowhatprovidesaux;
     default:
       break;
     }
@@ -225,6 +238,9 @@ pool_set_flag(Pool *pool, int flag, int value)
     case POOL_FLAG_ADDFILEPROVIDESFILTERED:
       pool->addfileprovidesfiltered = value;
       break;
+    case POOL_FLAG_NOWHATPROVIDESAUX:
+      pool->nowhatprovidesaux = value;
+      break;
     default:
       break;
     }
@@ -382,6 +398,34 @@ pool_shrink_whatprovides(Pool *pool)
   memset(pool->whatprovidesdata + o, 0, r * sizeof(Id));
 }
 
+/* this gets rid of all the zeros in the aux */
+static void
+pool_shrink_whatprovidesaux(Pool *pool)
+{
+  int num = pool->whatprovidesauxoff;
+  Id id;
+  Offset newoff;
+  Id *op, *wp = pool->whatprovidesauxdata + 1;
+  int i;
+
+  for (i = 0; i < num; i++)
+    {
+      Offset o = pool->whatprovidesaux[i];
+      if (o < 2)
+       continue;
+      op = pool->whatprovidesauxdata + o;
+      pool->whatprovidesaux[i] = wp - pool->whatprovidesauxdata;
+      if (op < wp)
+       abort();
+      while ((id = *op++) != 0)
+       *wp++ = id;
+    }
+  newoff = wp - pool->whatprovidesauxdata;
+  pool->whatprovidesauxdata = solv_realloc(pool->whatprovidesauxdata, newoff * sizeof(Id));
+  POOL_DEBUG(SOLV_DEBUG_STATS, "shrunk whatprovidesauxdata from %d to %d\n", pool->whatprovidesauxdataoff, newoff);
+  pool->whatprovidesauxdataoff = newoff;
+}
+
 
 /*
  * pool_createwhatprovides()
@@ -398,7 +442,8 @@ pool_createwhatprovides(Pool *pool)
   Id id;
   Offset *idp, n;
   Offset *whatprovides;
-  Id *whatprovidesdata, *d;
+  Id *whatprovidesdata, *dp, *whatprovidesauxdata;
+  Offset *whatprovidesaux;
   Repo *installed = pool->installed;
   unsigned int now;
 
@@ -466,6 +511,16 @@ pool_createwhatprovides(Pool *pool)
   whatprovidesdata = solv_calloc(off + extra, sizeof(Id));
   whatprovidesdata[2] = SYSTEMSOLVABLE;
 
+  /* alloc aux vector */
+  whatprovidesauxdata = 0;
+  if (!pool->nowhatprovidesaux)
+    {
+      pool->whatprovidesaux = whatprovidesaux = solv_calloc(num, sizeof(Offset));
+      pool->whatprovidesauxoff = num;
+      pool->whatprovidesauxdataoff = off;
+      pool->whatprovidesauxdata = whatprovidesauxdata = solv_calloc(pool->whatprovidesauxdataoff, sizeof(Id));
+    }
+
   /* now fill data for all provides */
   for (i = pool->nsolvables - 1; i > 0; i--)
     {
@@ -480,24 +535,35 @@ pool_createwhatprovides(Pool *pool)
       pp = s->repo->idarraydata + s->provides;
       while ((id = *pp++) != 0)
        {
+         Id auxid = id;
          while (ISRELDEP(id))
            {
              Reldep *rd = GETRELDEP(pool, id);
              id = rd->name;
            }
-         d = whatprovidesdata + whatprovides[id];   /* offset into whatprovidesdata */
-         if (*d != i)          /* don't add same solvable twice */
+         dp = whatprovidesdata + whatprovides[id];   /* offset into whatprovidesdata */
+         if (*dp != i)         /* don't add same solvable twice */
            {
-             d[-1] = i;
+             dp[-1] = i;
              whatprovides[id]--;
            }
+         else
+           auxid = 1;
+         if (whatprovidesauxdata)
+           whatprovidesauxdata[whatprovides[id]] = auxid;
        }
     }
+  if (pool->whatprovidesaux)
+    memcpy(pool->whatprovidesaux, pool->whatprovides, num * sizeof(Id));
   pool->whatprovidesdata = whatprovidesdata;
   pool->whatprovidesdataoff = off;
   pool->whatprovidesdataleft = extra;
   pool_shrink_whatprovides(pool);
+  if (pool->whatprovidesaux)
+    pool_shrink_whatprovidesaux(pool);
   POOL_DEBUG(SOLV_DEBUG_STATS, "whatprovides memory used: %d K id array, %d K data\n", (pool->ss.nstrings + pool->nrels + WHATPROVIDES_BLOCK) / (int)(1024/sizeof(Id)), (pool->whatprovidesdataoff + pool->whatprovidesdataleft) / (int)(1024/sizeof(Id)));
+  if (pool->whatprovidesaux)
+    POOL_DEBUG(SOLV_DEBUG_STATS, "whatprovidesaux memory used: %d K id array, %d K data\n", pool->whatprovidesauxoff / (int)(1024/sizeof(Id)), pool->whatprovidesauxdataoff / (int)(1024/sizeof(Id)));
 
   queue_empty(&pool->lazywhatprovidesq);
   if ((!pool->addedfileprovides && pool->disttype == DISTTYPE_RPM) || pool->addedfileprovides == 1)
@@ -516,6 +582,8 @@ pool_createwhatprovides(Pool *pool)
          if (pool->whatprovides[i] > 1)
            queue_push2(&pool->lazywhatprovidesq, i, pool->whatprovides[i]);
          pool->whatprovides[i] = 0;
+         if (pool->whatprovidesaux)
+           pool->whatprovidesaux[i] = 0;       /* sorry */
        }
       POOL_DEBUG(SOLV_DEBUG_STATS, "lazywhatprovidesq size: %d entries\n", pool->lazywhatprovidesq.count / 2);
     }
@@ -536,6 +604,10 @@ pool_freewhatprovides(Pool *pool)
   pool->whatprovidesdata = solv_free(pool->whatprovidesdata);
   pool->whatprovidesdataoff = 0;
   pool->whatprovidesdataleft = 0;
+  pool->whatprovidesaux = solv_free(pool->whatprovidesaux);
+  pool->whatprovidesauxdata = solv_free(pool->whatprovidesauxdata);
+  pool->whatprovidesauxoff = 0;
+  pool->whatprovidesauxdataoff = 0;
 }
 
 
@@ -549,15 +621,15 @@ pool_freewhatprovides(Pool *pool)
  * returns: Offset into whatprovidesdata
  *
  */
+
 Id
-pool_queuetowhatprovides(Pool *pool, Queue *q)
+pool_ids2whatprovides(Pool *pool, Id *ids, int count)
 {
   Offset off;
-  int count = q->count;
 
   if (count == 0)                     /* queue empty -> 1 */
     return 1;
-  if (count == 1 && q->elements[0] == SYSTEMSOLVABLE)
+  if (count == 1 && *ids == SYSTEMSOLVABLE)
     return 2;
 
   /* extend whatprovidesdata if needed, +1 for 0-termination */
@@ -570,7 +642,7 @@ pool_queuetowhatprovides(Pool *pool, Queue *q)
 
   /* copy queue to next free slot */
   off = pool->whatprovidesdataoff;
-  memcpy(pool->whatprovidesdata + pool->whatprovidesdataoff, q->elements, count * sizeof(Id));
+  memcpy(pool->whatprovidesdata + pool->whatprovidesdataoff, ids, count * sizeof(Id));
 
   /* adapt count and 0-terminate */
   pool->whatprovidesdataoff += count;
@@ -580,6 +652,17 @@ pool_queuetowhatprovides(Pool *pool, Queue *q)
   return (Id)off;
 }
 
+Id
+pool_queuetowhatprovides(Pool *pool, Queue *q)
+{
+  int count = q->count;
+  if (count == 0)                     /* queue empty -> 1 */
+    return 1;
+  if (count == 1 && q->elements[0] == SYSTEMSOLVABLE)
+    return 2;
+  return pool_ids2whatprovides(pool, q->elements, count);
+}
+
 
 /*************************************************************************/
 
@@ -622,6 +705,10 @@ pool_match_nevr_rel(Pool *pool, Solvable *s, Id d)
          if (!pool_match_nevr(pool, s, name))
            return 0;
          return pool_match_nevr(pool, s, evr);
+       case REL_WITHOUT:
+         if (!pool_match_nevr(pool, s, name))
+           return 0;
+         return !pool_match_nevr(pool, s, evr);
        case REL_MULTIARCH:
          if (evr != ARCH_ANY)
            return 0;
@@ -716,7 +803,7 @@ pool_match_flags_evr_rel_compat(Pool *pool, Reldep *range, int flags, int evr)
 
 /* public (i.e. not inlined) version of pool_match_flags_evr */
 int
-pool_intersect_evrs(Pool *pool, int pflags, Id pevr, int flags, int evr)
+pool_intersect_evrs(Pool *pool, int pflags, Id pevr, int flags, Id evr)
 {
   return pool_match_flags_evr(pool, pflags, pevr, flags, evr);
 }
@@ -730,10 +817,49 @@ pool_match_dep(Pool *pool, Id d1, Id d2)
 
   if (d1 == d2)
     return 1;
+
+  if (ISRELDEP(d1))
+    {
+      /* we use potentially matches for complex deps */
+      rd1 = GETRELDEP(pool, d1);
+      if (rd1->flags == REL_AND || rd1->flags == REL_OR || rd1->flags == REL_WITH || rd1->flags == REL_WITHOUT || rd1->flags == REL_COND || rd1->flags == REL_UNLESS)
+       {
+         if (pool_match_dep(pool, rd1->name, d2))
+           return 1;
+         if ((rd1->flags == REL_COND || rd1->flags == REL_UNLESS) && ISRELDEP(rd1->evr))
+           {
+             rd1 = GETRELDEP(pool, rd1->evr);
+             if (rd1->flags != REL_ELSE)
+               return 0;
+           }
+         if (rd1->flags != REL_COND && rd1->flags != REL_UNLESS && rd1->flags != REL_WITHOUT && pool_match_dep(pool, rd1->evr, d2))
+           return 1;
+         return 0;
+       }
+    }
+  if (ISRELDEP(d2))
+    {
+      /* we use potentially matches for complex deps */
+      rd2 = GETRELDEP(pool, d2);
+      if (rd2->flags == REL_AND || rd2->flags == REL_OR || rd2->flags == REL_WITH || rd2->flags == REL_WITHOUT || rd2->flags == REL_COND || rd2->flags == REL_UNLESS)
+       {
+         if (pool_match_dep(pool, d1, rd2->name))
+           return 1;
+         if ((rd2->flags == REL_COND || rd2->flags == REL_UNLESS) && ISRELDEP(rd2->evr))
+           {
+             rd2 = GETRELDEP(pool, rd2->evr);
+             if (rd2->flags != REL_ELSE)
+               return 0;
+           }
+         if (rd2->flags != REL_COND && rd2->flags != REL_UNLESS && rd2->flags != REL_WITHOUT && pool_match_dep(pool, d1, rd2->evr))
+           return 1;
+         return 0;
+       }
+    }
   if (!ISRELDEP(d1))
     {
       if (!ISRELDEP(d2))
-       return 0;
+       return 0;       /* cannot match as d1 != d2 */
       rd2 = GETRELDEP(pool, d2);
       return pool_match_dep(pool, d1, rd2->name);
     }
@@ -876,6 +1002,64 @@ pool_is_kind(Pool *pool, Id name, Id kind)
 }
 
 /*
+ * rpm eq magic:
+ *
+ * some dependencies are of the from "foo = md5sum", like the
+ * buildid provides. There's not much we can do to speed up
+ * getting the providers, because rpm's complex evr comparison
+ * rules get in the way. But we can use the first character(s)
+ * of the md5sum to do a simple pre-check.
+ */
+static inline int
+rpmeqmagic(Pool *pool, Id evr)
+{
+  const char *s = pool_id2str(pool, evr);
+  if (*s == '0')
+    {
+      while (*s == '0' && s[1] >= '0' && s[1] <= '9')
+       s++;
+      /* ignore epoch 0 */
+      if (*s == '0' && s[1] == ':')
+       {
+         s += 2;
+         while (*s == '0' && s[1] >= '0' && s[1] <= '9')
+           s++;
+       }
+    }
+  if (*s >= '0' && *s <= '9')
+    {
+      if (s[1] >= '0' && s[1] <= '9')
+        return *s + (s[1] << 8);
+      return *s;
+    }
+  if ((*s >= 'a' && *s <= 'z') || (*s >= 'A' && *s <= 'Z'))
+    {
+      if ((s[1] >= 'a' && s[1] <= 'z') || (s[1] >= 'A' && s[1] <= 'Z'))
+        return *s + (s[1] << 8);
+      return *s;
+    }
+  return -1;
+}
+
+static inline int
+rpmeqmagic_init(Pool *pool, int flags, Id evr)
+{
+  if (flags != REL_EQ || pool->disttype != DISTTYPE_RPM || pool->promoteepoch || ISRELDEP(evr))
+    return -1;
+  else
+    return rpmeqmagic(pool, evr);
+}
+
+static inline int
+rpmeqmagic_cantmatch(Pool *pool, int flags, Id evr, int eqmagic)
+{
+  int peqmagic = rpmeqmagic(pool, evr);
+  if (peqmagic > 0 && peqmagic != eqmagic)
+    return 1;
+  return 0;
+}
+
+/*
  * addrelproviders
  *
  * add packages fulfilling the relation to whatprovides array
@@ -928,13 +1112,39 @@ pool_addrelproviders(Pool *pool, Id d)
                wp = 0;
            }
          break;
-
+       case REL_WITHOUT:
+         wp = pool_whatprovides(pool, name);
+         pp2 = pool_whatprovides_ptr(pool, evr);
+         pp = pool->whatprovidesdata + wp;
+         while ((p = *pp++) != 0)
+           {
+             for (pp3 = pp2; *pp3; pp3++)
+               if (*pp3 == p)
+                 break;
+             if (!*pp3)
+               queue_push(&plist, p);  /* use it */
+             else
+               wp = 0;
+           }
+         break;
        case REL_AND:
        case REL_OR:
+       case REL_COND:
+       case REL_UNLESS:
+         if (flags == REL_COND || flags == REL_UNLESS)
+           {
+             if (ISRELDEP(evr))
+               {
+                 Reldep *rd2 = GETRELDEP(pool, evr);
+                 evr = rd2->flags == REL_ELSE ? rd2->evr : 0;
+               }
+             else
+               evr = 0;        /* assume cond is true */
+           }
          wp = pool_whatprovides(pool, name);
          if (!pool->whatprovidesdata[wp])
-           wp = pool_whatprovides(pool, evr);
-         else
+           wp = evr ? pool_whatprovides(pool, evr) : 1;
+         else if (evr)
            {
              /* sorted merge */
              pp2 = pool_whatprovides_ptr(pool, evr);
@@ -960,11 +1170,6 @@ pool_addrelproviders(Pool *pool, Id d)
            }
          break;
 
-       case REL_COND:
-         /* assume the condition is true */
-         wp = pool_whatprovides(pool, name);
-         break;
-
        case REL_NAMESPACE:
          if (name == NAMESPACE_OTHERPROVIDERS)
            {
@@ -1089,11 +1294,15 @@ pool_addrelproviders(Pool *pool, Id d)
     }
   else if (flags)
     {
+      Id *ppaux = 0;
+      int eqmagic = 0;
       /* simple version comparison relation */
 #if 0
       POOL_DEBUG(SOLV_DEBUG_STATS, "addrelproviders: what provides %s?\n", pool_dep2str(pool, name));
 #endif
       pp = pool_whatprovides_ptr(pool, name);
+      if (!ISRELDEP(name) && name < pool->whatprovidesauxoff)
+       ppaux = pool->whatprovidesaux[name] ? pool->whatprovidesauxdata + pool->whatprovidesaux[name] : 0;
       while (ISRELDEP(name))
        {
           rd = GETRELDEP(pool, name);
@@ -1102,6 +1311,39 @@ pool_addrelproviders(Pool *pool, Id d)
       while ((p = *pp++) != 0)
        {
          Solvable *s = pool->solvables + p;
+         if (ppaux)
+           {
+             pid = *ppaux++;
+             if (pid && pid != 1)
+               {
+#if 0
+                 POOL_DEBUG(SOLV_DEBUG_STATS, "addrelproviders: aux hit %d %s\n", p, pool_dep2str(pool, pid));
+#endif
+                 if (!ISRELDEP(pid))
+                   {
+                     if (pid != name)
+                       continue;               /* wrong provides name */
+                     if (pool->disttype == DISTTYPE_DEB)
+                       continue;               /* unversioned provides can never match versioned deps */
+                   }
+                 else
+                   {
+                     prd = GETRELDEP(pool, pid);
+                     if (prd->name != name)
+                       continue;               /* wrong provides name */
+                     if (!eqmagic)
+                       eqmagic = rpmeqmagic_init(pool, flags, evr);
+                     if (eqmagic > 0 && prd->flags == REL_EQ && !ISRELDEP(prd->evr) &&
+                         rpmeqmagic_cantmatch(pool, prd->flags, prd->evr, eqmagic))
+                       continue;
+                     /* right package, both deps are rels. check flags/evr */
+                     if (!pool_match_flags_evr(pool, prd->flags, prd->evr, flags, evr))
+                       continue;
+                   }
+                 queue_push(&plist, p);
+                 continue;
+               }
+           }
          if (!s->provides)
            {
              /* no provides - check nevr */
@@ -1110,6 +1352,8 @@ pool_addrelproviders(Pool *pool, Id d)
              continue;
            }
          /* solvable p provides name in some rels */
+         if (!eqmagic)
+           eqmagic = rpmeqmagic_init(pool, flags, evr);
          pidp = s->repo->idarraydata + s->provides;
          while ((pid = *pidp++) != 0)
            {
@@ -1125,6 +1369,9 @@ pool_addrelproviders(Pool *pool, Id d)
              if (prd->name != name)
                continue;               /* wrong provides name */
              /* right package, both deps are rels. check flags/evr */
+             if (eqmagic > 0 && prd->flags == REL_EQ && !ISRELDEP(prd->evr) &&
+                 rpmeqmagic_cantmatch(pool, prd->flags, prd->evr, eqmagic))
+               continue;
              if (pool_match_flags_evr(pool, prd->flags, prd->evr, flags, evr))
                break;  /* matches */
            }
@@ -1163,7 +1410,8 @@ pool_flush_namespaceproviders(Pool *pool, Id ns, Id evr)
        continue;
       if (evr && rd->evr != evr)
        continue;
-      pool->whatprovides_rel[d] = 0;
+      if (pool->whatprovides_rel[d])
+        pool_set_whatprovides(pool, MAKERELDEP(d), 0);
     }
 }
 
@@ -1172,8 +1420,19 @@ void
 pool_whatmatchesdep(Pool *pool, Id keyname, Id dep, Queue *q, int marker)
 {
   Id p;
+  Queue qq;
+  int i;
 
   queue_empty(q);
+  if (keyname == SOLVABLE_NAME)
+    {
+      Id pp;
+      FOR_PROVIDES(p, pp, dep)
+        if (pool_match_dep(pool, p, dep))
+         queue_push(q, p);
+      return;
+    }
+  queue_init(&qq);
   FOR_POOL_SOLVABLES(p)
     {
       Solvable *s = pool->solvables + p;
@@ -1181,9 +1440,49 @@ pool_whatmatchesdep(Pool *pool, Id keyname, Id dep, Queue *q, int marker)
        continue;
       if (s->repo != pool->installed && !pool_installable(pool, s))
        continue;
-      if (solvable_matchesdep(s, keyname, dep, marker))
-       queue_push(q, p);
+      if (qq.count)
+       queue_empty(&qq);
+      solvable_lookup_deparray(s, keyname, &qq, marker);
+      for (i = 0; i < qq.count; i++)
+       if (pool_match_dep(pool, qq.elements[i], dep))
+         {
+           queue_push(q, p);
+           break;
+         }
     }
+  queue_free(&qq);
+}
+
+/* check if keyname contains dep, return list of matching packages */
+void
+pool_whatcontainsdep(Pool *pool, Id keyname, Id dep, Queue *q, int marker)
+{
+  Id p;
+  Queue qq;
+  int i;
+
+  queue_empty(q);
+  if (!dep)
+    return;
+  queue_init(&qq);
+  FOR_POOL_SOLVABLES(p)
+    {
+      Solvable *s = pool->solvables + p;
+      if (s->repo->disabled)
+        continue;
+      if (s->repo != pool->installed && !pool_installable(pool, s))
+        continue;
+      if (qq.count)
+        queue_empty(&qq);
+      solvable_lookup_deparray(s, keyname, &qq, marker);
+      for (i = 0; i < qq.count; i++)
+        if (qq.elements[i] == dep)
+          {
+            queue_push(q, p);
+            break;
+          }
+    }
+  queue_free(&qq);
 }
 
 /*************************************************************************/
@@ -1218,6 +1517,9 @@ pool_error(Pool *pool, int ret, const char *format, ...)
 {
   va_list args;
   int l;
+
+  if (!pool)
+    return ret;
   va_start(args, format);
   if (!pool->errstr)
     {
@@ -1292,359 +1594,6 @@ void pool_setnamespacecallback(Pool *pool, Id (*cb)(struct _Pool *, void *, Id,
   pool->nscallbackdata = nscbdata;
 }
 
-/*************************************************************************/
-
-struct searchfiles {
-  Id *ids;
-  int nfiles;
-  Map seen;
-};
-
-#define SEARCHFILES_BLOCK 127
-
-static void
-pool_addfileprovides_dep(Pool *pool, Id *ida, struct searchfiles *sf, struct searchfiles *isf)
-{
-  Id dep, sid;
-  const char *s;
-  struct searchfiles *csf;
-
-  while ((dep = *ida++) != 0)
-    {
-      csf = sf;
-      while (ISRELDEP(dep))
-       {
-         Reldep *rd;
-         sid = pool->ss.nstrings + GETRELID(dep);
-         if (MAPTST(&csf->seen, sid))
-           {
-             dep = 0;
-             break;
-           }
-         MAPSET(&csf->seen, sid);
-         rd = GETRELDEP(pool, dep);
-         if (rd->flags < 8)
-           dep = rd->name;
-         else if (rd->flags == REL_NAMESPACE)
-           {
-             if (rd->name == NAMESPACE_INSTALLED || rd->name == NAMESPACE_SPLITPROVIDES)
-               {
-                 csf = isf;
-                 if (!csf || MAPTST(&csf->seen, sid))
-                   {
-                     dep = 0;
-                     break;
-                   }
-                 MAPSET(&csf->seen, sid);
-               }
-             dep = rd->evr;
-           }
-         else if (rd->flags == REL_FILECONFLICT)
-           {
-             dep = 0;
-             break;
-           }
-         else
-           {
-             Id ids[2];
-             ids[0] = rd->name;
-             ids[1] = 0;
-             pool_addfileprovides_dep(pool, ids, csf, isf);
-             dep = rd->evr;
-           }
-       }
-      if (!dep)
-       continue;
-      if (MAPTST(&csf->seen, dep))
-       continue;
-      MAPSET(&csf->seen, dep);
-      s = pool_id2str(pool, dep);
-      if (*s != '/')
-       continue;
-      if (csf != isf && pool->addedfileprovides == 1 && !repodata_filelistfilter_matches(0, s))
-       continue;       /* skip non-standard locations csf == isf: installed case */
-      csf->ids = solv_extend(csf->ids, csf->nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
-      csf->ids[csf->nfiles++] = dep;
-    }
-}
-
-struct addfileprovides_cbdata {
-  int nfiles;
-  Id *ids;
-  char **dirs;
-  char **names;
-
-  Id *dids;
-
-  Map providedids;
-
-  Map useddirs;
-};
-
-static int
-addfileprovides_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
-{
-  struct addfileprovides_cbdata *cbd = cbdata;
-  int i;
-
-  if (!cbd->useddirs.size)
-    {
-      map_init(&cbd->useddirs, data->dirpool.ndirs + 1);
-      if (!cbd->dirs)
-       {
-         cbd->dirs = solv_malloc2(cbd->nfiles, sizeof(char *));
-         cbd->names = solv_malloc2(cbd->nfiles, sizeof(char *));
-         for (i = 0; i < cbd->nfiles; i++)
-           {
-             char *s = solv_strdup(pool_id2str(data->repo->pool, cbd->ids[i]));
-             cbd->dirs[i] = s;
-             s = strrchr(s, '/');
-             *s = 0;
-             cbd->names[i] = s + 1;
-           }
-       }
-      for (i = 0; i < cbd->nfiles; i++)
-       {
-         Id did;
-         if (MAPTST(&cbd->providedids, cbd->ids[i]))
-           {
-             cbd->dids[i] = 0;
-             continue;
-           }
-         did = repodata_str2dir(data, cbd->dirs[i], 0);
-         cbd->dids[i] = did;
-         if (did)
-           MAPSET(&cbd->useddirs, did);
-       }
-      repodata_free_dircache(data);
-    }
-  if (value->id >= data->dirpool.ndirs || !MAPTST(&cbd->useddirs, value->id))
-    return 0;
-  for (i = 0; i < cbd->nfiles; i++)
-    if (cbd->dids[i] != value->id && !strcmp(cbd->names[i], value->str))
-      break;
-  if (i < cbd->nfiles)
-    s->provides = repo_addid_dep(s->repo, s->provides, cbd->ids[i], SOLVABLE_FILEMARKER);
-  return 0;
-}
-
-static void
-pool_addfileprovides_search(Pool *pool, struct addfileprovides_cbdata *cbd, struct searchfiles *sf, Repo *repoonly)
-{
-  Id p;
-  Repodata *data;
-  Repo *repo;
-  Queue fileprovidesq;
-  int i, j, repoid, repodataid;
-  int provstart, provend;
-  Map donemap;
-  int ndone, incomplete;
-
-  if (!pool->urepos)
-    return;
-
-  cbd->nfiles = sf->nfiles;
-  cbd->ids = sf->ids;
-  cbd->dirs = 0;
-  cbd->names = 0;
-  cbd->dids = solv_realloc2(cbd->dids, sf->nfiles, sizeof(Id));
-  map_init(&cbd->providedids, pool->ss.nstrings);
-
-  repoid = 1;
-  repo = repoonly ? repoonly : pool->repos[repoid];
-  map_init(&donemap, pool->nsolvables);
-  queue_init(&fileprovidesq);
-  provstart = provend = 0;
-  for (;;)
-    {
-      if (!repo || repo->disabled)
-       {
-         if (repoonly || ++repoid == pool->nrepos)
-           break;
-         repo = pool->repos[repoid];
-         continue;
-       }
-      ndone = 0;
-      FOR_REPODATAS(repo, repodataid, data)
-       {
-         if (ndone >= repo->nsolvables)
-           break;
-
-         if (repodata_lookup_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, &fileprovidesq))
-           {
-             map_empty(&cbd->providedids);
-             for (i = 0; i < fileprovidesq.count; i++)
-               MAPSET(&cbd->providedids, fileprovidesq.elements[i]);
-             provstart = data->start;
-             provend = data->end;
-             for (i = 0; i < cbd->nfiles; i++)
-               if (!MAPTST(&cbd->providedids, cbd->ids[i]))
-                 break;
-             if (i == cbd->nfiles)
-               {
-                 /* great! no need to search files */
-                 for (p = data->start; p < data->end; p++)
-                   if (pool->solvables[p].repo == repo)
-                     {
-                       if (MAPTST(&donemap, p))
-                         continue;
-                       MAPSET(&donemap, p);
-                       ndone++;
-                     }
-                 continue;
-               }
-           }
-
-         if (!repodata_has_keyname(data, SOLVABLE_FILELIST))
-           continue;
-
-         if (data->start < provstart || data->end > provend)
-           {
-             map_empty(&cbd->providedids);
-             provstart = provend = 0;
-           }
-
-         /* check if the data is incomplete */
-         incomplete = 0;
-         if (data->state == REPODATA_AVAILABLE)
-           {
-             for (j = 1; j < data->nkeys; j++)
-               if (data->keys[j].name != REPOSITORY_SOLVABLES && data->keys[j].name != SOLVABLE_FILELIST)
-                 break;
-             if (j < data->nkeys)
-               {
-#if 0
-                 for (i = 0; i < cbd->nfiles; i++)
-                   if (!MAPTST(&cbd->providedids, cbd->ids[i]) && !repodata_filelistfilter_matches(data, pool_id2str(pool, cbd->ids[i])))
-                     printf("need complete filelist because of %s\n", pool_id2str(pool, cbd->ids[i]));
-#endif
-                 for (i = 0; i < cbd->nfiles; i++)
-                   if (!MAPTST(&cbd->providedids, cbd->ids[i]) && !repodata_filelistfilter_matches(data, pool_id2str(pool, cbd->ids[i])))
-                     break;
-                 if (i < cbd->nfiles)
-                   incomplete = 1;
-               }
-           }
-
-         /* do the search */
-         map_init(&cbd->useddirs, 0);
-         for (p = data->start; p < data->end; p++)
-           if (pool->solvables[p].repo == repo)
-             {
-               if (MAPTST(&donemap, p))
-                 continue;
-               repodata_search(data, p, SOLVABLE_FILELIST, 0, addfileprovides_cb, cbd);
-               if (!incomplete)
-                 {
-                   MAPSET(&donemap, p);
-                   ndone++;
-                 }
-             }
-         map_free(&cbd->useddirs);
-       }
-
-      if (repoonly || ++repoid == pool->nrepos)
-       break;
-      repo = pool->repos[repoid];
-    }
-  map_free(&donemap);
-  queue_free(&fileprovidesq);
-  map_free(&cbd->providedids);
-  if (cbd->dirs)
-    {
-      for (i = 0; i < cbd->nfiles; i++)
-       solv_free(cbd->dirs[i]);
-      cbd->dirs = solv_free(cbd->dirs);
-      cbd->names = solv_free(cbd->names);
-    }
-}
-
-void
-pool_addfileprovides_queue(Pool *pool, Queue *idq, Queue *idqinst)
-{
-  Solvable *s;
-  Repo *installed, *repo;
-  struct searchfiles sf, isf, *isfp;
-  struct addfileprovides_cbdata cbd;
-  int i;
-  unsigned int now;
-
-  installed = pool->installed;
-  now = solv_timems(0);
-  memset(&sf, 0, sizeof(sf));
-  map_init(&sf.seen, pool->ss.nstrings + pool->nrels);
-  memset(&isf, 0, sizeof(isf));
-  map_init(&isf.seen, pool->ss.nstrings + pool->nrels);
-  pool->addedfileprovides = pool->addfileprovidesfiltered ? 1 : 2;
-
-  if (idq)
-    queue_empty(idq);
-  if (idqinst)
-    queue_empty(idqinst);
-  isfp = installed ? &isf : 0;
-  for (i = 1, s = pool->solvables + i; i < pool->nsolvables; i++, s++)
-    {
-      repo = s->repo;
-      if (!repo)
-       continue;
-      if (s->obsoletes)
-        pool_addfileprovides_dep(pool, repo->idarraydata + s->obsoletes, &sf, isfp);
-      if (s->conflicts)
-        pool_addfileprovides_dep(pool, repo->idarraydata + s->conflicts, &sf, isfp);
-      if (s->requires)
-        pool_addfileprovides_dep(pool, repo->idarraydata + s->requires, &sf, isfp);
-      if (s->recommends)
-        pool_addfileprovides_dep(pool, repo->idarraydata + s->recommends, &sf, isfp);
-      if (s->suggests)
-        pool_addfileprovides_dep(pool, repo->idarraydata + s->suggests, &sf, isfp);
-      if (s->supplements)
-        pool_addfileprovides_dep(pool, repo->idarraydata + s->supplements, &sf, isfp);
-      if (s->enhances)
-        pool_addfileprovides_dep(pool, repo->idarraydata + s->enhances, &sf, isfp);
-    }
-  map_free(&sf.seen);
-  map_free(&isf.seen);
-  POOL_DEBUG(SOLV_DEBUG_STATS, "found %d file dependencies, %d installed file dependencies\n", sf.nfiles, isf.nfiles);
-  cbd.dids = 0;
-  if (sf.nfiles)
-    {
-#if 0
-      for (i = 0; i < sf.nfiles; i++)
-       POOL_DEBUG(SOLV_DEBUG_STATS, "looking up %s in filelist\n", pool_id2str(pool, sf.ids[i]));
-#endif
-      pool_addfileprovides_search(pool, &cbd, &sf, 0);
-      if (idq)
-        for (i = 0; i < sf.nfiles; i++)
-         queue_push(idq, sf.ids[i]);
-      if (idqinst)
-        for (i = 0; i < sf.nfiles; i++)
-         queue_push(idqinst, sf.ids[i]);
-      solv_free(sf.ids);
-    }
-  if (isf.nfiles)
-    {
-#if 0
-      for (i = 0; i < isf.nfiles; i++)
-       POOL_DEBUG(SOLV_DEBUG_STATS, "looking up %s in installed filelist\n", pool_id2str(pool, isf.ids[i]));
-#endif
-      if (installed)
-        pool_addfileprovides_search(pool, &cbd, &isf, installed);
-      if (installed && idqinst)
-        for (i = 0; i < isf.nfiles; i++)
-         queue_pushunique(idqinst, isf.ids[i]);
-      solv_free(isf.ids);
-    }
-  solv_free(cbd.dids);
-  pool_freewhatprovides(pool); /* as we have added provides */
-  POOL_DEBUG(SOLV_DEBUG_STATS, "addfileprovides took %d ms\n", solv_timems(now));
-}
-
-void
-pool_addfileprovides(Pool *pool)
-{
-  pool_addfileprovides_queue(pool, 0, 0);
-}
-
 void
 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)
 {
@@ -1666,7 +1615,6 @@ pool_clear_pos(Pool *pool)
   memset(&pool->pos, 0, sizeof(pool->pos));
 }
 
-
 void
 pool_set_languages(Pool *pool, const char **languages, int nlanguages)
 {
@@ -1676,7 +1624,7 @@ pool_set_languages(Pool *pool, const char **languages, int nlanguages)
   pool->languagecacheother = 0;
   for (i = 0; i < pool->nlanguages; i++)
     free((char *)pool->languages[i]);
-  pool->languages = solv_free(pool->languages);
+  pool->languages = solv_free((void *)pool->languages);
   pool->nlanguages = nlanguages;
   if (!nlanguages)
     return;
@@ -1833,510 +1781,6 @@ pool_bin2hex(Pool *pool, const unsigned char *buf, int len)
   return s;
 }
 
-/*******************************************************************/
-
-struct mptree {
-  Id sibling;
-  Id child;
-  const char *comp;
-  int compl;
-  Id mountpoint;
-};
-
-struct ducbdata {
-  DUChanges *mps;
-  struct mptree *mptree;
-  int addsub;
-  int hasdu;
-
-  Id *dirmap;
-  int nmap;
-  Repodata *olddata;
-};
-
-
-static int
-solver_fill_DU_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
-{
-  struct ducbdata *cbd = cbdata;
-  Id mp;
-
-  if (data != cbd->olddata)
-    {
-      Id dn, mp, comp, *dirmap, *dirs;
-      int i, compl;
-      const char *compstr;
-      struct mptree *mptree;
-
-      /* create map from dir to mptree */
-      cbd->dirmap = solv_free(cbd->dirmap);
-      cbd->nmap = 0;
-      dirmap = solv_calloc(data->dirpool.ndirs, sizeof(Id));
-      mptree = cbd->mptree;
-      mp = 0;
-      for (dn = 2, dirs = data->dirpool.dirs + dn; dn < data->dirpool.ndirs; dn++)
-       {
-         comp = *dirs++;
-         if (comp <= 0)
-           {
-             mp = dirmap[-comp];
-             continue;
-           }
-         if (mp < 0)
-           {
-             /* unconnected */
-             dirmap[dn] = mp;
-             continue;
-           }
-         if (!mptree[mp].child)
-           {
-             dirmap[dn] = -mp;
-             continue;
-           }
-         if (data->localpool)
-           compstr = stringpool_id2str(&data->spool, comp);
-         else
-           compstr = pool_id2str(data->repo->pool, comp);
-         compl = strlen(compstr);
-         for (i = mptree[mp].child; i; i = mptree[i].sibling)
-           if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
-             break;
-         dirmap[dn] = i ? i : -mp;
-       }
-      /* change dirmap to point to mountpoint instead of mptree */
-      for (dn = 0; dn < data->dirpool.ndirs; dn++)
-       {
-         mp = dirmap[dn];
-         dirmap[dn] = mptree[mp > 0 ? mp : -mp].mountpoint;
-       }
-      cbd->dirmap = dirmap;
-      cbd->nmap = data->dirpool.ndirs;
-      cbd->olddata = data;
-    }
-  cbd->hasdu = 1;
-  if (value->id < 0 || value->id >= cbd->nmap)
-    return 0;
-  mp = cbd->dirmap[value->id];
-  if (mp < 0)
-    return 0;
-  if (cbd->addsub > 0)
-    {
-      cbd->mps[mp].kbytes += value->num;
-      cbd->mps[mp].files += value->num2;
-    }
-  else
-    {
-      cbd->mps[mp].kbytes -= value->num;
-      cbd->mps[mp].files -= value->num2;
-    }
-  return 0;
-}
-
-static void
-propagate_mountpoints(struct mptree *mptree, int pos, Id mountpoint)
-{
-  int i;
-  if (mptree[pos].mountpoint == -1)
-    mptree[pos].mountpoint = mountpoint;
-  else
-    mountpoint = mptree[pos].mountpoint;
-  for (i = mptree[pos].child; i; i = mptree[i].sibling)
-    propagate_mountpoints(mptree, i, mountpoint);
-}
-
-#define MPTREE_BLOCK 15
-
-static struct mptree *
-create_mptree(DUChanges *mps, int nmps)
-{
-  int i, nmptree;
-  struct mptree *mptree;
-  int pos, compl;
-  int mp;
-  const char *p, *path, *compstr;
-
-  mptree = solv_extend_resize(0, 1, sizeof(struct mptree), MPTREE_BLOCK);
-
-  /* our root node */
-  mptree[0].sibling = 0;
-  mptree[0].child = 0;
-  mptree[0].comp = 0;
-  mptree[0].compl = 0;
-  mptree[0].mountpoint = -1;
-  nmptree = 1;
-
-  /* create component tree */
-  for (mp = 0; mp < nmps; mp++)
-    {
-      mps[mp].kbytes = 0;
-      mps[mp].files = 0;
-      pos = 0;
-      path = mps[mp].path;
-      while(*path == '/')
-       path++;
-      while (*path)
-       {
-         if ((p = strchr(path, '/')) == 0)
-           {
-             compstr = path;
-             compl = strlen(compstr);
-             path += compl;
-           }
-         else
-           {
-             compstr = path;
-             compl = p - path;
-             path = p + 1;
-             while(*path == '/')
-               path++;
-           }
-          for (i = mptree[pos].child; i; i = mptree[i].sibling)
-           if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
-             break;
-         if (!i)
-           {
-             /* create new node */
-             mptree = solv_extend(mptree, nmptree, 1, sizeof(struct mptree), MPTREE_BLOCK);
-             i = nmptree++;
-             mptree[i].sibling = mptree[pos].child;
-             mptree[i].child = 0;
-             mptree[i].comp = compstr;
-             mptree[i].compl = compl;
-             mptree[i].mountpoint = -1;
-             mptree[pos].child = i;
-           }
-         pos = i;
-       }
-      mptree[pos].mountpoint = mp;
-    }
-
-  propagate_mountpoints(mptree, 0, mptree[0].mountpoint);
-
-#if 0
-  for (i = 0; i < nmptree; i++)
-    {
-      printf("#%d sibling: %d\n", i, mptree[i].sibling);
-      printf("#%d child: %d\n", i, mptree[i].child);
-      printf("#%d comp: %s\n", i, mptree[i].comp);
-      printf("#%d compl: %d\n", i, mptree[i].compl);
-      printf("#%d mountpont: %d\n", i, mptree[i].mountpoint);
-    }
-#endif
-
-  return mptree;
-}
-
-void
-pool_calc_duchanges(Pool *pool, Map *installedmap, DUChanges *mps, int nmps)
-{
-  struct mptree *mptree;
-  struct ducbdata cbd;
-  Solvable *s;
-  int sp;
-  Map ignoredu;
-  Repo *oldinstalled = pool->installed;
-
-  map_init(&ignoredu, 0);
-  mptree = create_mptree(mps, nmps);
-
-  cbd.mps = mps;
-  cbd.dirmap = 0;
-  cbd.nmap = 0;
-  cbd.olddata = 0;
-  cbd.mptree = mptree;
-  cbd.addsub = 1;
-  for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
-    {
-      if (!s->repo || (oldinstalled && s->repo == oldinstalled))
-       continue;
-      if (!MAPTST(installedmap, sp))
-       continue;
-      cbd.hasdu = 0;
-      repo_search(s->repo, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
-      if (!cbd.hasdu && oldinstalled)
-       {
-         Id op, opp;
-         /* no du data available, ignore data of all installed solvables we obsolete */
-         if (!ignoredu.size)
-           map_grow(&ignoredu, oldinstalled->end - oldinstalled->start);
-         if (s->obsoletes)
-           {
-             Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
-             while ((obs = *obsp++) != 0)
-               FOR_PROVIDES(op, opp, obs)
-                 if (op >= oldinstalled->start && op < oldinstalled->end)
-                   MAPSET(&ignoredu, op - oldinstalled->start);
-           }
-         FOR_PROVIDES(op, opp, s->name)
-           if (pool->solvables[op].name == s->name)
-             if (op >= oldinstalled->start && op < oldinstalled->end)
-               MAPSET(&ignoredu, op - oldinstalled->start);
-       }
-    }
-  cbd.addsub = -1;
-  if (oldinstalled)
-    {
-      /* assumes we allways have du data for installed solvables */
-      FOR_REPO_SOLVABLES(oldinstalled, sp, s)
-       {
-         if (MAPTST(installedmap, sp))
-           continue;
-         if (ignoredu.map && MAPTST(&ignoredu, sp - oldinstalled->start))
-           continue;
-         repo_search(oldinstalled, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
-       }
-    }
-  map_free(&ignoredu);
-  solv_free(cbd.dirmap);
-  solv_free(mptree);
-}
-
-int
-pool_calc_installsizechange(Pool *pool, Map *installedmap)
-{
-  Id sp;
-  Solvable *s;
-  int change = 0;
-  Repo *oldinstalled = pool->installed;
-
-  for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
-    {
-      if (!s->repo || (oldinstalled && s->repo == oldinstalled))
-       continue;
-      if (!MAPTST(installedmap, sp))
-       continue;
-      change += solvable_lookup_sizek(s, SOLVABLE_INSTALLSIZE, 0);
-    }
-  if (oldinstalled)
-    {
-      FOR_REPO_SOLVABLES(oldinstalled, sp, s)
-       {
-         if (MAPTST(installedmap, sp))
-           continue;
-         change -= solvable_lookup_sizek(s, SOLVABLE_INSTALLSIZE, 0);
-       }
-    }
-  return change;
-}
-
-/* map:
- *  1: installed
- *  2: conflicts with installed
- *  8: interesting (only true if installed)
- * 16: undecided
- */
-
-static inline Id dep2name(Pool *pool, Id dep)
-{
-  while (ISRELDEP(dep))
-    {
-      Reldep *rd = GETRELDEP(pool, dep);
-      dep = rd->name;
-    }
-  return dep;
-}
-
-static int providedbyinstalled_multiversion(Pool *pool, unsigned char *map, Id n, Id con)
-{
-  Id p, pp;
-  Solvable *sn = pool->solvables + n;
-
-  FOR_PROVIDES(p, pp, sn->name)
-    {
-      Solvable *s = pool->solvables + p;
-      if (s->name != sn->name || s->arch != sn->arch)
-        continue;
-      if ((map[p] & 9) != 9)
-        continue;
-      if (pool_match_nevr(pool, pool->solvables + p, con))
-       continue;
-      return 1;                /* found installed package that doesn't conflict */
-    }
-  return 0;
-}
-
-static inline int providedbyinstalled(Pool *pool, unsigned char *map, Id dep, int ispatch, Map *multiversionmap)
-{
-  Id p, pp;
-  int r = 0;
-  FOR_PROVIDES(p, pp, dep)
-    {
-      if (p == SYSTEMSOLVABLE)
-        return 1;      /* always boring, as never constraining */
-      if (ispatch && !pool_match_nevr(pool, pool->solvables + p, dep))
-       continue;
-      if (ispatch && multiversionmap && multiversionmap->size && MAPTST(multiversionmap, p) && ISRELDEP(dep))
-       if (providedbyinstalled_multiversion(pool, map, p, dep))
-         continue;
-      if ((map[p] & 9) == 9)
-       return 9;
-      r |= map[p] & 17;
-    }
-  return r;
-}
-
-/*
- * pool_trivial_installable - calculate if a set of solvables is
- * trivial installable without any other installs/deinstalls of
- * packages not belonging to the set.
- *
- * the state is returned in the result queue:
- * 1:  solvable is installable without any other package changes
- * 0:  solvable is not installable
- * -1: solvable is installable, but doesn't constrain any installed packages
- */
-
-void
-pool_trivial_installable_multiversionmap(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res, Map *multiversionmap)
-{
-  int i, r, m, did;
-  Id p, *dp, con, *conp, req, *reqp;
-  unsigned char *map;
-  Solvable *s;
-
-  map = solv_calloc(pool->nsolvables, 1);
-  for (p = 1; p < pool->nsolvables; p++)
-    {
-      if (!MAPTST(installedmap, p))
-       continue;
-      map[p] |= 9;
-      s = pool->solvables + p;
-      if (!s->conflicts)
-       continue;
-      conp = s->repo->idarraydata + s->conflicts;
-      while ((con = *conp++) != 0)
-       {
-         dp = pool_whatprovides_ptr(pool, con);
-         for (; *dp; dp++)
-           map[p] |= 2;        /* XXX: self conflict ? */
-       }
-    }
-  for (i = 0; i < pkgs->count; i++)
-    map[pkgs->elements[i]] = 16;
-
-  for (i = 0, did = 0; did < pkgs->count; i++, did++)
-    {
-      if (i == pkgs->count)
-       i = 0;
-      p = pkgs->elements[i];
-      if ((map[p] & 16) == 0)
-       continue;
-      if ((map[p] & 2) != 0)
-       {
-         map[p] = 2;
-         continue;
-       }
-      s = pool->solvables + p;
-      m = 1;
-      if (s->requires)
-       {
-         reqp = s->repo->idarraydata + s->requires;
-         while ((req = *reqp++) != 0)
-           {
-             if (req == SOLVABLE_PREREQMARKER)
-               continue;
-             r = providedbyinstalled(pool, map, req, 0, 0);
-             if (!r)
-               {
-                 /* decided and miss */
-                 map[p] = 2;
-                 did = 0;
-                 break;
-               }
-             if (r == 16)
-               break;  /* undecided */
-             m |= r;   /* 1 | 9 | 17 */
-           }
-         if (req)
-           continue;
-         if ((m & 9) == 9)
-           m = 9;
-       }
-      if (s->conflicts)
-       {
-         int ispatch = 0;      /* see solver.c patch handling */
-
-         if (!strncmp("patch:", pool_id2str(pool, s->name), 6))
-           ispatch = 1;
-         conp = s->repo->idarraydata + s->conflicts;
-         while ((con = *conp++) != 0)
-           {
-             if ((providedbyinstalled(pool, map, con, ispatch, multiversionmap) & 1) != 0)
-               {
-                 map[p] = 2;
-                 did = 0;
-                 break;
-               }
-             if ((m == 1 || m == 17) && ISRELDEP(con))
-               {
-                 con = dep2name(pool, con);
-                 if ((providedbyinstalled(pool, map, con, ispatch, multiversionmap) & 1) != 0)
-                   m = 9;
-               }
-           }
-         if (con)
-           continue;   /* found a conflict */
-       }
-#if 0
-      if (s->repo && s->repo != oldinstalled)
-       {
-         Id p2, obs, *obsp, *pp;
-         Solvable *s2;
-         if (s->obsoletes)
-           {
-             obsp = s->repo->idarraydata + s->obsoletes;
-             while ((obs = *obsp++) != 0)
-               {
-                 if ((providedbyinstalled(pool, map, obs, 0, 0) & 1) != 0)
-                   {
-                     map[p] = 2;
-                     break;
-                   }
-               }
-             if (obs)
-               continue;
-           }
-         FOR_PROVIDES(p2, pp, s->name)
-           {
-             s2 = pool->solvables + p2;
-             if (s2->name == s->name && (map[p2] & 1) != 0)
-               {
-                 map[p] = 2;
-                 break;
-               }
-           }
-         if (p2)
-           continue;
-       }
-#endif
-      if (m != map[p])
-       {
-         map[p] = m;
-         did = 0;
-       }
-    }
-  queue_free(res);
-  queue_init_clone(res, pkgs);
-  for (i = 0; i < pkgs->count; i++)
-    {
-      m = map[pkgs->elements[i]];
-      if ((m & 9) == 9)
-       r = 1;
-      else if (m & 1)
-       r = -1;
-      else
-       r = 0;
-      res->elements[i] = r;
-    }
-  free(map);
-}
-
-void
-pool_trivial_installable(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res)
-{
-  pool_trivial_installable_multiversionmap(pool, installedmap, pkgs, res, 0);
-}
-
 const char *
 pool_lookup_str(Pool *pool, Id entry, Id keyname)
 {
@@ -2422,24 +1866,66 @@ pool_lookup_deltalocation(Pool *pool, Id entry, unsigned int *medianrp)
   return loc;
 }
 
+void
+pool_set_whatprovides(Pool *pool, Id id, Id providers)
+{
+  int d, nrels = pool->nrels;
+  Reldep *rd;
+  Map m;
+
+  /* set new entry */
+  if (ISRELDEP(id))
+    {
+      d = GETRELID(id);
+      pool->whatprovides_rel[d] = providers;
+      d++;
+    }
+  else
+    {
+      pool->whatprovides[id] = providers;
+      if (id < pool->whatprovidesauxoff)
+       pool->whatprovidesaux[id] = 0;  /* sorry */
+      d = 1;
+    }
+  if (!pool->whatprovides_rel)
+    return;
+  /* clear cache of all rels that use it */
+  map_init(&m, 0);
+  for (rd = pool->rels + d; d < nrels; d++, rd++)
+    {
+      if (rd->name == id || rd->evr == id ||
+         (m.size && ISRELDEP(rd->name) && MAPTST(&m, GETRELID(rd->name))) || 
+         (m.size && ISRELDEP(rd->evr)  && MAPTST(&m, GETRELID(rd->evr))))
+       {
+         pool->whatprovides_rel[d] = 0;        /* clear cache */
+         if (!m.size)
+           map_init(&m, nrels);
+         MAPSET(&m, d);
+       }
+    }
+  map_free(&m);
+}
+
 static void
 add_new_provider(Pool *pool, Id id, Id p)
 {
   Queue q;
   Id *pp;
 
+  /* find whatprovides entry */
   while (ISRELDEP(id))
     {
       Reldep *rd = GETRELDEP(pool, id);
       id = rd->name;
     }
 
+  /* add new provider to existing list keeping it sorted */
   queue_init(&q);
   for (pp = pool->whatprovidesdata + pool->whatprovides[id]; *pp; pp++)
     {
       if (*pp == p)
        {
-         queue_free(&q);
+         queue_free(&q);       /* already have it */
          return;
        }
       if (*pp > p)
@@ -2451,7 +1937,7 @@ add_new_provider(Pool *pool, Id id, Id p)
     }
   if (p)
     queue_push(&q, p);
-  pool->whatprovides[id] = pool_queuetowhatprovides(pool, &q);
+  pool_set_whatprovides(pool, id, pool_queuetowhatprovides(pool, &q));
   queue_free(&q);
 }
 
@@ -2478,9 +1964,7 @@ pool_add_fileconflicts_deps(Pool *pool, Queue *conflicts)
        continue;
       s->provides = repo_addid_dep(s->repo, s->provides, id, SOLVABLE_FILEMARKER);
       if (pool->whatprovides)
-       add_new_provider(pool, fn, p);
-      if (pool->whatprovides_rel)
-       pool->whatprovides_rel[GETRELID(id)] = 0;       /* clear cache */
+       add_new_provider(pool, id, p);
       s = pool->solvables + q;
       if (!s->repo)
        continue;