Don't bother fetching and storing pre- and posttrans scripts in rpmfi
authorPanu Matilainen <pmatilai@redhat.com>
Wed, 29 Oct 2008 12:34:36 +0000 (14:34 +0200)
committerPanu Matilainen <pmatilai@redhat.com>
Thu, 30 Oct 2008 11:47:40 +0000 (13:47 +0200)
- the psm script machinery requires the full header to do anything at
  all, so the script + scriptprog were only used to check if the package
  *has* such scripts, a single integer will do just fine there thank you

lib/rpmfi.c
lib/rpmfi_internal.h
lib/transaction.c

index c20088c..19eb25a 100644 (file)
@@ -1120,12 +1120,6 @@ rpmfi rpmfiFree(rpmfi fi)
 if (_rpmfi_debug < 0)
 fprintf(stderr, "*** fi %p\t%s[%d]\n", fi, fi->Type, fi->fc);
 
-    /* Free pre- and post-transaction script and interpreter strings. */
-    fi->pretrans = _free(fi->pretrans);
-    fi->pretransprog = _free(fi->pretransprog);
-    fi->posttrans = _free(fi->posttrans);
-    fi->posttransprog = _free(fi->posttransprog);
-
     if (fi->fc > 0) {
        fi->bnl = _free(fi->bnl);
        fi->dnl = _free(fi->dnl);
@@ -1235,11 +1229,13 @@ rpmfi rpmfiNew(const rpmts ts, Header h, rpmTag tagN, rpmfiFlags flags)
     fi->archiveSize = asize ? *asize : 0;
     rpmtdFreeData(&td);
 
-    /* Extract pre- and post-transaction script and interpreter strings. */
-    _hgfi(h, RPMTAG_PRETRANS, &td, defFlags, fi->pretrans);
-    _hgfi(h, RPMTAG_PRETRANSPROG, &td, defFlags, fi->pretransprog);
-    _hgfi(h, RPMTAG_POSTTRANS, &td, defFlags, fi->posttrans);
-    _hgfi(h, RPMTAG_POSTTRANSPROG, &td, defFlags, fi->posttransprog);
+    /* See if we have pre/posttrans scripts. */
+    fi->transscripts |= (headerIsEntry(h, RPMTAG_PRETRANS) &&
+                        headerIsEntry(h, RPMTAG_PRETRANSPROG)) ?
+                       RPMFI_HAVE_PRETRANS : 0;
+    fi->transscripts |= (headerIsEntry(h, RPMTAG_POSTTRANS) &&
+                        headerIsEntry(h, RPMTAG_POSTTRANSPROG)) ?
+                       RPMFI_HAVE_POSTTRANS : 0;
 
     _hgfi(h, RPMTAG_BASENAMES, &td, defFlags, fi->bnl);
     fi->fc = rpmtdCount(&td);
index 4e0180e..b27390b 100644 (file)
@@ -96,10 +96,9 @@ struct rpmfi_s {
     pgpHashAlgo digestalgo;    /*!< File checksum algorithm */
     unsigned char * digests;   /*!< File checksums in binary. */
 
-    char * pretrans;
-    char * pretransprog;
-    char * posttrans;
-    char * posttransprog;
+#define RPMFI_HAVE_PRETRANS    (1 << 0)
+#define RPMFI_HAVE_POSTTRANS   (1 << 1)
+    int transscripts;          /*!< pre/posttrans script existence */
 
     char * fn;                 /*!< File name buffer. */
     size_t fnlen;              /*!< FIle name buffer length. */
index 6da24e9..0bee781 100644 (file)
@@ -751,21 +751,19 @@ static int runTransScripts(rpmts ts, rpmTag stag)
 
     pi = rpmtsiInit(ts);
     while ((p = rpmtsiNext(pi, TR_ADDED)) != NULL) {
-       const char * script = NULL, * scriptprog = NULL;
        rpmTag progtag = RPMTAG_NOT_FOUND;
+       int havescript = 0;
 
        if ((fi = rpmtsiFi(pi)) == NULL)
            continue;   /* XXX can't happen */
        
        switch (stag) {
        case RPMTAG_PRETRANS:
-           script = fi->pretrans;
-           scriptprog = fi->pretransprog;
+           havescript = fi->transscripts & RPMFI_HAVE_PRETRANS;
            progtag = RPMTAG_PRETRANSPROG;
            break;
        case RPMTAG_POSTTRANS:
-           script = fi->posttrans;
-           scriptprog = fi->posttransprog;
+           havescript = fi->transscripts & RPMFI_HAVE_POSTTRANS;
            progtag = RPMTAG_POSTTRANSPROG;
            break;
        default:
@@ -775,7 +773,7 @@ static int runTransScripts(rpmts ts, rpmTag stag)
        }
        
        /* If no pre/post-transaction script, then don't bother. */
-       if (script == NULL && scriptprog == NULL)
+       if (!havescript)
            continue;
 
        p->fd = rpmtsNotify(ts, p, RPMCALLBACK_INST_OPEN_FILE, 0, 0);