Imported Upstream version 0.6.9
[platform/upstream/libsolv.git] / ext / repo_rpmdb.c
index d37d8b7..71c69ab 100644 (file)
@@ -47,6 +47,9 @@
 #include "chksum.h"
 #include "repo_rpmdb.h"
 #include "repo_solv.h"
+#ifdef ENABLE_COMPLEX_DEPS
+#include "pool_parserpmrichdep.h"
+#endif
 
 /* 3: added triggers */
 /* 4: fixed triggers */
 #define DEP_STRONG             (1 << 27)
 #define DEP_PRE_IN             ((1 << 6) | (1 << 9) | (1 << 10))
 #define DEP_PRE_UN             ((1 << 6) | (1 << 11) | (1 << 12))
+#define DEP_RICH               (1 << 29)
 
 #define FILEFLAG_GHOST         (1 <<  6)
 
@@ -404,7 +408,6 @@ setutf8string(Repodata *repodata, Id handle, Id tag, const char *str)
     repodata_set_str(repodata, handle, tag, str);
 }
 
-
 /*
  * strong: 0: ignore strongness
  *         1: filter to strong
@@ -512,6 +515,7 @@ makedeps(Pool *pool, Repo *repo, RpmHead *rpmhead, int tagn, int tagv, int tagf,
   ida = repo->idarraydata + olddeps;
   for (i = 0; ; i++)
     {
+      Id id;
       if (i == nc)
        {
          if (haspre != 1)
@@ -532,9 +536,21 @@ makedeps(Pool *pool, Repo *repo, RpmHead *rpmhead, int tagn, int tagv, int tagf,
       if ((flags & RPM_ADD_NO_RPMLIBREQS) != 0)
        if (!strncmp(n[i], "rpmlib(", 7))
          continue;
+#ifdef ENABLE_COMPLEX_DEPS
+      if ((f[i] & (DEP_RICH|DEP_LESS| DEP_EQUAL|DEP_GREATER)) == DEP_RICH && n[i][0] == '(')
+       {
+         id = pool_parserpmrichdep(pool, n[i]);
+         if (id)
+           *ida++ = id;
+         else
+           cc--;
+         continue;
+       }
+#endif
+      id = pool_str2id(pool, n[i], 1);
       if (f[i] & (DEP_LESS|DEP_GREATER|DEP_EQUAL))
        {
-         Id name, evr;
+         Id evr;
          int fl = 0;
          if ((f[i] & DEP_LESS) != 0)
            fl |= REL_LT;
@@ -542,15 +558,13 @@ makedeps(Pool *pool, Repo *repo, RpmHead *rpmhead, int tagn, int tagv, int tagf,
            fl |= REL_EQ;
          if ((f[i] & DEP_GREATER) != 0)
            fl |= REL_GT;
-         name = pool_str2id(pool, n[i], 1);
          if (v[i][0] == '0' && v[i][1] == ':' && v[i][2])
            evr = pool_str2id(pool, v[i] + 2, 1);
          else
            evr = pool_str2id(pool, v[i], 1);
-         *ida++ = pool_rel2id(pool, name, evr, fl, 1);
+         id = pool_rel2id(pool, id, evr, fl, 1);
        }
-      else
-        *ida++ = pool_str2id(pool, n[i], 1);
+      *ida++ = id;
     }
   *ida++ = 0;
   repo->idarraysize += cc + 1;
@@ -717,8 +731,23 @@ adddudata(Repodata *data, Id handle, RpmHead *rpmhead, char **dn, unsigned int *
   solv_free(fkb);
 }
 
+static int
+is_filtered(const char *dir)
+{
+  if (!dir)
+    return 1;
+  /* the dirs always have a trailing / in rpm */
+  if (strstr(dir, "bin/"))
+    return 0;
+  if (!strncmp(dir, "/etc/", 5))
+    return 0;
+  if (!strcmp(dir, "/usr/lib/"))
+    return 2;
+  return 1;
+}
+
 static void
-addfilelist(Repodata *data, Id handle, RpmHead *rpmhead)
+addfilelist(Repodata *data, Id handle, RpmHead *rpmhead, int flags)
 {
   char **bn;
   char **dn;
@@ -727,6 +756,7 @@ addfilelist(Repodata *data, Id handle, RpmHead *rpmhead)
   int i;
   Id lastdid = 0;
   unsigned int lastdii = -1;
+  int lastfiltered = 0;
 
   if (!data)
     return;
@@ -765,14 +795,25 @@ addfilelist(Repodata *data, Id handle, RpmHead *rpmhead)
        {
          if (di[i] >= dnc)
            continue;   /* corrupt entry */
-         did = repodata_str2dir(data, dn[di[i]], 1);
+         lastdii = di[i];
+         if ((flags & RPM_ADD_FILTERED_FILELIST) != 0)
+           {
+             lastfiltered = is_filtered(dn[di[i]]);
+             if (lastfiltered == 1)
+               continue;
+           }
+         did = repodata_str2dir(data, dn[lastdii], 1);
          if (!did)
            did = repodata_str2dir(data, "/", 1);
          lastdid = did;
-         lastdii = di[i];
        }
       if (b && *b == '/')      /* work around rpm bug */
        b++;
+      if (lastfiltered)
+       {
+         if (lastfiltered != 2 || strcmp(b, "sendmail"))
+           continue;
+       }
       repodata_add_dirstr(data, handle, SOLVABLE_FILELIST, did, b);
     }
   solv_free(bn);
@@ -994,7 +1035,7 @@ rpm2solv(Pool *pool, Repo *repo, Repodata *data, Solvable *s, RpmHead *rpmhead,
            }
        }
       if ((flags & RPM_ADD_NO_FILELIST) == 0)
-       addfilelist(data, handle, rpmhead);
+       addfilelist(data, handle, rpmhead, flags);
       if ((flags & RPM_ADD_WITH_CHANGELOG) != 0)
        addchangelog(data, handle, rpmhead);
     }
@@ -1018,6 +1059,7 @@ struct rpmdbstate {
   DB_ENV *dbenv;       /* database environment */
   DB *db;              /* packages database */
   int byteswapped;     /* endianess of packages database */
+  int is_ostree;       /* read-only db that lives in /usr/share/rpm */
 };
 
 struct rpmdbentry {
@@ -1108,6 +1150,10 @@ opendbenv(struct rpmdbstate *state)
   snprintf(dbpath, PATH_MAX, "%s/var/lib/rpm", rootdir ? rootdir : "");
   if (access(dbpath, W_OK) == -1)
     {
+      snprintf(dbpath, PATH_MAX, "%s/usr/share/rpm/Packages", rootdir ? rootdir : "");
+      if (access(dbpath, R_OK) == 0)
+       state->is_ostree = 1;
+      snprintf(dbpath, PATH_MAX, "%s%s", rootdir ? rootdir : "", state->is_ostree ? "/usr/share/rpm" : "/var/lib/rpm");
       r = dbenv->open(dbenv, dbpath, DB_CREATE|DB_PRIVATE|DB_INIT_MPOOL, 0);
     }
   else
@@ -1382,12 +1428,12 @@ freestate(struct rpmdbstate *state)
   /* close down */
   if (!state)
     return;
-  if (state->rootdir)
-    solv_free(state->rootdir);
   if (state->db)
     state->db->close(state->db, 0);
   if (state->dbenv)
     closedbenv(state);
+  if (state->rootdir)
+    solv_free(state->rootdir);
   solv_free(state->rpmhead);
 }
 
@@ -1421,7 +1467,7 @@ count_headers(struct rpmdbstate *state)
   DBT dbkey;
   DBT dbdata;
 
-  snprintf(dbpath, PATH_MAX, "%s/var/lib/rpm/Name", state->rootdir ? state->rootdir : "");
+  snprintf(dbpath, PATH_MAX, "%s%s/Name", state->rootdir ? state->rootdir : "", state->is_ostree ? "/usr/share/rpm" : "/var/lib/rpm");
   if (stat(dbpath, &statbuf))
     return 0;
   memset(&dbkey, 0, sizeof(dbkey));
@@ -1573,12 +1619,12 @@ solvable_copy_cb(void *vcbdata, Solvable *r, Repodata *fromdata, Repokey *key, K
       cbdata->handle = repodata_new_handle(data);
       repodata_add_flexarray(data, cbdata->subhandle, keyname, cbdata->handle);
       break;
-    case REPOKEY_TYPE_MD5:
-    case REPOKEY_TYPE_SHA1:
-    case REPOKEY_TYPE_SHA256:
-      repodata_set_bin_checksum(data, handle, keyname, key->type, (const unsigned char *)kv->str);
-      break;
     default:
+      if (solv_chksum_len(key->type))
+       {
+         repodata_set_bin_checksum(data, handle, keyname, key->type, (const unsigned char *)kv->str);
+         break;
+       }
       break;
     }
   return 0;
@@ -1739,7 +1785,7 @@ repo_add_rpmdb(Repo *repo, Repo *ref, int flags)
     }
 
   /* XXX: should get ro lock of Packages database! */
-  snprintf(dbpath, PATH_MAX, "%s/var/lib/rpm/Packages", state.rootdir ? state.rootdir : "");
+  snprintf(dbpath, PATH_MAX, "%s%s/Packages", state.rootdir ? state.rootdir : "", state.is_ostree ? "/usr/share/rpm" : "/var/lib/rpm");
   if (stat(dbpath, &packagesstat))
     {
       pool_error(pool, -1, "%s: %s", dbpath, strerror(errno));