support medianr in lookup_deltalocation, change lookup_location to return medianr...
[platform/upstream/libsolv.git] / src / pool.c
index a08a1d3..4b6ab43 100644 (file)
@@ -54,25 +54,34 @@ pool_create(void)
   pool->nsolvables = 2;
   memset(pool->solvables, 0, 2 * sizeof(Solvable));
 
+  queue_init(&pool->vendormap);
+
+#if defined(DEBIAN)
+  pool->disttype = DISTTYPE_DEB;
+  pool->noarchid = ARCH_ALL;
+#elif defined(ARCHLINUX)
+  pool->disttype = DISTTYPE_ARCH;
+  pool->noarchid = ARCH_ANY;
+#else
+  pool->disttype = DISTTYPE_RPM;
+  pool->noarchid = ARCH_NOARCH;
+#endif
+
   /* initialize the system solvable */
   s = pool->solvables + SYSTEMSOLVABLE;
   s->name = SYSTEM_SYSTEM;
-  s->arch = ARCH_NOARCH;
+  s->arch = pool->noarchid;
   s->evr = ID_EMPTY;
 
-  queue_init(&pool->vendormap);
-
   pool->debugmask = SOLV_DEBUG_RESULT; /* FIXME */
 #ifdef FEDORA
   pool->obsoleteusescolors = 1;
 #endif
-#ifdef DEBIAN 
-  pool->disttype = DISTTYPE_DEB;
-#endif
 #ifdef RPM5
   pool->forbidselfconflicts = 1;
   pool->obsoleteusesprovides = 1;
   pool->implicitobsoleteusesprovides = 1;
+  pool->havedistepoch = 1;
 #endif
   return pool;
 }
@@ -100,6 +109,8 @@ pool_free(Pool *pool)
     free((char *)pool->languages[i]);
   solv_free(pool->languages);
   solv_free(pool->languagecache);
+  solv_free(pool->errstr);
+  solv_free(pool->rootdir);
   solv_free(pool);
 }
 
@@ -124,6 +135,13 @@ void
 pool_setdisttype(Pool *pool, int disttype)
 {
   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;
+  pool->solvables[SYSTEMSOLVABLE].arch = pool->noarchid;
 }
 #endif
 
@@ -144,6 +162,8 @@ pool_get_flag(Pool *pool, int flag)
       return pool->obsoleteusescolors;
     case POOL_FLAG_NOINSTALLEDOBSOLETES:
       return pool->noinstalledobsoletes;
+    case POOL_FLAG_HAVEDISTEPOCH:
+      return pool->havedistepoch;
     default:
       break;
     }
@@ -174,6 +194,9 @@ pool_set_flag(Pool *pool, int flag, int value)
     case POOL_FLAG_NOINSTALLEDOBSOLETES:
       pool->noinstalledobsoletes = value;
       break;
+    case POOL_FLAG_HAVEDISTEPOCH:
+      pool->havedistepoch = value;
+      break;
     default:
       break;
     }
@@ -505,7 +528,7 @@ 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)
+#elif defined(DEBIAN)
 # define EVRCMP_DEPCMP EVRCMP_COMPARE
 #else
 # define EVRCMP_DEPCMP EVRCMP_MATCH_RELEASE
@@ -527,7 +550,10 @@ pool_match_nevr_rel(Pool *pool, Solvable *s, Id d)
        {
        case REL_ARCH:
          if (s->arch != evr)
-           return 0;
+           {
+             if (evr != ARCH_SRC || s->arch != ARCH_NOSRC)
+               return 0;
+           }
          return pool_match_nevr(pool, s, name);
        case REL_OR:
          if (pool_match_nevr(pool, s, name))
@@ -718,12 +744,14 @@ pool_addrelproviders(Pool *pool, Id d)
           * we have to iterate over the solvables as src packages do not
           * provide anything, thus they are not indexed in our
           * whatprovides hash */
-         if (evr == ARCH_SRC)
+         if (evr == ARCH_SRC || evr == ARCH_NOSRC)
            {
              Solvable *s;
              for (p = 1, s = pool->solvables + p; p < pool->nsolvables; p++, s++)
                {
-                 if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
+                 if (!s->repo)
+                   continue;
+                 if (s->arch != evr && s->arch != ARCH_NOSRC)
                    continue;
                  if (pool_match_nevr(pool, s, name))
                    queue_push(&plist, p);
@@ -850,15 +878,56 @@ pool_debug(Pool *pool, int type, const char *format, ...)
       return;
     }
   vsnprintf(buf, sizeof(buf), format, args);
+  va_end(args);
   pool->debugcallback(pool, pool->debugcallbackdata, type, buf);
 }
 
+int
+pool_error(Pool *pool, int ret, const char *format, ...)
+{
+  va_list args;
+  int l;
+  va_start(args, format);
+  if (!pool->errstr)
+    {
+      pool->errstra = 1024;
+      pool->errstr = solv_malloc(pool->errstra);
+    }
+  if (!*format)
+    {
+      *pool->errstr = 0;
+      l = 0;
+    }
+  else
+    l = vsnprintf(pool->errstr, pool->errstra, format, args);
+  va_end(args);
+  if (l >= 0 && l + 1 > pool->errstra)
+    {
+      pool->errstra = l + 256;
+      pool->errstr = solv_realloc(pool->errstr, pool->errstra);
+      va_start(args, format);
+      l = vsnprintf(pool->errstr, pool->errstra, format, args);
+      va_end(args);
+    }
+  if (l < 0)
+    strcpy(pool->errstr, "unknown error");
+  if (pool->debugmask & SOLV_ERROR)
+    pool_debug(pool, SOLV_ERROR, "%s\n", pool->errstr);
+  return ret;
+}
+
+char *
+pool_errstr(Pool *pool)
+{
+  return pool->errstr ? pool->errstr : "no error";
+}
+
 void
 pool_setdebuglevel(Pool *pool, int level)
 {
   int mask = SOLV_DEBUG_RESULT;
   if (level > 0)
-    mask |= SOLV_DEBUG_STATS|SOLV_DEBUG_ANALYZE|SOLV_DEBUG_UNSOLVABLE|SOLV_DEBUG_SOLVER|SOLV_DEBUG_TRANSACTION;
+    mask |= SOLV_DEBUG_STATS|SOLV_DEBUG_ANALYZE|SOLV_DEBUG_UNSOLVABLE|SOLV_DEBUG_SOLVER|SOLV_DEBUG_TRANSACTION|SOLV_ERROR;
   if (level > 1)
     mask |= SOLV_DEBUG_JOB|SOLV_DEBUG_SOLUTIONS|SOLV_DEBUG_POLICY;
   if (level > 2)
@@ -1703,7 +1772,7 @@ pool_calc_installsizechange(Pool *pool, Map *installedmap)
        continue;
       if (!MAPTST(installedmap, sp))
        continue;
-      change += solvable_lookup_num(s, SOLVABLE_INSTALLSIZE, 0);
+      change += solvable_lookup_sizek(s, SOLVABLE_INSTALLSIZE, 0);
     }
   if (oldinstalled)
     {
@@ -1711,7 +1780,7 @@ pool_calc_installsizechange(Pool *pool, Map *installedmap)
        {
          if (MAPTST(installedmap, sp))
            continue;
-         change -= solvable_lookup_num(s, SOLVABLE_INSTALLSIZE, 0);
+         change -= solvable_lookup_sizek(s, SOLVABLE_INSTALLSIZE, 0);
        }
     }
   return change;
@@ -1955,12 +2024,12 @@ pool_lookup_id(Pool *pool, Id entry, Id keyname)
   return solvable_lookup_id(pool->solvables + entry, keyname);
 }
 
-unsigned int
-pool_lookup_num(Pool *pool, Id entry, Id keyname, unsigned int notfound)
+unsigned long long
+pool_lookup_num(Pool *pool, Id entry, Id keyname, unsigned long long notfound)
 {
   if (entry == SOLVID_POS && pool->pos.repo)
     {
-      unsigned int value;
+      unsigned long long value;
       if (repodata_lookup_num(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname, &value))
        return value;
       return notfound;
@@ -2003,6 +2072,21 @@ pool_lookup_checksum(Pool *pool, Id entry, Id keyname, Id *typep)
   return solvable_lookup_checksum(pool->solvables + entry, keyname, typep);
 }
 
+const char *
+pool_lookup_deltalocation(Pool *pool, Id entry, unsigned int *medianrp)
+{
+  const char *loc;
+  if (medianrp)
+    *medianrp = 0;
+  if (entry != SOLVID_POS)
+    return 0;
+  loc = pool_lookup_str(pool, entry, DELTA_LOCATION_DIR);
+  loc = pool_tmpjoin(pool, loc, loc ? "/" : 0, pool_lookup_str(pool, entry, DELTA_LOCATION_NAME));
+  loc = pool_tmpappend(pool, loc, "-", pool_lookup_str(pool, entry, DELTA_LOCATION_EVR));
+  loc = pool_tmpappend(pool, loc, ".", pool_lookup_str(pool, entry, DELTA_LOCATION_SUFFIX));
+  return loc;
+}
+
 void
 pool_add_fileconflicts_deps(Pool *pool, Queue *conflicts)
 {
@@ -2035,4 +2119,37 @@ pool_add_fileconflicts_deps(Pool *pool, Queue *conflicts)
     pool_freeidhashes(pool);
 }
 
+char *
+pool_prepend_rootdir(Pool *pool, const char *path)
+{
+  if (!path)
+    return 0;
+  if (!pool->rootdir)
+    return solv_strdup(path);
+  return solv_dupjoin(pool->rootdir, "/", *path == '/' ? path + 1 : path);
+}
+
+const char *
+pool_prepend_rootdir_tmp(Pool *pool, const char *path)
+{
+  if (!path)
+    return 0;
+  if (!pool->rootdir)
+    return path;
+  return pool_tmpjoin(pool, pool->rootdir, "/", *path == '/' ? path + 1 : path);
+}
+
+void
+pool_set_rootdir(Pool *pool, const char *rootdir)
+{
+  solv_free(pool->rootdir);
+  pool->rootdir = solv_strdup(rootdir);
+}
+
+const char *
+pool_get_rootdir(Pool *pool)
+{
+  return pool->rootdir;
+}
+
 /* EOF */