- add SOLVER_NOAUTOSET to disable automatic SET deduction
[platform/upstream/libsolv.git] / src / pool.c
index 1761d42..cd649d2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, Novell Inc.
+ * Copyright (c) 2007-2009, Novell Inc.
  *
  * This program is licensed under the BSD license, read LICENSE.BSD
  * for further information
@@ -61,6 +61,9 @@ pool_create(void)
   queue_init(&pool->vendormap);
 
   pool->debugmask = SAT_DEBUG_RESULT;  /* FIXME */
+#ifdef FEDORA
+  pool->obsoleteusescolors = 1;
+#endif
   return pool;
 }
 
@@ -88,6 +91,14 @@ pool_free(Pool *pool)
   sat_free(pool);
 }
 
+#ifdef MULTI_SEMANTICS
+void
+pool_setdisttype(Pool *pool, int disttype)
+{
+  pool->disttype = disttype;
+}
+#endif
+
 Id
 pool_add_solvable(Pool *pool)
 {
@@ -123,13 +134,20 @@ pool_free_solvable_block(Pool *pool, Id start, int count, int reuseids)
 }
 
 
-static Pool *pool_shrink_whatprovides_sortcmp_data;
+void
+pool_set_installed(Pool *pool, Repo *installed)
+{
+  if (pool->installed == installed)
+    return;
+  pool->installed = installed;
+  pool_freewhatprovides(pool);
+}
 
 static int
-pool_shrink_whatprovides_sortcmp(const void *ap, const void *bp)
+pool_shrink_whatprovides_sortcmp(const void *ap, const void *bp, void *dp)
 {
   int r;
-  Pool *pool = pool_shrink_whatprovides_sortcmp_data;
+  Pool *pool = dp;
   Id oa, ob, *da, *db;
   oa = pool->whatprovides[*(Id *)ap];
   ob = pool->whatprovides[*(Id *)bp];
@@ -169,8 +187,7 @@ pool_shrink_whatprovides(Pool *pool)
   sorted = sat_malloc2(pool->ss.nstrings, sizeof(Id));
   for (id = 0; id < pool->ss.nstrings; id++)
     sorted[id] = id;
-  pool_shrink_whatprovides_sortcmp_data = pool;
-  qsort(sorted + 1, pool->ss.nstrings - 1, sizeof(Id), pool_shrink_whatprovides_sortcmp);
+  sat_sort(sorted + 1, pool->ss.nstrings - 1, sizeof(Id), pool_shrink_whatprovides_sortcmp, pool);
   last = 0;
   lastid = 0;
   for (i = 1; i < pool->ss.nstrings; i++)
@@ -251,7 +268,10 @@ pool_createwhatprovides(Pool *pool)
   Offset *idp, n;
   Offset *whatprovides;
   Id *whatprovidesdata, *d;
+  Repo *installed = pool->installed;
+  unsigned int now;
 
+  now = sat_timems(0);
   POOL_DEBUG(SAT_DEBUG_STATS, "number of solvables: %d\n", pool->nsolvables);
   POOL_DEBUG(SAT_DEBUG_STATS, "number of ids: %d + %d\n", pool->ss.nstrings, pool->nrels);
 
@@ -262,16 +282,18 @@ pool_createwhatprovides(Pool *pool)
   pool->whatprovides_rel = sat_calloc_block(pool->nrels, sizeof(Offset), WHATPROVIDES_BLOCK);
 
   /* count providers for each name */
-  for (i = 1; i < pool->nsolvables; i++)
+  for (i = pool->nsolvables - 1; i > 0; i--)
     {
       Id *pp;
       s = pool->solvables + i;
-      if (!s->provides)
+      if (!s->provides || !s->repo || s->repo->disabled)
        continue;
-      if (!pool_installable(pool, s))
+      /* we always need the installed solvable in the whatprovides data,
+         otherwise obsoletes/conflicts on them won't work */
+      if (s->repo != installed && !pool_installable(pool, s))
        continue;
       pp = s->repo->idarraydata + s->provides;
-      while ((id = *pp++) != ID_NULL)
+      while ((id = *pp++) != 0)
        {
          while (ISRELDEP(id))
            {
@@ -283,16 +305,15 @@ pool_createwhatprovides(Pool *pool)
     }
 
   off = 2;     /* first entry is undef, second is empty list */
-  idp = whatprovides;
   np = 0;                             /* number of names provided */
-  for (i = 0; i < num; i++, idp++)
+  for (i = 0, idp = whatprovides; i < num; i++, idp++)
     {
       n = *idp;
       if (!n)                         /* no providers */
        continue;
-      *idp = off;                     /* move from counts to offsets into whatprovidesdata */
-      off += n + 1;                   /* make space for all providers + terminating ID_NULL */
-      np++;                           /* inc # of provider 'slots' */
+      off += n;                               /* make space for all providers */
+      *idp = off++;                   /* now idp points to terminating zero */
+      np++;                           /* inc # of provider 'slots' for stats */
     }
 
   POOL_DEBUG(SAT_DEBUG_STATS, "provide ids: %d\n", np);
@@ -308,13 +329,13 @@ pool_createwhatprovides(Pool *pool)
   whatprovidesdata = sat_calloc(off + extra, sizeof(Id));
 
   /* now fill data for all provides */
-  for (i = 1; i < pool->nsolvables; i++)
+  for (i = pool->nsolvables - 1; i > 0; i--)
     {
       Id *pp;
       s = pool->solvables + i;
-      if (!s->provides)
+      if (!s->provides || !s->repo || s->repo->disabled)
        continue;
-      if (!pool_installable(pool, s))
+      if (s->repo != installed && !pool_installable(pool, s))
        continue;
 
       /* for all provides of this solvable */
@@ -327,26 +348,25 @@ pool_createwhatprovides(Pool *pool)
              id = rd->name;
            }
          d = whatprovidesdata + whatprovides[id];   /* offset into whatprovidesdata */
-         if (*d)
+         if (*d != i)          /* don't add same solvable twice */
            {
-             d++;
-             while (*d)               /* find free slot */
-               d++;
-             if (d[-1] == i)          /* solvable already tacked at end ? */
-               continue;              /* Y: skip, on to next provides */
+             d[-1] = i;
+             whatprovides[id]--;
            }
-         *d = i;                      /* put solvable Id into data */
        }
     }
   pool->whatprovidesdata = whatprovidesdata;
   pool->whatprovidesdataoff = off;
   pool->whatprovidesdataleft = extra;
   pool_shrink_whatprovides(pool);
+  POOL_DEBUG(SAT_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)));
+  POOL_DEBUG(SAT_DEBUG_STATS, "createwhatprovides took %d ms\n", sat_timems(now));
 }
 
 /*
  * free all of our whatprovides data
- * be careful, everything internalized with pool_queuetowhatprovides is gone, too
+ * be careful, everything internalized with pool_queuetowhatprovides is
+ * gone, too
  */
 void
 pool_freewhatprovides(Pool *pool)
@@ -402,6 +422,14 @@ pool_queuetowhatprovides(Pool *pool, Queue *q)
 
 /*************************************************************************/
 
+#if defined(MULTI_SEMANTICS)
+# define EVRCMP_DEPCMP (pool->disttype == DISTTYPE_DEB ? EVRCMP_COMPARE : EVRCMP_MATCH_RELEASE)
+#elif defined(DEBIAN_SEMANTICS)
+# define EVRCMP_DEPCMP EVRCMP_COMPARE
+#else
+# define EVRCMP_DEPCMP EVRCMP_MATCH_RELEASE
+#endif
+
 /* check if a package's nevr matches a dependency */
 
 int
@@ -443,11 +471,64 @@ pool_match_nevr_rel(Pool *pool, Solvable *s, Id d)
     return 1;
   if (flags != 2 && flags != 5)
     flags ^= 5;
-  if ((flags & (1 << (1 + evrcmp(pool, s->evr, evr, EVRCMP_MATCH_RELEASE)))) != 0)
+  if ((flags & (1 << (1 + evrcmp(pool, s->evr, evr, EVRCMP_DEPCMP)))) != 0)
     return 1;
   return 0;
 }
 
+/* match (flags, evr) against provider (pflags, pevr) */
+static inline int
+pool_match_flags_evr(Pool *pool, int pflags, Id pevr, int flags, int evr)
+{
+  if (!pflags || !flags || pflags >= 8 || flags >= 8)
+    return 0;
+  if (flags == 7 || pflags == 7)
+    return 1;          /* rel provides every version */
+  if ((pflags & flags & 5) != 0)
+    return 1;          /* both rels show in the same direction */
+  if (pevr == evr)
+    {
+      if ((pflags & flags & 2) != 0)
+       return 1;       /* both have '=', match */
+    }
+  else
+    {
+      int f = flags == 5 ? 5 : flags == 2 ? pflags : (flags ^ 5) & (pflags | 5);
+      if ((f & (1 << (1 + evrcmp(pool, pevr, evr, EVRCMP_DEPCMP)))) != 0)
+       return 1;
+    }
+  return 0;
+}
+
+/* match two dependencies (d1 = provider) */
+
+int
+pool_match_dep(Pool *pool, Id d1, Id d2)
+{
+  Reldep *rd1, *rd2;
+
+  if (d1 == d2)
+    return 1;
+  if (!ISRELDEP(d1))
+    {
+      if (!ISRELDEP(d2))
+       return 0;
+      rd2 = GETRELDEP(pool, d2);
+      return pool_match_dep(pool, d1, rd2->name);
+    }
+  rd1 = GETRELDEP(pool, d1);
+  if (!ISRELDEP(d2))
+    {
+      return pool_match_dep(pool, rd1->name, d2);
+    }
+  rd2 = GETRELDEP(pool, d2);
+  /* first match name */
+  if (!pool_match_dep(pool, rd1->name, rd2->name))
+    return 0;
+  /* name matches, check flags and evr */
+  return pool_match_flags_evr(pool, rd1->flags, rd1->evr, rd2->flags, rd2->evr);
+}
+
 /*
  * addrelproviders
  * 
@@ -456,7 +537,7 @@ pool_match_nevr_rel(Pool *pool, Solvable *s, Id d)
  * 
  */
 
-Id *
+Id
 pool_addrelproviders(Pool *pool, Id d)
 {
   Reldep *rd = GETRELDEP(pool, d);
@@ -467,7 +548,7 @@ pool_addrelproviders(Pool *pool, Id d)
   Id evr = rd->evr;
   int flags = rd->flags;
   Id pid, *pidp;
-  Id p, *pp, *pp2, *pp3;
+  Id p, wp, *pp, *pp2, *pp3;
 
   d = GETRELID(d);
   queue_init_buffer(&plist, buf, sizeof(buf)/sizeof(*buf));
@@ -475,8 +556,8 @@ pool_addrelproviders(Pool *pool, Id d)
     {
     case REL_AND:
     case REL_WITH:
-      pp = pool_whatprovides(pool, name);
-      pp2 = pool_whatprovides(pool, evr);
+      pp = pool_whatprovides_ptr(pool, name);
+      pp2 = pool_whatprovides_ptr(pool, evr);
       while ((p = *pp++) != 0)
        {
          for (pp3 = pp2; *pp3;)
@@ -488,14 +569,20 @@ pool_addrelproviders(Pool *pool, Id d)
        }
       break;
     case REL_OR:
-      pp = pool_whatprovides(pool, name);
+      pp = pool_whatprovides_ptr(pool, name);
       while ((p = *pp++) != 0)
        queue_push(&plist, p);
-      pp = pool_whatprovides(pool, evr);
+      pp = pool_whatprovides_ptr(pool, evr);
       while ((p = *pp++) != 0)
        queue_pushunique(&plist, p);
       break;
     case REL_NAMESPACE:
+      if (name == NAMESPACE_OTHERPROVIDERS)
+       {
+         wp = pool_whatprovides(pool, evr);
+         pool->whatprovides_rel[d] = wp;
+         return wp;
+       }
       if (pool->nscallback)
        {
          /* ask callback which packages provide the dependency
@@ -508,7 +595,7 @@ pool_addrelproviders(Pool *pool, Id d)
            {
              queue_free(&plist);
              pool->whatprovides_rel[d] = p;
-             return pool->whatprovidesdata + p;
+             return p;
            }
          if (p == 1)
            queue_push(&plist, SYSTEMSOLVABLE);
@@ -531,17 +618,38 @@ pool_addrelproviders(Pool *pool, Id d)
            }
          break;
        }
-      pp = pp2 = pool_whatprovides(pool, name);
+      wp = pool_whatprovides(pool, name);
+      pp = pool->whatprovidesdata + wp;
       while ((p = *pp++) != 0)
        {
          Solvable *s = pool->solvables + p;
          if (s->arch == evr)
            queue_push(&plist, p);
          else
-           pp2 = 0;
+           wp = 0;
+       }
+      if (wp)
+       {
+         /* all solvables match, no need to create a new list */
+         pool->whatprovides_rel[d] = wp;
+         return wp;
+       }
+      break;
+    case REL_FILECONFLICT:
+      pp = pool_whatprovides_ptr(pool, name);
+      while ((p = *pp++) != 0)
+       {
+         Id origd = MAKERELDEP(d);
+         Solvable *s = pool->solvables + p;
+         if (!s->provides)
+           continue;
+         pidp = s->repo->idarraydata + s->provides;
+         while ((pid = *pidp++) != 0)
+           if (pid == origd)
+             break;
+         if (pid)
+           queue_push(&plist, p);
        }
-      if (pp2)
-       return pp2;
       break;
     default:
       break;
@@ -553,7 +661,7 @@ pool_addrelproviders(Pool *pool, Id d)
 #endif
   if (flags && flags < 8)
     {
-      pp = pool_whatprovides(pool, name);
+      pp = pool_whatprovides_ptr(pool, name);
       while (ISRELDEP(name))
        {
           rd = GETRELDEP(pool, name);
@@ -576,12 +684,14 @@ pool_addrelproviders(Pool *pool, Id d)
          pidp = s->repo->idarraydata + s->provides;
          while ((pid = *pidp++) != 0)
            {
-             int pflags;
-             Id pevr;
-
              if (pid == name)
                {
-#ifdef DEBIAN_SEMANTICS
+#if defined(MULTI_SEMANTICS)
+                 if (pool->disttype == DISTTYPE_DEB)
+                   continue;
+                 else
+                   break;
+#elif defined(DEBIAN_SEMANTICS)
                  continue;             /* unversioned provides can
                                         * never match versioned deps */
 #else
@@ -593,29 +703,12 @@ pool_addrelproviders(Pool *pool, Id d)
              prd = GETRELDEP(pool, pid);
              if (prd->name != name)
                continue;               /* wrong provides name */
-             /* right package, both deps are rels */
-             pflags = prd->flags;
-             if (!pflags)
-               continue;
-             if (flags == 7 || pflags == 7)
-               break; /* included */
-             if ((pflags & flags & 5) != 0)
-               break; /* same direction, match */
-             pevr = prd->evr;
-             if (pevr == evr)
-               {
-                 if ((pflags & flags & 2) != 0)
-                   break; /* both have =, match */
-               }
-             else
-               {
-                 int f = flags == 5 ? 5 : flags == 2 ? pflags : (flags ^ 5) & (pflags | 5);
-                 if ((f & (1 << (1 + evrcmp(pool, pevr, evr, EVRCMP_MATCH_RELEASE)))) != 0)
-                   break;
-               }
+             /* right package, both deps are rels. check flags/evr */
+             if (pool_match_flags_evr(pool, prd->flags, prd->evr, flags, evr))
+               break;  /* matches */
            }
          if (!pid)
-           continue;   /* no rel match */
+           continue;   /* none of the providers matched */
          queue_push(&plist, p);
        }
       /* make our system solvable provide all unknown rpmlib() stuff */
@@ -629,7 +722,7 @@ pool_addrelproviders(Pool *pool, Id d)
   pool->whatprovides_rel[d] = pool_queuetowhatprovides(pool, &plist);
   queue_free(&plist);
 
-  return pool->whatprovidesdata + pool->whatprovides_rel[d];
+  return pool->whatprovides_rel[d];
 }
 
 /*************************************************************************/
@@ -648,7 +741,7 @@ pool_debug(Pool *pool, int type, const char *format, ...)
   va_start(args, format);
   if (!pool->debugcallback)
     {
-      if ((type & (SAT_FATAL|SAT_ERROR)) == 0)
+      if ((type & (SAT_FATAL|SAT_ERROR)) == 0 && !(pool->debugmask & SAT_DEBUG_TO_STDERR))
         vprintf(format, args);
       else
         vfprintf(stderr, format, args);
@@ -663,7 +756,7 @@ pool_setdebuglevel(Pool *pool, int level)
 {
   int mask = SAT_DEBUG_RESULT;
   if (level > 0)
-    mask |= SAT_DEBUG_STATS|SAT_DEBUG_ANALYZE|SAT_DEBUG_UNSOLVABLE;
+    mask |= SAT_DEBUG_STATS|SAT_DEBUG_ANALYZE|SAT_DEBUG_UNSOLVABLE|SAT_DEBUG_SOLVER|SAT_DEBUG_TRANSACTION;
   if (level > 1)
     mask |= SAT_DEBUG_JOB|SAT_DEBUG_SOLUTIONS|SAT_DEBUG_POLICY;
   if (level > 2)
@@ -672,6 +765,7 @@ pool_setdebuglevel(Pool *pool, int level)
     mask |= SAT_DEBUG_RULE_CREATION;
   if (level > 4)
     mask |= SAT_DEBUG_SCHUBI;
+  mask |= pool->debugmask & SAT_DEBUG_TO_STDERR;       /* keep bit */
   pool->debugmask = mask;
 }
 
@@ -724,6 +818,11 @@ pool_addfileprovides_dep(Pool *pool, Id *ida, struct searchfiles *sf, struct sea
                }
              dep = rd->evr;
            }
+         else if (rd->flags == REL_FILECONFLICT)
+           {
+             dep = 0;
+             break;
+           }
          else
            {
              Id ids[2];
@@ -761,8 +860,10 @@ struct addfileprovides_cbdata {
   char **dirs;
   char **names;
 
-  Repodata *olddata;
   Id *dids;
+
+  Map providedids;
+
   Map useddirs;
 };
 
@@ -772,20 +873,24 @@ addfileprovides_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyV
   struct addfileprovides_cbdata *cbd = cbdata;
   int i;
 
-  if (data != cbd->olddata)
+  if (!cbd->useddirs.size)
     {
-      map_free(&cbd->useddirs);
-      map_init(&cbd->useddirs, data->dirpool.ndirs);
+      map_init(&cbd->useddirs, data->dirpool.ndirs + 1);
       for (i = 0; i < cbd->nfiles; i++)
        {
-         Id did = repodata_str2dir(data, cbd->dirs[i], 0);
-          cbd->dids[i] = did;
+         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);
        }
-      cbd->olddata = data;
     }
-  if (!MAPTST(&cbd->useddirs, value->id))
+  if (value->id >= data->dirpool.ndirs || !MAPTST(&cbd->useddirs, value->id))
     return 0;
   for (i = 0; i < cbd->nfiles; i++)
     {
@@ -800,76 +905,128 @@ addfileprovides_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyV
   return 0;
 }
 
-
 static void
 pool_addfileprovides_search(Pool *pool, struct addfileprovides_cbdata *cbd, struct searchfiles *sf, Repo *repoonly)
 {
-  Id p, start, end, *idp;
-  Solvable *s;
-  Repodata *data = 0, *nextdata;
-  Repo *oldrepo = 0;
-  int dataincludes = 0;
-  int i;
-  Map providedids;
+  Id p;
+  Repodata *data;
+  Repo *repo;
+  Queue fileprovidesq;
+  int i, j, repoid, repodataid;
+  int provstart, provend;
+  Map donemap;
+  int ndone, incomplete;
+
+  if (!pool->nrepos)
+    return;
 
   cbd->nfiles = sf->nfiles;
   cbd->ids = sf->ids;
   cbd->dirs = sf->dirs;
   cbd->names = sf->names;
-  cbd->olddata = 0;
   cbd->dids = sat_realloc2(cbd->dids, sf->nfiles, sizeof(Id));
-  if (repoonly)
-    {
-      start = repoonly->start;
-      end = repoonly->end;
-    }
-  else
+  map_init(&cbd->providedids, pool->ss.nstrings);
+
+  repoid = 0;
+  repo = repoonly ? repoonly : pool->repos[0];
+  map_init(&donemap, pool->nsolvables);
+  queue_init(&fileprovidesq);
+  provstart = provend = 0;
+  for (;;)
     {
-      start = 2;       /* skip system solvable */
-      end = pool->nsolvables;
-    }
-  for (p = start, s = pool->solvables + p; p < end; p++, s++)
-    {
-      if (!s->repo || (repoonly && s->repo != repoonly))
-       continue;
-      if (s->repo != oldrepo || (data && p >= data->end))
+      if (repo->disabled)
        {
-         data = 0;
-         oldrepo = 0;
+         if (repoonly || ++repoid == pool->nrepos)
+           break;
+         repo = pool->repos[repoid];
+         continue;
        }
-      if (oldrepo == 0)
+      ndone = 0;
+      for (data = repo->repodata, repodataid = 0; repodataid < repo->nrepodata; repodataid++, data++)
        {
-         nextdata = 0;
-         for (i = 0, data = s->repo->repodata; i < s->repo->nrepodata; i++, data++)
+         if (ndone >= repo->nsolvables)
+           break;
+
+         if (repodata_lookup_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, &fileprovidesq))
            {
-             if (!data->addedfileprovides || p >= data->end)
-               continue;
-             if (!nextdata || nextdata->start > data->start)
-               nextdata = data;
-             if (p >= data->start)
-               break;
+             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 (i == s->repo->nrepodata)
-           data = nextdata;
-         if (data)
+
+         if (!repodata_has_keyname(data, SOLVABLE_FILELIST))
+           continue;
+
+         if (data->start < provstart || data->end > provend)
            {
-             map_init(&providedids, pool->ss.nstrings);
-             for (idp = data->addedfileprovides; *idp; idp++)
-               MAPSET(&providedids, *idp);
-             for (i = 0; i < cbd->nfiles; i++)
-               if (!MAPTST(&providedids, cbd->ids[i]))
+             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, id2str(pool, cbd->ids[i])))
+                     printf("need complete filelist because of %s\n", id2str(pool, cbd->ids[i]));
+#endif
+                 for (i = 0; i < cbd->nfiles; i++)
+                   if (!MAPTST(&cbd->providedids, cbd->ids[i]) && !repodata_filelistfilter_matches(data, 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)
                  {
-                   break;
+                   MAPSET(&donemap, p);
+                   ndone++;
                  }
-             map_free(&providedids);
-             dataincludes = i == cbd->nfiles;
-           }
-         oldrepo = s->repo;
+             }
+         map_free(&cbd->useddirs);
        }
-      if (data && p >= data->start && dataincludes)
-       continue;
-      repo_search(s->repo, p, SOLVABLE_FILELIST, 0, 0, addfileprovides_cb, cbd);
+
+      if (repoonly || ++repoid == pool->nrepos)
+       break;
+      repo = pool->repos[repoid];
     }
+  map_free(&donemap);
+  queue_free(&fileprovidesq);
+  map_free(&cbd->providedids);
 }
 
 void
@@ -880,7 +1037,9 @@ pool_addfileprovides_ids(Pool *pool, Repo *installed, Id **idp)
   struct searchfiles sf, isf, *isfp;
   struct addfileprovides_cbdata cbd;
   int i;
+  unsigned int now;
 
+  now = sat_timems(0);
   memset(&sf, 0, sizeof(sf));
   map_init(&sf.seen, pool->ss.nstrings + pool->nrels);
   memset(&isf, 0, sizeof(isf));
@@ -909,10 +1068,8 @@ pool_addfileprovides_ids(Pool *pool, Repo *installed, Id **idp)
     }
   map_free(&sf.seen);
   map_free(&isf.seen);
-  POOL_DEBUG(SAT_DEBUG_STATS, "found %d file dependencies\n", sf.nfiles);
-  POOL_DEBUG(SAT_DEBUG_STATS, "found %d installed file dependencies\n", isf.nfiles);
+  POOL_DEBUG(SAT_DEBUG_STATS, "found %d file dependencies, %d installed file dependencies\n", sf.nfiles, isf.nfiles);
   cbd.dids = 0;
-  map_init(&cbd.useddirs, 1);
   if (idp)
     *idp = 0;
   if (sf.nfiles)
@@ -955,15 +1112,15 @@ pool_addfileprovides_ids(Pool *pool, Repo *installed, Id **idp)
       sat_free(isf.dirs);
       sat_free(isf.names);
     }
-  map_free(&cbd.useddirs);
   sat_free(cbd.dids);
   pool_freewhatprovides(pool); /* as we have added provides */
+  POOL_DEBUG(SAT_DEBUG_STATS, "addfileprovides took %d ms\n", sat_timems(now));
 }
 
 void
-pool_addfileprovides(Pool *pool, Repo *installed)
+pool_addfileprovides(Pool *pool)
 {
-  pool_addfileprovides_ids(pool, installed, 0);
+  pool_addfileprovides_ids(pool, pool->installed, 0);
 }
 
 void
@@ -981,6 +1138,12 @@ pool_search(Pool *pool, Id p, Id key, const char *match, int flags, int (*callba
       repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
 }
 
+void
+pool_clear_pos(Pool *pool)
+{
+  memset(&pool->pos, 0, sizeof(pool->pos));
+}
+
 
 void
 pool_set_languages(Pool *pool, const char **languages, int nlanguages)
@@ -1040,6 +1203,35 @@ pool_alloctmpspace(Pool *pool, int len)
   return pool->tmpspacebuf[n];
 }
 
+char *
+pool_tmpjoin(Pool *pool, const char *str1, const char *str2, const char *str3)
+{
+  int l1, l2, l3;
+  char *s, *str;
+  l1 = str1 ? strlen(str1) : 0;
+  l2 = str2 ? strlen(str2) : 0;
+  l3 = str3 ? strlen(str3) : 0;
+  s = str = pool_alloctmpspace(pool, l1 + l2 + l3 + 1);
+  if (l1)
+    {
+      strcpy(s, str1);
+      s += l1;
+    }
+  if (l2)
+    {
+      strcpy(s, str2);
+      s += l2;
+    }
+  if (l3)
+    {
+      strcpy(s, str3);
+      s += l3;
+    }
+  *s = 0;
+  return str;
+}
+
+
 /*******************************************************************/
 
 struct mptree {
@@ -1154,7 +1346,7 @@ propagate_mountpoints(struct mptree *mptree, int pos, Id mountpoint)
 #define MPTREE_BLOCK 15
 
 void
-pool_calc_duchanges(Pool *pool, Repo *oldinstalled, Map *installedmap, DUChanges *mps, int nmps)
+pool_calc_duchanges(Pool *pool, Map *installedmap, DUChanges *mps, int nmps)
 {
   char *p;
   const char *path, *compstr;
@@ -1166,6 +1358,7 @@ pool_calc_duchanges(Pool *pool, Repo *oldinstalled, Map *installedmap, DUChanges
   Solvable *s;
   Id sp;
   Map ignoredu;
+  Repo *oldinstalled = pool->installed;
 
   memset(&ignoredu, 0, sizeof(ignoredu));
   cbd.mps = mps;
@@ -1254,7 +1447,7 @@ pool_calc_duchanges(Pool *pool, Repo *oldinstalled, Map *installedmap, DUChanges
       repo_search(s->repo, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
       if (!cbd.hasdu && oldinstalled)
        {
-         Id op, *opp;
+         Id op, opp;
          /* no du data available, ignore data of all installed solvables we obsolete */
          if (!ignoredu.map)
            map_init(&ignoredu, oldinstalled->end - oldinstalled->start);
@@ -1292,11 +1485,12 @@ pool_calc_duchanges(Pool *pool, Repo *oldinstalled, Map *installedmap, DUChanges
 }
 
 int
-pool_calc_installsizechange(Pool *pool, Repo *oldinstalled, Map *installedmap)
+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++)
     {
@@ -1304,7 +1498,7 @@ pool_calc_installsizechange(Pool *pool, Repo *oldinstalled, Map *installedmap)
        continue;
       if (!MAPTST(installedmap, sp))
        continue;
-      change += repo_lookup_num(s, SOLVABLE_INSTALLSIZE);
+      change += solvable_lookup_num(s, SOLVABLE_INSTALLSIZE, 0);
     }
   if (oldinstalled)
     {
@@ -1312,7 +1506,7 @@ pool_calc_installsizechange(Pool *pool, Repo *oldinstalled, Map *installedmap)
        {
          if (MAPTST(installedmap, sp))
            continue;
-         change -= repo_lookup_num(s, SOLVABLE_INSTALLSIZE);
+         change -= solvable_lookup_num(s, SOLVABLE_INSTALLSIZE, 0);
        }
     }
   return change;
@@ -1335,14 +1529,38 @@ static inline Id dep2name(Pool *pool, Id dep)
   return dep;
 }
 
-static inline int providedbyinstalled(Pool *pool, unsigned char *map, Id dep)
+static int providedbyinstalled_multiversion(Pool *pool, unsigned char *map, Id n, Id con) 
 {
-  Id p, *pp;
+  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 *noobsoletesmap)
+{
+  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 && noobsoletesmap && noobsoletesmap->size && MAPTST(noobsoletesmap, p) && ISRELDEP(dep))
+       if (providedbyinstalled_multiversion(pool, map, p, dep))
+         continue;
       if ((map[p] & 9) == 9)
        return 9;
       r |= map[p] & 17;
@@ -1362,7 +1580,7 @@ static inline int providedbyinstalled(Pool *pool, unsigned char *map, Id dep)
  */
 
 void
-pool_trivial_installable(Pool *pool, Repo *oldinstalled, Map *installedmap, Queue *pkgs, Queue *res)
+pool_trivial_installable_noobsoletesmap(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res, Map *noobsoletesmap)
 {
   int i, r, m, did;
   Id p, *dp, con, *conp, req, *reqp;
@@ -1381,7 +1599,7 @@ pool_trivial_installable(Pool *pool, Repo *oldinstalled, Map *installedmap, Queu
       conp = s->repo->idarraydata + s->conflicts;
       while ((con = *conp++) != 0)
        {
-         dp = pool_whatprovides(pool, con);
+         dp = pool_whatprovides_ptr(pool, con);
          for (; *dp; dp++)
            map[p] |= 2;        /* XXX: self conflict ? */
        }
@@ -1410,7 +1628,7 @@ pool_trivial_installable(Pool *pool, Repo *oldinstalled, Map *installedmap, Queu
            {
              if (req == SOLVABLE_PREREQMARKER)
                continue;
-             r = providedbyinstalled(pool, map, req);
+             r = providedbyinstalled(pool, map, req, 0, 0);
              if (!r)
                {
                  /* decided and miss */
@@ -1426,10 +1644,14 @@ pool_trivial_installable(Pool *pool, Repo *oldinstalled, Map *installedmap, Queu
        }
       if (s->conflicts)
        {
+         int ispatch = 0;      /* see solver.c patch handling */
+
+         if (!strncmp("patch:", id2str(pool, s->name), 6))
+           ispatch = 1;
          conp = s->repo->idarraydata + s->conflicts;
          while ((con = *conp++) != 0)
            {
-             if ((providedbyinstalled(pool, map, con) & 1) != 0)
+             if ((providedbyinstalled(pool, map, con, ispatch, noobsoletesmap) & 1) != 0)
                {
                  map[p] = 2;
                  break;
@@ -1437,7 +1659,7 @@ pool_trivial_installable(Pool *pool, Repo *oldinstalled, Map *installedmap, Queu
              if ((m == 1 || m == 17) && ISRELDEP(con))
                {
                  con = dep2name(pool, con);
-                 if ((providedbyinstalled(pool, map, con) & 1) != 0)
+                 if ((providedbyinstalled(pool, map, con, ispatch, noobsoletesmap) & 1) != 0)
                    m = 9;
                }
            }
@@ -1454,7 +1676,7 @@ pool_trivial_installable(Pool *pool, Repo *oldinstalled, Map *installedmap, Queu
              obsp = s->repo->idarraydata + s->obsoletes;
              while ((obs = *obsp++) != 0)
                {
-                 if ((providedbyinstalled(pool, map, obs) & 1) != 0)
+                 if ((providedbyinstalled(pool, map, obs, 0, 0) & 1) != 0)
                    {
                      map[p] = 2;
                      break;
@@ -1478,12 +1700,12 @@ pool_trivial_installable(Pool *pool, Repo *oldinstalled, Map *installedmap, Queu
 #endif
       if (m != map[p])
        {
-          map[p] = m;
+         map[p] = m;
          did = 0;
        }
     }
   queue_free(res);
-  queue_clone(res, pkgs);
+  queue_init_clone(res, pkgs);
   for (i = 0; i < pkgs->count; i++)
     {
       m = map[pkgs->elements[i]];
@@ -1498,4 +1720,114 @@ pool_trivial_installable(Pool *pool, Repo *oldinstalled, Map *installedmap, Queu
   free(map);
 }
 
-// EOF
+void
+pool_trivial_installable(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res)
+{
+  pool_trivial_installable_noobsoletesmap(pool, installedmap, pkgs, res, 0);
+}
+
+const char *
+pool_lookup_str(Pool *pool, Id entry, Id keyname)
+{
+  if (entry == SOLVID_POS && pool->pos.repo)
+    return repodata_lookup_str(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname);
+  if (entry <= 0)
+    return 0;
+  return solvable_lookup_str(pool->solvables + entry, keyname);
+}
+
+Id
+pool_lookup_id(Pool *pool, Id entry, Id keyname)
+{
+  if (entry == SOLVID_POS && pool->pos.repo)
+    {
+      Repodata *data = pool->pos.repo->repodata + pool->pos.repodataid;
+      Id id = repodata_lookup_id(data, SOLVID_POS, keyname);
+      return data->localpool ? repodata_globalize_id(data, id, 1) : id;
+    }
+  if (entry <= 0)
+    return 0;
+  return solvable_lookup_id(pool->solvables + entry, keyname);
+}
+
+unsigned int
+pool_lookup_num(Pool *pool, Id entry, Id keyname, unsigned int notfound)
+{
+  if (entry == SOLVID_POS && pool->pos.repo)
+    {
+      unsigned int value;
+      if (repodata_lookup_num(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname, &value))
+       return value;
+      return notfound;
+    }
+  if (entry <= 0)
+    return notfound;
+  return solvable_lookup_num(pool->solvables + entry, keyname, notfound);
+}
+
+int
+pool_lookup_void(Pool *pool, Id entry, Id keyname)
+{
+  if (entry == SOLVID_POS && pool->pos.repo)
+    return repodata_lookup_void(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname);
+  if (entry <= 0)
+    return 0;
+  return solvable_lookup_void(pool->solvables + entry, keyname);
+}
+
+const unsigned char *
+pool_lookup_bin_checksum(Pool *pool, Id entry, Id keyname, Id *typep)
+{
+  if (entry == SOLVID_POS && pool->pos.repo)
+    return repodata_lookup_bin_checksum(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname, typep);
+  if (entry <= 0)
+    return 0;
+  return solvable_lookup_bin_checksum(pool->solvables + entry, keyname, typep);
+}
+
+const char *
+pool_lookup_checksum(Pool *pool, Id entry, Id keyname, Id *typep)
+{
+  if (entry == SOLVID_POS && pool->pos.repo)
+    {
+      const unsigned char *chk = repodata_lookup_bin_checksum(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname, typep);
+      return chk ? repodata_chk2str(pool->pos.repo->repodata + pool->pos.repodataid, *typep, chk) : 0;
+    }
+  if (entry <= 0)
+    return 0;
+  return solvable_lookup_checksum(pool->solvables + entry, keyname, typep);
+}
+
+void
+pool_add_fileconflicts_deps(Pool *pool, Queue *conflicts)
+{
+  int hadhashes = pool->relhashtbl ? 1 : 0;
+  Solvable *s;
+  Id fn, p, q, md5;
+  Id id;
+  int i;
+
+  if (!conflicts->count)
+    return;
+  pool_freewhatprovides(pool);
+  for (i = 0; i < conflicts->count; i += 5)
+    {
+      fn = conflicts->elements[i];
+      p = conflicts->elements[i + 1];
+      md5 = conflicts->elements[i + 2];
+      q = conflicts->elements[i + 3];
+      id = rel2id(pool, fn, md5, REL_FILECONFLICT, 1);
+      s = pool->solvables + p;
+      if (!s->repo)
+       continue;
+      s->provides = repo_addid_dep(s->repo, s->provides, id, SOLVABLE_FILEMARKER);
+      s = pool->solvables + q;
+      if (!s->repo)
+       continue;
+      s->conflicts = repo_addid_dep(s->repo, s->conflicts, id, 0);
+    }
+  if (!hadhashes)
+    pool_freeidhashes(pool);
+}
+
+/* EOF */