Implement pretrans, posttrans and verifyscript as psm goals
authorPanu Matilainen <pmatilai@redhat.com>
Thu, 25 Feb 2010 12:22:34 +0000 (14:22 +0200)
committerPanu Matilainen <pmatilai@redhat.com>
Thu, 25 Feb 2010 12:22:34 +0000 (14:22 +0200)
- Loose rpmpsmScriptStage() hack and bury the psm details inside
  the psm implementation
- Map the script-only goal enums to the corresponding script tag
  to avoid having to re-re-re-map stuff unnecessarily
- pretrans and posttrans should really be handled as a part of PKG_INSTALL
  process, but as these stages are disconnected from the main install
  part we can't remember the state in the psm - it would need to be
  stashed into transaction elements in the meanwhile

lib/psm.c
lib/psm.h
lib/transaction.c
lib/verify.c

index 1b46500..a7cd4f4 100644 (file)
--- a/lib/psm.c
+++ b/lib/psm.c
 #define        _PSM_DEBUG      0
 int _psm_debug = _PSM_DEBUG;
 
-/**
- */
+typedef enum pkgStage_e {
+    PSM_UNKNOWN                =  0,
+    PSM_INIT           =  1,
+    PSM_PRE            =  2,
+    PSM_PROCESS                =  3,
+    PSM_POST           =  4,
+    PSM_UNDO           =  5,
+    PSM_FINI           =  6,
+
+    PSM_PKGCOMMIT      = 10,
+
+    PSM_CREATE         = 17,
+    PSM_NOTIFY         = 22,
+    PSM_DESTROY                = 23,
+    PSM_COMMIT         = 25,
+
+    PSM_CHROOT_IN      = 51,
+    PSM_CHROOT_OUT     = 52,
+    PSM_SCRIPT         = 53,
+    PSM_TRIGGERS       = 54,
+    PSM_IMMED_TRIGGERS = 55,
+
+    PSM_RPMDB_ADD      = 98,
+    PSM_RPMDB_REMOVE   = 99
+
+} pkgStage;
+
 struct rpmpsm_s {
     rpmts ts;                  /*!< transaction set */
     rpmte te;                  /*!< current transaction element */
@@ -56,6 +81,8 @@ struct rpmpsm_s {
     int nrefs;                 /*!< Reference count. */
 };
 
+static rpmRC rpmpsmStage(rpmpsm psm, pkgStage stage);
+
 /**
  * Macros to be defined from per-header tag values.
  * @todo Should other macros be added from header when installing a package?
@@ -650,16 +677,6 @@ rpmpsm rpmpsmFree(rpmpsm psm)
     return NULL;
 }
 
-rpmRC rpmpsmScriptStage(rpmpsm psm, rpmTag scriptTag)
-{
-    assert(psm != NULL);
-    psm->scriptTag = scriptTag;
-    if (scriptTag == RPMTAG_VERIFYSCRIPT) {
-       psm->goalName = "verify";
-    }
-    return rpmpsmStage(psm, PSM_SCRIPT);
-}
-
 rpmpsm rpmpsmNew(rpmts ts, rpmte te)
 {
     rpmpsm psm = xcalloc(1, sizeof(*psm));
@@ -683,7 +700,7 @@ static int rpmpsmNext(rpmpsm psm, pkgStage nstage)
     return rpmpsmStage(psm, psm->nstage);
 }
 
-rpmRC rpmpsmStage(rpmpsm psm, pkgStage stage)
+static rpmRC rpmpsmStage(rpmpsm psm, pkgStage stage)
 {
     const rpmts ts = psm->ts;
     rpm_color_t tscolor = rpmtsColor(ts);
@@ -1116,7 +1133,10 @@ static const char * pkgGoalString(pkgGoal goal)
     switch(goal) {
     case PKG_INSTALL:  return "  install";
     case PKG_ERASE:    return "    erase";
-    default:           return "???";
+    case PKG_VERIFY:   return "   verify";
+    case PKG_PRETRANS: return " pretrans";
+    case PKG_POSTTRANS:        return "posttrans";
+    default:           return "unknown";
     }
 }
 
@@ -1137,6 +1157,12 @@ rpmRC rpmpsmRun(rpmpsm psm, pkgGoal goal)
            if (!rc) rc = rpmpsmNext(psm, PSM_POST);
            (void) rpmpsmNext(psm, PSM_FINI);
            break;
+       case PKG_PRETRANS:
+       case PKG_POSTTRANS:
+       case PKG_VERIFY:
+           psm->scriptTag = goal;
+           rc = rpmpsmStage(psm, PSM_SCRIPT);
+           break;
        default:
            break;
        }
index 059154d..6e47fac 100644 (file)
--- a/lib/psm.h
+++ b/lib/psm.h
@@ -17,35 +17,12 @@ typedef enum pkgGoal_e {
     /* permit using rpmteType() for install + erase goals */
     PKG_INSTALL                = TR_ADDED,
     PKG_ERASE          = TR_REMOVED,
+    /* permit using scriptname for these for now... */
+    PKG_VERIFY         = RPMTAG_VERIFYSCRIPT,
+    PKG_PRETRANS       = RPMTAG_PRETRANS,
+    PKG_POSTTRANS      = RPMTAG_POSTTRANS,
 } pkgGoal;
 
-typedef enum pkgStage_e {
-    PSM_UNKNOWN                =  0,
-    PSM_INIT           =  1,
-    PSM_PRE            =  2,
-    PSM_PROCESS                =  3,
-    PSM_POST           =  4,
-    PSM_UNDO           =  5,
-    PSM_FINI           =  6,
-
-    PSM_PKGCOMMIT      = 10,
-
-    PSM_CREATE         = 17,
-    PSM_NOTIFY         = 22,
-    PSM_DESTROY                = 23,
-    PSM_COMMIT         = 25,
-
-    PSM_CHROOT_IN      = 51,
-    PSM_CHROOT_OUT     = 52,
-    PSM_SCRIPT         = 53,
-    PSM_TRIGGERS       = 54,
-    PSM_IMMED_TRIGGERS = 55,
-
-    PSM_RPMDB_ADD      = 98,
-    PSM_RPMDB_REMOVE   = 99
-
-} pkgStage;
-
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -86,27 +63,14 @@ rpmpsm rpmpsmFree(rpmpsm psm);
 RPM_GNUC_INTERNAL
 rpmpsm rpmpsmNew(rpmts ts, rpmte te);
 
-RPM_GNUC_INTERNAL
-rpmRC rpmpsmRun(rpmpsm psm, pkgGoal goal);
-
 /**
  * Package state machine driver.
  * @param psm          package state machine data
- * @param stage                next stage
+ * @param goal         state machine goal
  * @return             0 on success
  */
 RPM_GNUC_INTERNAL
-rpmRC rpmpsmStage(rpmpsm psm, pkgStage stage);
-#define        rpmpsmUNSAFE    rpmpsmSTAGE
-
-/**
- * Run rpmpsmStage(PSM_SCRIPT) for scriptTag
- * @param psm          package state machine data
- * @param scriptTag    scriptlet tag to execute
- * @return             0 on success
- */
-RPM_GNUC_INTERNAL
-rpmRC rpmpsmScriptStage(rpmpsm psm, rpmTag scriptTag);
+rpmRC rpmpsmRun(rpmpsm psm, pkgGoal goal);
 
 #ifdef __cplusplus
 }
index e91901a..de4c5c2 100644 (file)
@@ -1197,7 +1197,8 @@ static int runTransScripts(rpmts ts, rpmTag stag)
 
        if (rpmteOpen(p, ts, 0)) {
            psm = rpmpsmNew(ts, p);
-           xx = rpmpsmScriptStage(psm, stag);
+           /* XXX should %pretrans failure fail the package install? */
+           xx = rpmpsmRun(psm, stag);
            psm = rpmpsmFree(psm);
            rpmteClose(p, ts, 0);
        }
index 7758b19..cb5ee54 100644 (file)
@@ -285,8 +285,7 @@ static int rpmVerifyScript(QVA_t qva, rpmts ts, Header h, FD_t scriptFd)
 
     /* create psm to run the script */
     psm = rpmpsmNew(ts, te);
-    rpmpsmScriptStage(psm, RPMTAG_VERIFYSCRIPT);
-    rc = rpmpsmStage(psm, PSM_SCRIPT);
+    rc = rpmpsmRun(psm, PKG_VERIFY);
     psm = rpmpsmFree(psm);
 
     if (scriptFd != NULL)