From ee59836299c5e1c293b64a826552cbfba5dcec12 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Fri, 14 Nov 2008 13:05:41 +0200 Subject: [PATCH] Move open + close of files during install to separate functions - internal rpmteOpen() and rpmteClose() functions replacing copy-paste slop between rpmtsRun() and runTransScripts() - eliminates bunch of rpmte privacy violations - rpmtsRun() doesn't need the file descriptor for anything, might as well keep it hidden --- lib/rpmte.c | 43 +++++++++++++++++++++++++ lib/rpmte_internal.h | 6 ++++ lib/transaction.c | 77 ++++---------------------------------------- 3 files changed, 55 insertions(+), 71 deletions(-) diff --git a/lib/rpmte.c b/lib/rpmte.c index 8c885e226..9227c451f 100644 --- a/lib/rpmte.c +++ b/lib/rpmte.c @@ -606,3 +606,46 @@ rpmte rpmtsiNext(rpmtsi tsi, rpmElementType type) } return te; } + +int rpmteOpen(rpmte te, rpmts ts) +{ + int rc = 0; + if (te == NULL || ts == NULL) + goto exit; + + te->h = NULL; + te->fd = rpmtsNotify(ts, te, RPMCALLBACK_INST_OPEN_FILE, 0, 0); + if (te->fd != NULL) { + rpmVSFlags ovsflags; + rpmRC pkgrc; + + ovsflags = rpmtsSetVSFlags(ts, rpmtsVSFlags(ts) | RPMVSF_NEEDPAYLOAD); + pkgrc = rpmReadPackageFile(ts, rpmteFd(te), rpmteNEVRA(te), &te->h); + rpmtsSetVSFlags(ts, ovsflags); + switch (pkgrc) { + default: + rpmteClose(te, ts); + break; + case RPMRC_NOTTRUSTED: + case RPMRC_NOKEY: + case RPMRC_OK: + rc = 1; + break; + } + } + +exit: + return rc; +} + +int rpmteClose(rpmte te, rpmts ts) +{ + int rc = 0; + if (te != NULL && ts != NULL) { + rpmtsNotify(ts, te, RPMCALLBACK_INST_CLOSE_FILE, 0, 0); + te->fd = NULL; + te->h = headerFree(te->h); + rc = 1; + } + return rc; +} diff --git a/lib/rpmte_internal.h b/lib/rpmte_internal.h index fc228744e..7b3593800 100644 --- a/lib/rpmte_internal.h +++ b/lib/rpmte_internal.h @@ -75,5 +75,11 @@ struct rpmtsi_s { int oc; /*!< iterator index. */ }; +RPM_GNUC_INTERNAL +int rpmteOpen(rpmte te, rpmts ts); + +RPM_GNUC_INTERNAL +int rpmteClose(rpmte te, rpmts ts); + #endif /* _RPMTE_INTERNAL_H */ diff --git a/lib/transaction.c b/lib/transaction.c index 635acb01b..d904ccc00 100644 --- a/lib/transaction.c +++ b/lib/transaction.c @@ -755,30 +755,7 @@ static int runTransScripts(rpmts ts, rpmTag stag) if (!havescript) continue; - p->fd = rpmtsNotify(ts, p, RPMCALLBACK_INST_OPEN_FILE, 0, 0); - p->h = NULL; - if (rpmteFd(p) != NULL) { - rpmVSFlags ovsflags = rpmtsVSFlags(ts); - rpmVSFlags vsflags = ovsflags | RPMVSF_NEEDPAYLOAD; - rpmRC rpmrc; - ovsflags = rpmtsSetVSFlags(ts, vsflags); - rpmrc = rpmReadPackageFile(ts, rpmteFd(p), - rpmteNEVR(p), &p->h); - vsflags = rpmtsSetVSFlags(ts, ovsflags); - switch (rpmrc) { - default: - /* FIX: notify annotations */ - p->fd = rpmtsNotify(ts, p, RPMCALLBACK_INST_CLOSE_FILE, 0, 0); - p->fd = NULL; - break; - case RPMRC_NOTTRUSTED: - case RPMRC_NOKEY: - case RPMRC_OK: - break; - } - } - - if (rpmteFd(p) != NULL) { + if (rpmteOpen(p, ts)) { p->fi = rpmfiFree(p->fi); fi = rpmfiNew(ts, p->h, RPMTAG_BASENAMES, RPMFI_KEEPHEADER); if (fi != NULL) { /* XXX can't happen */ @@ -791,13 +768,10 @@ static int runTransScripts(rpmts ts, rpmTag stag) } } psm = rpmpsmNew(ts, p, p->fi); - assert(psm != NULL); xx = rpmpsmScriptStage(psm, stag, progtag); psm = rpmpsmFree(psm); - (void) rpmtsNotify(ts, p, RPMCALLBACK_INST_CLOSE_FILE, 0, 0); - p->fd = NULL; - p->h = headerFree(p->h); + rpmteClose(p, ts); } } pi = rpmtsiFree(pi); @@ -1271,9 +1245,8 @@ int rpmtsRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet) /* FIX: fi reload needs work */ while ((p = rpmtsiNext(pi, 0)) != NULL) { rpmalKey pkgKey; - int gotfd, async; + int async; - gotfd = 0; if ((fi = rpmtsiFi(pi)) == NULL) continue; /* XXX can't happen */ @@ -1290,38 +1263,8 @@ int rpmtsRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet) rpmlog(RPMLOG_DEBUG, "========== +++ %s %s-%s 0x%x\n", rpmteNEVR(p), rpmteA(p), rpmteO(p), rpmteColor(p)); - p->h = NULL; - /* FIX: rpmte not opaque */ - { - p->fd = rpmtsNotify(ts, p, RPMCALLBACK_INST_OPEN_FILE, 0, 0); - if (rpmteFd(p) != NULL) { - rpmVSFlags ovsflags = rpmtsVSFlags(ts); - rpmVSFlags vsflags = ovsflags | RPMVSF_NEEDPAYLOAD; - rpmRC rpmrc; - - ovsflags = rpmtsSetVSFlags(ts, vsflags); - rpmrc = rpmReadPackageFile(ts, rpmteFd(p), - rpmteNEVR(p), &p->h); - vsflags = rpmtsSetVSFlags(ts, ovsflags); - - switch (rpmrc) { - default: - /* FIX: notify annotations */ - p->fd = rpmtsNotify(ts, p, RPMCALLBACK_INST_CLOSE_FILE, - 0, 0); - p->fd = NULL; - ourrc++; - break; - case RPMRC_NOTTRUSTED: - case RPMRC_NOKEY: - case RPMRC_OK: - break; - } - if (rpmteFd(p) != NULL) gotfd = 1; - } - } - - if (rpmteFd(p) != NULL) { + + if (rpmteOpen(p, ts)) { /* * XXX Sludge necessary to tranfer existing fstates/actions * XXX around a recreated file info set. @@ -1374,20 +1317,12 @@ int rpmtsRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet) ourrc++; lastFailKey = pkgKey; } + rpmteClose(p, ts); } else { ourrc++; lastFailKey = pkgKey; } - - if (gotfd) { - /* FIX: check rc */ - (void) rpmtsNotify(ts, p, RPMCALLBACK_INST_CLOSE_FILE, 0, 0); - p->fd = NULL; - } - - p->h = headerFree(p->h); - (void) rpmswExit(rpmtsOp(ts, RPMTS_OP_INSTALL), 0); break;