Make psm opaque, add minimal methods to cover internal needs
authorPanu Matilainen <pmatilai@redhat.com>
Mon, 17 Dec 2007 12:58:02 +0000 (14:58 +0200)
committerPanu Matilainen <pmatilai@redhat.com>
Mon, 17 Dec 2007 12:58:02 +0000 (14:58 +0200)
lib/psm.c
lib/psm.h
lib/transaction.c
lib/verify.c

index 857b5b8..9e70d11 100644 (file)
--- a/lib/psm.c
+++ b/lib/psm.c
@@ -40,6 +40,42 @@ int _psm_threads = 0;
  */
 extern unsigned int myinstall_instance;
 
+/**
+ */
+struct rpmpsm_s {
+    struct rpmsqElem sq;       /*!< Scriptlet/signal queue element. */
+
+    rpmts ts;                  /*!< transaction set */
+    rpmte te;                  /*!< current transaction element */
+    rpmfi fi;                  /*!< transaction element file info */
+    FD_t cfd;                  /*!< Payload file handle. */
+    FD_t fd;                   /*!< Repackage file handle. */
+    Header oh;                 /*!< Repackage header. */
+    rpmdbMatchIterator mi;
+    const char * stepName;
+    const char * rpmio_flags;
+    const char * failedFile;
+    const char * pkgURL;       /*!< Repackage URL. */
+    const char * pkgfn;                /*!< Repackage file name. */
+    int scriptTag;             /*!< Scriptlet data tag. */
+    int progTag;               /*!< Scriptlet interpreter tag. */
+    int npkgs_installed;       /*!< No. of installed instances. */
+    int scriptArg;             /*!< Scriptlet package arg. */
+    int sense;                 /*!< One of RPMSENSE_TRIGGER{IN,UN,POSTUN}. */
+    int countCorrection;       /*!< 0 if installing, -1 if removing. */
+    int chrootDone;            /*!< Was chroot(2) done by pkgStage? */
+    int unorderedSuccessor;    /*!< Can the PSM be run asynchronously? */
+    rpmCallbackType what;      /*!< Callback type. */
+    unsigned long amount;      /*!< Callback amount. */
+    unsigned long total;       /*!< Callback total. */
+    rpmRC rc;
+    pkgStage goal;
+    pkgStage stage;            /*!< Current psm stage. */
+    pkgStage nstage;           /*!< Next psm stage. */
+
+    int nrefs;                 /*!< Reference count. */
+};
+
 int rpmVersionCompare(Header first, Header second)
 {
     const char * one, * two;
@@ -1219,6 +1255,40 @@ rpmpsm rpmpsmFree(rpmpsm psm)
     return NULL;
 }
 
+void rpmpsmSetAsync(rpmpsm psm, int async)
+{
+    assert(psm != NULL);
+    psm->unorderedSuccessor = async;
+}
+
+rpmRC rpmpsmScriptStage(rpmpsm psm, rpm_tag_t scriptTag, rpm_tag_t progTag)
+{
+    assert(psm != NULL);
+    psm->scriptTag = scriptTag;
+    psm->progTag = progTag;
+    if (scriptTag == RPMTAG_VERIFYSCRIPT) {
+       psm->stepName = "verify";
+    }
+    return rpmpsmStage(psm, PSM_SCRIPT);
+}
+
+rpmfi rpmpsmSetFI(rpmpsm psm, rpmfi fi)
+{
+    assert(psm != NULL);
+    if (psm->fi != NULL) {
+       psm->fi = rpmfiFree(psm->fi);
+    }
+    if (fi != NULL) {
+       psm->fi = rpmfiLink(fi, RPMDBG_M("rpmpsmSetFI"));
+    }
+    return psm->fi;
+}
+
+rpmts rpmpsmGetTs(rpmpsm psm)
+{
+    return (psm ? psm->ts : NULL);
+}
+
 rpmpsm rpmpsmNew(rpmts ts, rpmte te, rpmfi fi)
 {
     rpmpsm psm = xcalloc(1, sizeof(*psm));
index e05cabf..f86ee0e 100644 (file)
--- a/lib/psm.h
+++ b/lib/psm.h
@@ -60,42 +60,6 @@ typedef enum pkgStage_e {
 #undef _fs
 #undef _fd
 
-/**
- */
-struct rpmpsm_s {
-    struct rpmsqElem sq;       /*!< Scriptlet/signal queue element. */
-
-    rpmts ts;                  /*!< transaction set */
-    rpmte te;                  /*!< current transaction element */
-    rpmfi fi;                  /*!< transaction element file info */
-    FD_t cfd;                  /*!< Payload file handle. */
-    FD_t fd;                   /*!< Repackage file handle. */
-    Header oh;                 /*!< Repackage header. */
-    rpmdbMatchIterator mi;
-    const char * stepName;
-    const char * rpmio_flags;
-    const char * failedFile;
-    const char * pkgURL;       /*!< Repackage URL. */
-    const char * pkgfn;                /*!< Repackage file name. */
-    int scriptTag;             /*!< Scriptlet data tag. */
-    int progTag;               /*!< Scriptlet interpreter tag. */
-    int npkgs_installed;       /*!< No. of installed instances. */
-    int scriptArg;             /*!< Scriptlet package arg. */
-    int sense;                 /*!< One of RPMSENSE_TRIGGER{IN,UN,POSTUN}. */
-    int countCorrection;       /*!< 0 if installing, -1 if removing. */
-    int chrootDone;            /*!< Was chroot(2) done by pkgStage? */
-    int unorderedSuccessor;    /*!< Can the PSM be run asynchronously? */
-    rpmCallbackType what;      /*!< Callback type. */
-    unsigned long amount;      /*!< Callback amount. */
-    unsigned long total;       /*!< Callback total. */
-    rpmRC rc;
-    pkgStage goal;
-    pkgStage stage;            /*!< Current psm stage. */
-    pkgStage nstage;           /*!< Next psm stage. */
-
-    int nrefs;                 /*!< Reference count. */
-};
-
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -142,6 +106,30 @@ rpmpsm rpmpsmNew(rpmts ts, rpmte te, rpmfi fi);
 rpmRC rpmpsmStage(rpmpsm psm, pkgStage stage);
 #define        rpmpsmUNSAFE    rpmpsmSTAGE
 
+/**
+ * Run rpmpsmStage(PSM_SCRIPT) for scriptTag and progTag
+ * @param psm          package state machine data
+ * @param scriptTag    scriptlet tag to execute
+ * @param progTag      scriptlet prog tag to execute
+ * @return             0 on success
+ */
+rpmRC rpmpsmScriptStage(rpmpsm psm, rpm_tag_t scriptTag, rpm_tag_t progTag);
+
+/**
+ * @param psm          package state machine data
+ * @param fi           new file info pointer (or NULL to dealloc)
+ * @return             newly set rpmfi pointer
+ */
+rpmfi rpmpsmSetFI(rpmpsm psm, rpmfi fi);
+
+/**
+ * @param psm          package state machine data
+ * @return             psm transaction set pointer
+ */
+rpmts rpmpsmGetTs(rpmpsm psm);
+
+void rpmpsmSetAsync(rpmpsm psm, int async);
+
 #ifdef __cplusplus
 }
 #endif
index 5bbf582..9f400c5 100644 (file)
@@ -1527,9 +1527,7 @@ rpmlog(RPMLOG_DEBUG, _("sanity checking %d elements\n"), rpmtsNElements(ts));
                }
                psm = rpmpsmNew(ts, p, p->fi);
 assert(psm != NULL);
-               psm->scriptTag = RPMTAG_PRETRANS;
-               psm->progTag = RPMTAG_PRETRANSPROG;
-               xx = rpmpsmStage(psm, PSM_SCRIPT);
+               xx = rpmpsmScriptStage(psm, RPMTAG_PRETRANS, RPMTAG_PRETRANSPROG);
                psm = rpmpsmFree(psm);
 
                (void) ts->notify(p->h, RPMCALLBACK_INST_CLOSE_FILE, 0, 0,
@@ -1914,16 +1912,15 @@ assert(psm != NULL);
     /* FIX: fi reload needs work */
     while ((p = rpmtsiNext(pi, 0)) != NULL) {
        rpmalKey pkgKey;
-       int gotfd;
+       int gotfd, async;
 
        gotfd = 0;
        if ((fi = rpmtsiFi(pi)) == NULL)
            continue;   /* XXX can't happen */
        
        psm = rpmpsmNew(ts, p, fi);
-assert(psm != NULL);
-       psm->unorderedSuccessor =
-               (rpmtsiOc(pi) >= rpmtsUnorderedSuccessors(ts, -1) ? 1 : 0);
+       async = (rpmtsiOc(pi) >= rpmtsUnorderedSuccessors(ts, -1) ? 1 : 0);
+       rpmpsmSetAsync(psm, async);
 
        switch (rpmteType(p)) {
        case TR_ADDED:
@@ -1990,7 +1987,7 @@ assert(psm != NULL);
                 * XXX Sludge necessary to tranfer existing fstates/actions
                 * XXX around a recreated file info set.
                 */
-               psm->fi = rpmfiFree(psm->fi);
+               rpmpsmSetFI(psm, NULL);
                {
                    char * fstates = fi->fstates;
                    rpmFileAction * actions = fi->actions;
@@ -2034,7 +2031,7 @@ assert(psm != NULL);
                        p->fi = fi;
                    }
                }
-               psm->fi = rpmfiLink(p->fi, RPMDBG_M("rpmtsRun"));
+               rpmpsmSetFI(psm, p->fi);
 
 /* FIX: psm->fi may be NULL */
                if (rpmpsmStage(psm, PSM_PKGINSTALL)) {
@@ -2237,9 +2234,7 @@ assert(psm != NULL);
                    p->fi->te = p;
                psm = rpmpsmNew(ts, p, p->fi);
 assert(psm != NULL);
-               psm->scriptTag = RPMTAG_POSTTRANS;
-               psm->progTag = RPMTAG_POSTTRANSPROG;
-               xx = rpmpsmStage(psm, PSM_SCRIPT);
+               rpmpsmScriptStage(psm, RPMTAG_POSTTRANS, RPMTAG_POSTTRANSPROG);
                psm = rpmpsmFree(psm);
 
                (void) ts->notify(p->h, RPMCALLBACK_INST_CLOSE_FILE, 0, 0,
index df01858..c0287fc 100644 (file)
@@ -220,15 +220,13 @@ static int rpmVerifyScript(QVA_t qva, rpmts ts,
        return rc;
 
     if (scriptFd != NULL)
-       rpmtsSetScriptFd(psm->ts, scriptFd);
+       rpmtsSetScriptFd(rpmpsmGetTs(psm), scriptFd);
 
-    psm->stepName = "verify";
-    psm->scriptTag = RPMTAG_VERIFYSCRIPT;
-    psm->progTag = RPMTAG_VERIFYSCRIPTPROG;
+    rc = rpmpsmScriptStage(psm, RPMTAG_VERIFYSCRIPT, RPMTAG_VERIFYSCRIPTPROG);
     rc = rpmpsmStage(psm, PSM_SCRIPT);
 
     if (scriptFd != NULL)
-       rpmtsSetScriptFd(psm->ts, NULL);
+       rpmtsSetScriptFd(rpmpsmGetTs(psm), NULL);
 
     psm = rpmpsmFree(psm);