- also look at triggers when ordering packages
authorMichael Schroeder <mls@suse.de>
Mon, 21 Sep 2009 14:11:20 +0000 (16:11 +0200)
committerMichael Schroeder <mls@suse.de>
Mon, 21 Sep 2009 14:11:20 +0000 (16:11 +0200)
ext/repo_rpmdb.c
ext/repo_rpmdb.h
ext/repo_write.c
src/knownid.h
src/pool.h
src/transaction.c

index eb95b82..ee3626b 100644 (file)
@@ -43,7 +43,8 @@
 #include "chksum.h"
 #include "repo_rpmdb.h"
 
-#define RPMDB_COOKIE_VERSION 2
+/* 3: added triggers */
+#define RPMDB_COOKIE_VERSION 3
 
 #define TAG_NAME               1000
 #define TAG_VERSION            1001
@@ -76,6 +77,9 @@
 #define TAG_CONFLICTFLAGS      1053
 #define TAG_CONFLICTNAME       1054
 #define TAG_CONFLICTVERSION    1055
+#define TAG_TRIGGERNAME                1066
+#define TAG_TRIGGERVERSION     1067
+#define TAG_TRIGGERFLAGS       1068
 #define TAG_OBSOLETENAME       1090
 #define TAG_FILEDEVICES                1095
 #define TAG_FILEINODES         1096
@@ -930,6 +934,27 @@ rpm2solv(Pool *pool, Repo *repo, Repodata *data, Solvable *s, RpmHead *rpmhead,
         repodata_set_num(data, handle, SOLVABLE_INSTALLSIZE, (u32 + 1023) / 1024);
       if (sourcerpm)
        addsourcerpm(pool, data, handle, sourcerpm, name, evr);
+      if ((flags & RPM_ADD_TRIGGERS) != 0)
+       {
+         Id id, lastid;
+         unsigned int ida = makedeps(pool, repo, rpmhead, TAG_TRIGGERNAME, TAG_TRIGGERVERSION, TAG_TRIGGERFLAGS, 0);
+
+         lastid = 0;
+         for (; (id = repo->idarraydata[ida]) != 0; ida++)
+           {
+             /* we currently do not support rel ids in incore data, so
+              * strip off versioning information */
+             while (ISRELDEP(id))
+               {
+                 Reldep *rd = GETRELDEP(pool, id);
+                 id = rd->name;
+               }
+             if (id == lastid)
+               continue;
+             repodata_add_idarray(data, handle, SOLVABLE_TRIGGERS, id);
+             lastid = id;
+           }
+       }
     }
   sat_free(evr);
   return 1;
@@ -1412,7 +1437,7 @@ repo_add_rpmdb(Repo *repo, Repo *ref, const char *rootdir, int flags)
          memcpy(rpmhead->data, (unsigned char *)dbdata.data + 8, rpmhead->cnt * 16 + rpmhead->dcnt);
          rpmhead->dp = rpmhead->data + rpmhead->cnt * 16;
          repo->rpmdbid[(s - pool->solvables) - repo->start] = dbid;
-         if (rpm2solv(pool, repo, data, s, rpmhead, flags))
+         if (rpm2solv(pool, repo, data, s, rpmhead, flags | RPM_ADD_TRIGGERS))
            {
              i++;
              s = 0;
@@ -1648,7 +1673,7 @@ repo_add_rpmdb(Repo *repo, Repo *ref, const char *rootdir, int flags)
          memcpy(rpmhead->data, (unsigned char *)dbdata.data + 8, rpmhead->cnt * 16 + rpmhead->dcnt);
          rpmhead->dp = rpmhead->data + rpmhead->cnt * 16;
 
-         rpm2solv(pool, repo, data, s, rpmhead, flags);
+         rpm2solv(pool, repo, data, s, rpmhead, flags | RPM_ADD_TRIGGERS);
          if ((flags & RPMDB_REPORT_PROGRESS) != 0)
            {
              if (done < count)
index b801a48..92cd403 100644 (file)
@@ -21,6 +21,7 @@ void repo_add_pubkeys(Repo *repo, const char **keys, int nkeys, int flags);
 #define RPM_ADD_NO_RPMLIBREQS  (1 << 11)
 #define RPM_ADD_WITH_SHA1SUM   (1 << 12)
 #define RPM_ADD_WITH_SHA256SUM (1 << 13)
+#define RPM_ADD_TRIGGERS       (1 << 14)
 
 #define RPM_ITERATE_FILELIST_ONLYDIRS  (1 << 0)
 #define RPM_ITERATE_FILELIST_WITHMD5   (1 << 1)
index 9cb4f57..2f0d4e4 100644 (file)
@@ -749,6 +749,7 @@ repo_write_adddata(struct cbdata *cbdata, Repodata *data, Repokey *key, KeyValue
   unsigned int u32;
   unsigned char v[4];
   struct extdata *xd;
+  NeedId *needid;
 
   if (key->name == REPOSITORY_SOLVABLES)
     return SEARCH_NEXT_KEY;
@@ -778,14 +779,16 @@ repo_write_adddata(struct cbdata *cbdata, Repodata *data, Repokey *key, KeyValue
        id = kv->id;
        if (!ISRELDEP(id) && cbdata->ownspool && id > 1)
          id = putinownpool(cbdata, data->localpool ? &data->spool : &data->repo->pool->ss, id);
-       id = cbdata->needid[id].need;
+       needid = cbdata->needid;
+       id = needid[ISRELDEP(id) ? RELOFF(id) : id].need;
        data_addid(xd, id);
        break;
       case REPOKEY_TYPE_IDARRAY:
        id = kv->id;
        if (cbdata->ownspool && id > 1)
          id = putinownpool(cbdata, data->localpool ? &data->spool : &data->repo->pool->ss, id);
-       id = cbdata->needid[id].need;
+       needid = cbdata->needid;
+       id = needid[ISRELDEP(id) ? RELOFF(id) : id].need;
        data_addideof(xd, id, kv->eof);
        break;
       case REPOKEY_TYPE_STR:
index 56dae52..0db9a91 100644 (file)
@@ -86,6 +86,7 @@ KNOWNID(REPOKEY_TYPE_NUM,             "repokey:type:num"),
 KNOWNID(REPOKEY_TYPE_U32,              "repokey:type:num32"),
 KNOWNID(REPOKEY_TYPE_DIR,              "repokey:type:dir"),
 KNOWNID(REPOKEY_TYPE_STR,              "repokey:type:str"),
+KNOWNID(REPOKEY_TYPE_BINARY,           "repokey:type:binary"),
 KNOWNID(REPOKEY_TYPE_IDARRAY,          "repokey:type:idarray"),
 KNOWNID(REPOKEY_TYPE_REL_IDARRAY,      "repokey:type:relidarray"),
 KNOWNID(REPOKEY_TYPE_DIRSTRARRAY,      "repokey:type:dirstrarray"),
@@ -124,6 +125,7 @@ KNOWNID(SOLVABLE_SOURCEARCH,                "solvable:sourcearch"),
 KNOWNID(SOLVABLE_SOURCENAME,           "solvable:sourcename"),
 KNOWNID(SOLVABLE_SOURCEEVR,            "solvable:sourceevr"),
 KNOWNID(SOLVABLE_ISVISIBLE,            "solvable:isvisible"),
+KNOWNID(SOLVABLE_TRIGGERS,             "solvable:triggers"),
 KNOWNID(SOLVABLE_CHECKSUM,             "solvable:checksum"),
 KNOWNID(SOLVABLE_PKGID,                        "solvable:pkgid"),      /* pkgid: md5sum over header + payload */
 KNOWNID(SOLVABLE_HDRID,                        "solvable:hdrid"),      /* hdrid: sha1sum over header only */
index 6996207..d82a64d 100644 (file)
@@ -215,6 +215,7 @@ int solvable_lookup_void(Solvable *s, Id keyname);
 char * solvable_get_location(Solvable *s, unsigned int *medianrp);
 const unsigned char *solvable_lookup_bin_checksum(Solvable *s, Id keyname, Id *typep);
 const char *solvable_lookup_checksum(Solvable *s, Id keyname, Id *typep);
+int solvable_lookup_idarray(Solvable *s, Id keyname, Queue *q);
 int solvable_identical(Solvable *s1, Solvable *s2);
 Id solvable_selfprovidedep(Solvable *s);
 
index 2c341d3..2a481fa 100644 (file)
@@ -1243,6 +1243,33 @@ addsolvableedges(struct orderdata *od, Solvable *s)
            }
        }
     }
+  if (s->repo == installed && solvable_lookup_idarray(s, SOLVABLE_TRIGGERS, &reqq) && reqq.count)
+    {
+      /* we're getting deinstalled/updated. Try to do this before our
+       * triggers are hit */
+      for (i = 0; i < reqq.count; i++)
+       {
+         Id tri = reqq.elements[i];
+         FOR_PROVIDES(p2, pp2, tri)
+           {
+             if (p2 == p)
+               continue;
+             s2 = pool->solvables + p2;
+             if (!s2->repo)
+               continue;
+             if (s2->name == s->name)
+               continue;       /* obsoleted anyway */
+             if (s2->repo != installed && MAPTST(&trans->transactsmap, p2))
+               {
+                 /* deinstall/update p before installing p2 */
+#if 0
+                 printf("add trigger uninst->inst edge (%s -> %s -> %s)\n", solvid2str(pool, p2), dep2str(pool, tri), solvid2str(pool, p));
+#endif
+                 addedge(od, p2, p, TYPE_CON);
+               }
+           }
+       }
+    }
   queue_free(&reqq);
 }