- add evrmatch
authorMichael Schroeder <mls@suse.de>
Fri, 21 Dec 2007 18:16:33 +0000 (18:16 +0000)
committerMichael Schroeder <mls@suse.de>
Fri, 21 Dec 2007 18:16:33 +0000 (18:16 +0000)
- first shot at adding file provides

src/evr.c
src/evr.h
src/pool.c
src/pool.h

index 9ea0398..185cb7c 100644 (file)
--- a/src/evr.c
+++ b/src/evr.c
@@ -167,4 +167,52 @@ evrcmp(Pool *pool, Id evr1id, Id evr2id, int mode)
   return r;
 }
 
+int
+evrmatch(Pool *pool, Id evrid, const char *epoch, const char *version, const char *release)
+{
+  const char *evr1;
+  const char *s1;
+  const char *r1;
+  int r;
+
+  evr1 = id2str(pool, evrid);
+  for (s1 = evr1; *s1 >= '0' && *s1 <= '9'; s1++)
+    ;
+  if (s1 != evr1 && *s1 == ':')
+    {
+      if (epoch)
+       {
+         r = vercmp(evr1, s1, epoch, epoch + strlen(epoch));
+         if (r)
+           return r;
+       }
+      evr1 = s1 + 1;
+    }
+  else if (epoch)
+    {
+      while (*epoch == '0')
+       epoch++;
+      if (*epoch)
+       return -1;
+    }
+  for (s1 = evr1, r1 = 0; *s1; s1++)
+    if (*s1 == '-')
+      r1 = s1;
+  if (version)
+    {
+      r = vercmp(evr1, r1 ? r1 : s1, version, version + strlen(version));
+      if (r)
+       return r;
+    }
+  if (release)
+    {
+      if (!r1)
+       return -1;
+      r = vercmp(r1 + 1, s1, release, release + strlen(release));
+      if (r)
+       return r;
+    }
+  return 0;
+}
+
 // EOF
index 7606608..bf80358 100644 (file)
--- a/src/evr.h
+++ b/src/evr.h
@@ -25,6 +25,7 @@ extern "C" {
 
 extern int vercmp(const char *s1, const char *q1, const char *s2, const char *q2);
 extern int evrcmp(Pool *pool, Id evr1id, Id evr2id, int mode);
+extern int evrmatch(Pool *pool, Id evrid, const char *epoch, const char *version, const char *release);
 
 #ifdef __cplusplus
 }
index d23d76c..5ac60a3 100644 (file)
@@ -24,6 +24,7 @@
 #include "poolid_private.h"
 #include "poolarch.h"
 #include "util.h"
+#include "bitmap.h"
 #include "evr.h"
 
 #define SOLVABLE_BLOCK 255
@@ -626,5 +627,132 @@ pool_setdebuglevel(Pool *pool, int level)
   pool->debugmask = mask;
 }
 
+/*************************************************************************/
+
+struct searchfiles {
+  const char **files;
+  int nfiles;
+};
+
+#define SEARCHFILES_BLOCK 127
+
+static void
+pool_addfileprovides_dep(Pool *pool, Id *ida, Map *seen, struct searchfiles *sf)
+{
+  Id dep, sid;
+  const char *s;
+
+  while ((dep = *ida++) != 0)
+    {
+      while (ISRELDEP(dep))
+       {
+         Reldep *rd;
+         sid = pool->ss.nstrings + GETRELID(dep);
+         if (MAPTST(seen, sid))
+           {
+             dep = 0;
+             break;
+           }
+         MAPSET(seen, sid);
+         rd = GETRELDEP(pool, dep);
+         if (rd->flags < 8)
+           dep = rd->name;
+         else if (rd->flags == REL_NAMESPACE)
+           {
+             if (rd->name == NAMESPACE_INSTALLED)
+               {
+                 dep = 0;      /* for now */
+                 break;
+               }
+             dep = rd->evr;
+           }
+         else
+           {
+             Id ids[2];
+             ids[0] = rd->name;
+             ids[1] = 0;
+             pool_addfileprovides_dep(pool, ids, seen, sf);
+             dep = rd->evr;
+           }
+       }
+      if (!dep)
+       continue;
+      if (MAPTST(seen, dep))
+       continue;
+      MAPSET(seen, dep);
+      s = id2str(pool, dep);
+      if (*s != '/')
+       continue;
+      if ((sf->nfiles & SEARCHFILES_BLOCK) == 0)
+       sf->files = xrealloc2(sf->files, sf->nfiles + (SEARCHFILES_BLOCK + 1), sizeof(const char *));
+      sf->files[sf->nfiles++] = strdup(s);
+    }
+}
+
+#if 0
+static int
+addfileprovides_cb(void *data, Solvable *s, Id key, const char *str)
+{
+  Pool *pool = s->repo->pool;
+  Id id;
+  id = str2id(pool, str, 0);
+  if (!id)
+    return 0;  /* can't happen */
+  s->provides = repo_addid_dep(s->repo, s->provides, id, SOLVABLE_FILEMARKER);
+  return 0;
+}
+#endif
+
+void
+pool_addfileprovides(Pool *pool)
+{
+  Solvable *s;
+  Repo *repo;
+  Map seen;
+  struct searchfiles sf;
+  int i;
+
+  map_init(&seen, pool->ss.nstrings + pool->nrels);
+  memset(&sf, 0, sizeof(sf));
+
+  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, &seen, &sf);
+      if (s->conflicts)
+        pool_addfileprovides_dep(pool, repo->idarraydata + s->conflicts, &seen, &sf);
+      if (s->requires)
+        pool_addfileprovides_dep(pool, repo->idarraydata + s->requires, &seen, &sf);
+      if (s->recommends)
+        pool_addfileprovides_dep(pool, repo->idarraydata + s->recommends, &seen, &sf);
+      if (s->suggests)
+        pool_addfileprovides_dep(pool, repo->idarraydata + s->suggests, &seen, &sf);
+      if (s->supplements)
+        pool_addfileprovides_dep(pool, repo->idarraydata + s->supplements, &seen, &sf);
+      if (s->enhances)
+        pool_addfileprovides_dep(pool, repo->idarraydata + s->enhances, &seen, &sf);
+      if (s->freshens)
+        pool_addfileprovides_dep(pool, repo->idarraydata + s->freshens, &seen, &sf);
+    }
+  map_free(&seen);
+  POOL_DEBUG(SAT_DEBUG_STATS, "found %d file dependencies\n", sf.nfiles);
+  if (!sf.nfiles)
+    return;
+#if 0
+  for (i = 0; i < sf.nfiles; i++)
+    POOL_DEBUG(SAT_DEBUG_STATS, "looking up %s in filelist\n", sf.files[i]);
+#endif
+  if ((sf.nfiles & SEARCHFILES_BLOCK) == 0)
+    sf.files = xrealloc2(sf.files, sf.nfiles + (SEARCHFILES_BLOCK + 1), sizeof(const char *));
+  sf.files[sf.nfiles++] = 0;
+#if 0
+  pool_search(0, SOLVABLE_FILELIST, (const char *)sf.files, SEARCH_STRING|SEARCH_MULTIPLE, addfileprovides_cb, 0);
+#endif
+  xfree(sf.files);
+  pool_freewhatprovides(pool); /* as we have added provides */
+}
 
 // EOF
index 261c7c2..01beb33 100644 (file)
@@ -207,6 +207,7 @@ extern const char *solvable2str(Pool *pool, Solvable *s);
  * Prepares a pool for solving
  */
 extern void pool_createwhatprovides(Pool *pool);
+extern void pool_addfileprovides(Pool *pool);
 extern void pool_freewhatprovides(Pool *pool);
 extern Id pool_queuetowhatprovides(Pool *pool, Queue *q);