From 2275a2ef895e211115fc001d95e8676ecc5c9f40 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Mon, 29 Mar 2010 18:36:21 +0300 Subject: [PATCH] Hide rpmte open/close/error etc logic inside rpmteProcess() - make a bunch of helper functions static now that they're not needed elsewhere, rpmte is slowly becoming self-aware ;) --- lib/rpmte.c | 38 +++++++++++++++++++++++++++++++++----- lib/rpmte_internal.h | 11 +---------- lib/transaction.c | 40 +++++++++++----------------------------- lib/verify.c | 8 +++----- 4 files changed, 48 insertions(+), 49 deletions(-) diff --git a/lib/rpmte.c b/lib/rpmte.c index afdf856..22c8581 100644 --- a/lib/rpmte.c +++ b/lib/rpmte.c @@ -62,7 +62,9 @@ struct rpmte_s { rpmfs fs; }; -static void rpmteColorDS(rpmte te, rpmTag tag); /* forward declaration */ +/* forward declarations */ +static void rpmteColorDS(rpmte te, rpmTag tag); +static int rpmteClose(rpmte te, rpmts ts, int reset_fi); void rpmteCleanDS(rpmte te) { @@ -597,7 +599,7 @@ static Header rpmteFDHeader(rpmts ts, rpmte te) return h; } -int rpmteOpen(rpmte te, rpmts ts, int reload_fi) +static int rpmteOpen(rpmte te, rpmts ts, int reload_fi) { Header h = NULL; unsigned int instance; @@ -628,7 +630,7 @@ exit: return (h != NULL); } -int rpmteClose(rpmte te, rpmts ts, int reset_fi) +static int rpmteClose(rpmte te, rpmts ts, int reset_fi) { if (te == NULL || ts == NULL) return 0; @@ -663,7 +665,7 @@ FD_t rpmtePayload(rpmte te) return payload; } -int rpmteMarkFailed(rpmte te, rpmts ts) +static int rpmteMarkFailed(rpmte te, rpmts ts) { rpmtsi pi = rpmtsiInit(ts); rpmte p; @@ -684,7 +686,7 @@ int rpmteFailed(rpmte te) return (te != NULL) ? te->failed : -1; } -int rpmteHaveTransScript(rpmte te, rpmTag tag) +static int rpmteHaveTransScript(rpmte te, rpmTag tag) { int rc = 0; if (tag == RPMTAG_PRETRANS) { @@ -770,3 +772,29 @@ rpmfs rpmteGetFileStates(rpmte te) { return te->fs; } +int rpmteProcess(rpmte te, rpmts ts, pkgGoal goal) +{ + /* Only install/erase resets pkg file info */ + int scriptstage = (goal != PKG_INSTALL && goal != PKG_ERASE); + int reset_fi = (scriptstage == 0); + int failed = 1; + + /* Dont bother opening for elements without pre/posttrans scripts */ + if (goal == PKG_PRETRANS || goal == PKG_POSTTRANS) { + if (!rpmteHaveTransScript(te, goal)) { + return 0; + } + } + + if (rpmteOpen(te, ts, reset_fi)) { + failed = rpmpsmRun(ts, te, goal); + rpmteClose(te, ts, reset_fi); + } + + /* XXX should %pretrans failure fail the package install? */ + if (failed && !scriptstage) { + failed = rpmteMarkFailed(te, ts); + } + + return failed; +} diff --git a/lib/rpmte_internal.h b/lib/rpmte_internal.h index 38769f0..87f4d5f 100644 --- a/lib/rpmte_internal.h +++ b/lib/rpmte_internal.h @@ -28,19 +28,10 @@ RPM_GNUC_INTERNAL FD_t rpmteSetFd(rpmte te, FD_t fd); RPM_GNUC_INTERNAL -int rpmteOpen(rpmte te, rpmts ts, int reload_fi); - -RPM_GNUC_INTERNAL -int rpmteClose(rpmte te, rpmts ts, int reset_fi); - -RPM_GNUC_INTERNAL FD_t rpmtePayload(rpmte te); RPM_GNUC_INTERNAL -int rpmteMarkFailed(rpmte te, rpmts ts); - -RPM_GNUC_INTERNAL -int rpmteHaveTransScript(rpmte te, rpmTag tag); +int rpmteProcess(rpmte te, rpmts ts, pkgGoal goal); RPM_GNUC_INTERNAL void rpmteAddProblem(rpmte te, rpmProblemType type, diff --git a/lib/transaction.c b/lib/transaction.c index 6813c36..d0686f2 100644 --- a/lib/transaction.c +++ b/lib/transaction.c @@ -1099,32 +1099,18 @@ static rpmps checkProblems(rpmts ts) /* * Run pre/post transaction scripts for transaction set * param ts Transaction set - * param stag RPMTAG_PRETRANS or RPMTAG_POSTTRANS - * return 0 on success, -1 on error (invalid script tag) + * param goal PKG_PRETRANS/PKG_POSTTRANS + * return 0 on success */ -static int runTransScripts(rpmts ts, rpmTag stag) +static int runTransScripts(rpmts ts, pkgGoal goal) { - rpmtsi pi; rpmte p; - int xx; - - if (stag != RPMTAG_PRETRANS && stag != RPMTAG_POSTTRANS) - return -1; - - pi = rpmtsiInit(ts); + rpmtsi pi = rpmtsiInit(ts); while ((p = rpmtsiNext(pi, TR_ADDED)) != NULL) { - /* Skip elements without pre/posttrans */ - if (!rpmteHaveTransScript(p, stag)) - continue; - - if (rpmteOpen(p, ts, 0)) { - /* XXX should %pretrans failure fail the package install? */ - xx = rpmpsmRun(ts, p, stag); - rpmteClose(p, ts, 0); - } + rpmteProcess(p, ts, goal); } pi = rpmtsiFree(pi); - return 0; + return 0; /* what to do about failures? */ } /* Add fingerprint for each file not skipped. */ @@ -1351,19 +1337,15 @@ static int rpmtsProcess(rpmts ts) pi = rpmtsiInit(ts); while ((p = rpmtsiNext(pi, 0)) != NULL) { - int failed = 1; + int failed; rpmlog(RPMLOG_DEBUG, "========== +++ %s %s-%s 0x%x\n", rpmteNEVR(p), rpmteA(p), rpmteO(p), rpmteColor(p)); - if (rpmteOpen(p, ts, 1)) { - failed = rpmpsmRun(ts, p, rpmteType(p)); - rpmteClose(p, ts, 1); - } + failed = rpmteProcess(p, ts, rpmteType(p)); if (failed) { - int fails = rpmteMarkFailed(p, ts); rpmlog(RPMLOG_ERR, "%s: %s %s\n", rpmteNEVRA(p), - rpmteTypeString(p), fails > 1 ? _("skipped") : _("failed")); + rpmteTypeString(p), failed > 1 ? _("skipped") : _("failed")); rc++; } (void) rpmdbSync(rpmtsGetRdb(ts)); @@ -1404,7 +1386,7 @@ int rpmtsRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet) || (rpmpsNumProblems(tsprobs) && (okProbs == NULL || rpmpsTrim(tsprobs, okProbs))))) { rpmlog(RPMLOG_DEBUG, "running pre-transaction scripts\n"); - runTransScripts(ts, RPMTAG_PRETRANS); + runTransScripts(ts, PKG_PRETRANS); } tsprobs = rpmpsFree(tsprobs); @@ -1434,7 +1416,7 @@ int rpmtsRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet) /* Run post-transaction scripts unless disabled */ if (!(rpmtsFlags(ts) & (RPMTRANS_FLAG_TEST|RPMTRANS_FLAG_NOPOST))) { rpmlog(RPMLOG_DEBUG, "running post-transaction scripts\n"); - runTransScripts(ts, RPMTAG_POSTTRANS); + runTransScripts(ts, PKG_POSTTRANS); } /* Finish up... */ diff --git a/lib/verify.c b/lib/verify.c index b3242aa..af63547 100644 --- a/lib/verify.c +++ b/lib/verify.c @@ -22,7 +22,7 @@ #include #include "lib/misc.h" /* uidToUname(), gnameToGid */ -#include "lib/rpmte_internal.h" /* rpmteOpen(), rpmteClose() */ +#include "lib/rpmte_internal.h" /* rpmteProcess() */ #include "debug.h" @@ -272,12 +272,10 @@ static int rpmVerifyScript(QVA_t qva, rpmts ts, Header h) /* fake up a erasure transaction element */ rc = rpmtsAddEraseElement(ts, h, -1); te = rpmtsElement(ts, 0); - rpmteOpen(te, ts, 0); - - rc = rpmpsmRun(ts, te, PKG_VERIFY); + + rc = rpmteProcess(te, ts, PKG_VERIFY); /* clean up our fake transaction bits */ - rpmteClose(te, ts, 0); rpmtsEmpty(ts); return rc; -- 2.7.4