]> git.ipfire.org Git - thirdparty/libsolv.git/commitdiff
- add vendor change policy (but fixes no test case, as there is no
authorMichael Schroeder <mls@suse.de>
Tue, 30 Oct 2007 17:55:35 +0000 (17:55 +0000)
committerMichael Schroeder <mls@suse.de>
Tue, 30 Oct 2007 17:55:35 +0000 (17:55 +0000)
  good test case)

src/CMakeLists.txt
src/pool.c
src/pool.h
src/poolvendor.c [new file with mode: 0644]
src/poolvendor.h [new file with mode: 0644]
src/solver.c
src/solver.h

index 65749268f93996e907989d9e9a5d73b9e60845ff..6866a8b06c7a4d523b2115cec515d50e84100ed4 100644 (file)
@@ -1,10 +1,10 @@
 
-SET(libsatsolver_SRCS bitmap.c  poolarch.c  poolid.c  solver.c  repo_solv.c
-evr.c pool.c queue.c   repo.c  util.c)
+SET(libsatsolver_SRCS bitmap.c  poolarch.c  poolvendor.c  poolid.c
+solver.c  repo_solv.c evr.c pool.c queue.c   repo.c  util.c)
 
 ADD_LIBRARY(satsolver STATIC ${libsatsolver_SRCS})
 
-SET(libsatsolver_HEADERS bitmap.h evr.h hash.h poolarch.h pool.h poolid.h pooltypes.h queue.h solvable.h solver.h repo.h repo_solv.h util.h )
+SET(libsatsolver_HEADERS bitmap.h evr.h hash.h poolarch.h poolvendor.h pool.h poolid.h pooltypes.h queue.h solvable.h solver.h repo.h repo_solv.h util.h )
 
 INSTALL(  FILES ${libsatsolver_HEADERS} DESTINATION "${CMAKE_INSTALL_PREFIX}/include/satsolver" )
-INSTALL(TARGETS satsolver LIBRARY DESTINATION ${LIB_INSTALL_DIR} ARCHIVE DESTINATION ${LIB_INSTALL_DIR})
\ No newline at end of file
+INSTALL(TARGETS satsolver LIBRARY DESTINATION ${LIB_INSTALL_DIR} ARCHIVE DESTINATION ${LIB_INSTALL_DIR})
index 9e728947ebfa28d3751c6d335f3bbe476a807a3b..493d8ef69d2569309d932484ed95de440f8cb074 100644 (file)
@@ -96,6 +96,7 @@ pool_create(void)
   // pre-alloc space for a Solvable
   pool->solvables = (Solvable *)xcalloc(2, sizeof(Solvable));
   pool->nsolvables = 2;
+  queue_init(&pool->vendormap);
   s = pool->solvables + SYSTEMSOLVABLE;
   s->name = SYSTEM_SYSTEM;
   s->arch = ARCH_NOARCH;
@@ -127,6 +128,7 @@ pool_free(Pool *pool)
   xfree(pool->stringspace);
   xfree(pool->strings);
   xfree(pool->rels);
+  queue_free(&pool->vendormap);
   for (i = 0; i < DEP2STRBUF; i++)
     xfree(pool->dep2strbuf[i]);
   xfree(pool);
index 1222256e64d6d0a504ce6a4f2061318fa23e590c..5e11eb04bf9f618aee56be2fa624a4ececdabce1 100644 (file)
@@ -80,6 +80,7 @@ struct _Pool {
 
   Id *id2arch;                 /* map arch ids to scores */
   Id lastarch;                 /* last valid entry in id2arch */
+  Queue vendormap;             /* map vendor to vendorclasses mask */
 
   /* providers data, as two-step indirect list
    * whatprovides[Id] -> Offset into whatprovidesdata for name
diff --git a/src/poolvendor.c b/src/poolvendor.c
new file mode 100644 (file)
index 0000000..b818445
--- /dev/null
@@ -0,0 +1,62 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define _GNU_SOURCE 1
+#include <fnmatch.h>
+
+#include "pool.h"
+#include "poolid.h"
+#include "poolvendor.h"
+#include "util.h"
+
+const char *vendors[] = {
+  "SUSE*",
+  "openSUSE*",
+  "SGI*",
+  "Novell*",
+  "Silicon Graphics*",
+  "Jpackage Project*",
+  "ATI Technologies Inc.*",
+  "Nvidia*",
+  0,
+  0,
+};
+
+Id pool_vendor2mask(Pool *pool, Id vendor)
+{
+  const char *vstr;
+  int i;
+  Id mask, m;
+  const char **v;
+
+  if (vendor == 0)
+    return 0;
+  for (i = 0; i < pool->vendormap.count; i += 2)
+    if (pool->vendormap.elements[i] == vendor)
+      return pool->vendormap.elements[i + 1];
+  vstr = id2str(pool, vendor);
+  m = 1;
+  mask = 0;
+  for (v = vendors; ; v++)
+    {
+      if (*v == 0)
+       {
+         v++;
+         if (*v == 0)
+           break;
+         if (m == (1 << 31))
+           break;
+         m <<= 1;
+       }
+      if (fnmatch(*v, vstr, FNM_CASEFOLD) == 0)
+       {
+         mask |= m;
+         while (v[1])
+           v++;
+       }
+    }
+  queue_push(&pool->vendormap, vendor);
+  queue_push(&pool->vendormap, mask);
+  return mask;
+}
diff --git a/src/poolvendor.h b/src/poolvendor.h
new file mode 100644 (file)
index 0000000..2596a43
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef POOLVENDOR_H
+#define POOLVENDOR_H
+
+#include "pool.h"
+
+Id pool_vendor2mask(Pool *pool, Id vendor);
+
+#endif /* POOLVENDOR_H */
index 8e5c56d0fd02aa7ac67b5470854017436cbe24e8..cf11b7913babcd227c9cd2b97ac2a26999c2695b 100644 (file)
@@ -14,6 +14,7 @@
 #include "pool.h"
 #include "util.h"
 #include "evr.h"
+#include "poolvendor.h"
 
 #define RULES_BLOCK 63
 
@@ -1073,15 +1074,15 @@ archchanges(Pool *pool, Solvable *s1, Solvable *s2)
   return 0;
 }
 
-
 static void
-findupdatepackages(Solver *solv, Solvable *s, Queue *qs, Map *m, int allowdowngrade, int allowarchchange)
+findupdatepackages(Solver *solv, Solvable *s, Queue *qs, Map *m, int allowdowngrade, int allowarchchange, int allowvendorchange)
 {
   /* installed packages get a special upgrade allowed rule */
   Pool *pool = solv->pool;
   Id p, *pp, n, p2, *pp2;
   Id obs, *obsp;
   Solvable *ps;
+  Id vendormask;
 
   queue_empty(qs);
   /*
@@ -1089,6 +1090,8 @@ findupdatepackages(Solver *solv, Solvable *s, Queue *qs, Map *m, int allowdowngr
    * n = solvable Id
    */
   n = s - pool->solvables;
+  vendormask = pool_vendor2mask(pool, s->vendor);
+
   if (m && !MAPTST(m, n))      /* add rule for s if not already done */
     addrulesforsolvable(solv, s, m);
 
@@ -1109,6 +1112,8 @@ findupdatepackages(Solver *solv, Solvable *s, Queue *qs, Map *m, int allowdowngr
          /* XXX */
          if (!allowarchchange && archchanges(pool, s, ps))
            continue;
+         if (!allowvendorchange && s->vendor != ps->vendor && vendormask && (vendormask & pool_vendor2mask(pool, ps->vendor)) == 0)
+           continue;
        }
       else if (!solv->noupdateprovide && ps->obsoletes)   /* provides/obsoletes combination ? */
        {
@@ -1156,7 +1161,7 @@ findupdatepackages(Solver *solv, Solvable *s, Queue *qs, Map *m, int allowdowngr
  */
 
 static void
-addupdaterule(Solver *solv, Solvable *s, Map *m, int allowdowngrade, int allowarchchange, int dontaddrule)
+addupdaterule(Solver *solv, Solvable *s, Map *m, int allowdowngrade, int allowarchchange, int allowvendorchange, int dontaddrule)
 {
   /* installed packages get a special upgrade allowed rule */
   Pool *pool = solv->pool;
@@ -1166,7 +1171,7 @@ addupdaterule(Solver *solv, Solvable *s, Map *m, int allowdowngrade, int allowar
   Id qsbuf[64];
 
   queue_init_buffer(&qs, qsbuf, sizeof(qsbuf)/sizeof(*qsbuf));
-  findupdatepackages(solv, s, &qs, m, allowdowngrade, allowarchchange);
+  findupdatepackages(solv, s, &qs, m, allowdowngrade, allowarchchange, allowvendorchange);
   p = s - pool->solvables;
   if (dontaddrule)     /* we consider update candidates but dont force them */
     {
@@ -2737,7 +2742,7 @@ solve(Solver *solv, Queue *job)
          break;
        case SOLVER_INSTALL_SOLVABLE_UPDATE:
          /* dont allow downgrade */
-         addupdaterule(solv, pool->solvables + what, &addedmap, 0, 0, 1);
+         addupdaterule(solv, pool->solvables + what, &addedmap, 0, 0, 0, 1);
          break;
        }
     }
@@ -2754,11 +2759,11 @@ solve(Solver *solv, Queue *job)
     {
       /* add update rule for every installed package */
       for (i = solv->installed->start; i < solv->installed->start + solv->installed->nsolvables; i++)
-        addupdaterule(solv, pool->solvables + i, &addedmap, solv->allowdowngrade, solv->allowarchchange, 1);
+        addupdaterule(solv, pool->solvables + i, &addedmap, solv->allowdowngrade, solv->allowarchchange, solv->allowvendorchange, 1);
     }
 #else  /* this is just to add the needed rpm rules to our set */
   for (i = solv->installed->start; i < solv->installed->start + solv->installed->nsolvables; i++)
-    addupdaterule(solv, pool->solvables + i, &addedmap, 1, 1, 1);
+    addupdaterule(solv, pool->solvables + i, &addedmap, 1, 1, 1, 1);
 #endif
 
   addrulesforweak(solv, &addedmap);
@@ -2855,7 +2860,7 @@ solve(Solver *solv, Queue *job)
            }
          break;
        case SOLVER_INSTALL_SOLVABLE_UPDATE:              /* find update for solvable */
-         addupdaterule(solv, pool->solvables + what, &addedmap, 0, 0, 0);
+         addupdaterule(solv, pool->solvables + what, &addedmap, 0, 0, 0, 0);
          queue_push(&solv->ruletojob, i);
          break;
        }
@@ -2885,7 +2890,7 @@ solve(Solver *solv, Queue *job)
       for (i = solv->installed->start; i < solv->installed->start + solv->installed->nsolvables; i++)
       {
        if (!MAPTST(&noupdaterule, i)) /* if not marked as 'noupdate' */
-         addupdaterule(solv, pool->solvables + i, &addedmap, solv->allowdowngrade, solv->allowarchchange, 0);
+         addupdaterule(solv, pool->solvables + i, &addedmap, solv->allowdowngrade, solv->allowarchchange, solv->allowvendorchange, 0);
         else
          addrule(solv, 0, 0);          /* place holder */
       }
@@ -2904,7 +2909,7 @@ solve(Solver *solv, Queue *job)
        {
          if (MAPTST(&noupdaterule, solv->installed->start + i))
            continue;
-         findupdatepackages(solv, pool->solvables + solv->installed->start + i, &q, (Map *)0, 1, 1);
+         findupdatepackages(solv, pool->solvables + solv->installed->start + i, &q, (Map *)0, 1, 1, 1);
          if (q.count)
            solv->weaksystemrules[i] = pool_queuetowhatprovides(pool, &q);
        }
@@ -3098,11 +3103,19 @@ solve(Solver *solv, Queue *job)
                          printf("- allow downgrade of %s-%s.%s to %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), id2str(pool, sd->name), id2str(pool, sd->evr), id2str(pool, sd->arch));
                          gotone = 1;
                        }
-                     if (!solv->allowarchchange && archchanges(pool, sd, s))
+                     if (!solv->allowarchchange && s->name == sd->name && archchanges(pool, sd, s))
                        {
                          printf("- allow architecture change of %s-%s.%s to %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), id2str(pool, sd->name), id2str(pool, sd->evr), id2str(pool, sd->arch));
                          gotone = 1;
                        }
+                     if (!solv->allowvendorchange && s->name == sd->name && s->vendor != sd->vendor && pool_vendor2mask(pool, s->vendor) && (pool_vendor2mask(pool, s->vendor) & pool_vendor2mask(pool, sd->vendor)) == 0)
+                       {
+                         if (sd->vendor)
+                           printf("- allow vendor change from '%s' (%s-%s.%s) to '%s' (%s-%s.%s)\n", id2str(pool, s->vendor), id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), id2str(pool, sd->vendor), id2str(pool, sd->name), id2str(pool, sd->evr), id2str(pool, sd->arch));
+                         else
+                           printf("- allow vendor change from '%s' (%s-%s.%s) to no vendor (%s-%s.%s)\n", id2str(pool, s->vendor), id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), id2str(pool, sd->name), id2str(pool, sd->evr), id2str(pool, sd->arch));
+                         gotone = 1;
+                       }
                      if (!gotone)
                        printf("- allow replacement of %s-%s.%s with %s-%s.%s\n", id2str(pool, s->name), id2str(pool, s->evr), id2str(pool, s->arch), id2str(pool, sd->name), id2str(pool, sd->evr), id2str(pool, sd->arch));
                    }
@@ -3117,9 +3130,9 @@ solve(Solver *solv, Queue *job)
                }
            }
          printf("------------------------------------\n");
-         queue_free(&problems);
-         queue_free(&solution);
        }
+      queue_free(&solution);
+      queue_free(&problems);
       return;
     }
 
index 9e23f40afcfc921293a074241f89d0e733ca177d..fb0c8b9ddaa0ad90caa3ab35061e8d5384fd3ff4 100644 (file)
@@ -44,6 +44,7 @@ typedef struct solver {
   int fixsystem;                       /* repair errors in rpm dependency graph */
   int allowdowngrade;                  /* allow to downgrade installed solvable */
   int allowarchchange;                 /* allow to change architecture of installed solvables */
+  int allowvendorchange;               /* allow to change vendor of installed solvables */
   int allowuninstall;                  /* allow removal of installed solvables */
   int updatesystem;                    /* distupgrade */
   int allowvirtualconflicts;           /* false: conflicts on package name, true: conflicts on package provides */