- move create_obsolete_index to policy.c
[platform/upstream/libsolv.git] / src / pool.c
index f35ca8f..e375b91 100644 (file)
@@ -132,13 +132,11 @@ pool_set_installed(Pool *pool, Repo *installed)
   pool_freewhatprovides(pool);
 }
 
-static Pool *pool_shrink_whatprovides_sortcmp_data;
-
 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];
@@ -178,8 +176,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++)
@@ -362,7 +359,8 @@ pool_createwhatprovides(Pool *pool)
 
 /*
  * 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)
@@ -459,8 +457,65 @@ pool_match_nevr_rel(Pool *pool, Solvable *s, Id d)
     return 1;
   if (flags != 2 && flags != 5)
     flags ^= 5;
+#ifdef DEBIAN_SEMANTICS
+  if ((flags & (1 << (1 + evrcmp(pool, s->evr, evr, EVRCMP_COMPARE)))) != 0)
+    return 1;
+#else
   if ((flags & (1 << (1 + evrcmp(pool, s->evr, evr, EVRCMP_MATCH_RELEASE)))) != 0)
     return 1;
+#endif
+  return 0;
+}
+
+/* match two dependencies */
+
+int
+pool_match_dep(Pool *pool, Id d1, Id d2)
+{
+  Reldep *rd1, *rd2;
+  int pflags, flags;
+
+  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);
+  if (!pool_match_dep(pool, rd1->name, rd2->name))
+    return 0;
+  pflags = rd1->flags;
+  flags = rd2->flags;
+  if (!pflags || !flags || pflags >= 8 || flags >= 8)
+    return 0;
+  if (flags == 7 || pflags == 7)
+    return 1;
+  if ((pflags & flags & 5) != 0)
+    return 1;
+  if (rd1->evr == rd2->evr)
+    {
+      if ((pflags & flags & 2) != 0)
+       return 1;
+    }
+  else
+    {
+      int f = flags == 5 ? 5 : flags == 2 ? pflags : (flags ^ 5) & (pflags | 5);
+#ifdef DEBIAN_SEMANTICS
+      if ((f & (1 << (1 + evrcmp(pool, rd1->evr, rd2->evr, EVRCMP_COMPARE)))) != 0)
+       return 1;
+#else
+      if ((f & (1 << (1 + evrcmp(pool, rd1->evr, rd2->evr, EVRCMP_MATCH_RELEASE)))) != 0)
+       return 1;
+#endif
+    }
   return 0;
 }
 
@@ -491,8 +546,8 @@ pool_addrelproviders(Pool *pool, Id d)
     {
     case REL_AND:
     case REL_WITH:
-      pp = pool->whatprovidesdata + pool_whatprovides(pool, name);
-      pp2 = pool->whatprovidesdata + pool_whatprovides(pool, evr);
+      pp = pool_whatprovides_ptr(pool, name);
+      pp2 = pool_whatprovides_ptr(pool, evr);
       while ((p = *pp++) != 0)
        {
          for (pp3 = pp2; *pp3;)
@@ -504,10 +559,10 @@ pool_addrelproviders(Pool *pool, Id d)
        }
       break;
     case REL_OR:
-      pp = pool->whatprovidesdata + pool_whatprovides(pool, name);
+      pp = pool_whatprovides_ptr(pool, name);
       while ((p = *pp++) != 0)
        queue_push(&plist, p);
-      pp = pool->whatprovidesdata + pool_whatprovides(pool, evr);
+      pp = pool_whatprovides_ptr(pool, evr);
       while ((p = *pp++) != 0)
        queue_pushunique(&plist, p);
       break;
@@ -579,7 +634,7 @@ pool_addrelproviders(Pool *pool, Id d)
 #endif
   if (flags && flags < 8)
     {
-      pp = pool->whatprovidesdata + pool_whatprovides(pool, name);
+      pp = pool_whatprovides_ptr(pool, name);
       while (ISRELDEP(name))
        {
           rd = GETRELDEP(pool, name);
@@ -1392,7 +1447,23 @@ static inline Id dep2name(Pool *pool, Id dep)
   return dep;
 }
 
-static inline int providedbyinstalled(Pool *pool, unsigned char *map, Id dep, int ispatch)
+static int providedbyinstalled_multiversion(Pool *pool, unsigned char *map, Id n, Id dep) 
+{
+  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)
+        return 1;
+    }    
+  return 0;
+}
+
+static inline int providedbyinstalled(Pool *pool, unsigned char *map, Id dep, int ispatch, Map *noobsoletesmap)
 {
   Id p, pp;
   int r = 0;
@@ -1402,6 +1473,9 @@ static inline int providedbyinstalled(Pool *pool, unsigned char *map, Id dep, in
         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;
@@ -1421,7 +1495,7 @@ static inline int providedbyinstalled(Pool *pool, unsigned char *map, Id dep, in
  */
 
 void
-pool_trivial_installable(Pool *pool, 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;
@@ -1440,7 +1514,7 @@ pool_trivial_installable(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res)
       conp = s->repo->idarraydata + s->conflicts;
       while ((con = *conp++) != 0)
        {
-         dp = pool->whatprovidesdata + pool_whatprovides(pool, con);
+         dp = pool_whatprovides_ptr(pool, con);
          for (; *dp; dp++)
            map[p] |= 2;        /* XXX: self conflict ? */
        }
@@ -1469,7 +1543,7 @@ pool_trivial_installable(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res)
            {
              if (req == SOLVABLE_PREREQMARKER)
                continue;
-             r = providedbyinstalled(pool, map, req, 0);
+             r = providedbyinstalled(pool, map, req, 0, 0);
              if (!r)
                {
                  /* decided and miss */
@@ -1492,7 +1566,7 @@ pool_trivial_installable(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res)
          conp = s->repo->idarraydata + s->conflicts;
          while ((con = *conp++) != 0)
            {
-             if ((providedbyinstalled(pool, map, con, ispatch) & 1) != 0)
+             if ((providedbyinstalled(pool, map, con, ispatch, noobsoletesmap) & 1) != 0)
                {
                  map[p] = 2;
                  break;
@@ -1500,7 +1574,7 @@ pool_trivial_installable(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res)
              if ((m == 1 || m == 17) && ISRELDEP(con))
                {
                  con = dep2name(pool, con);
-                 if ((providedbyinstalled(pool, map, con, ispatch) & 1) != 0)
+                 if ((providedbyinstalled(pool, map, con, ispatch, noobsoletesmap) & 1) != 0)
                    m = 9;
                }
            }
@@ -1517,7 +1591,7 @@ pool_trivial_installable(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res)
              obsp = s->repo->idarraydata + s->obsoletes;
              while ((obs = *obsp++) != 0)
                {
-                 if ((providedbyinstalled(pool, map, obs, 0) & 1) != 0)
+                 if ((providedbyinstalled(pool, map, obs, 0, 0) & 1) != 0)
                    {
                      map[p] = 2;
                      break;
@@ -1561,4 +1635,10 @@ pool_trivial_installable(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res)
   free(map);
 }
 
+void
+pool_trivial_installable(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res)
+{
+  pool_trivial_installable_noobsoletesmap(pool, installedmap, pkgs, res, 0);
+}
+
 // EOF