/**
*/
-static rpmRC chkdir (const char * dpath, const char * dname)
+static rpmRC chkdir (const char * dpath, const char * dname)
{
struct stat st;
int rc;
break;
case FSM_PKGERASE:
break;
+ case FSM_PKGSAVE:
+ break;
case FSM_PKGCOMMIT:
break;
case FSM_PKGBUILD:
* When we run scripts, we pass an argument which is the number of
* versions of this package that will be installed when we are finished.
*/
- fi->scriptArg = rpmdbCountPackages(ts->rpmdb, fi->name) + 1;
- if (fi->scriptArg < 1)
+ psm->scriptArg = rpmdbCountPackages(ts->rpmdb, fi->name) + 1;
+ if (psm->scriptArg < 1)
goto exit;
{ rpmdbMatchIterator mi;
rpmMessage(RPMMESS_DEBUG, _("%s: running %s script(s) (if any)\n"),
stepName, "pre-install");
- rc = runInstScript(ts, fi->h, RPMTAG_PREIN, RPMTAG_PREINPROG, fi->scriptArg,
- ts->transFlags & RPMTRANS_FLAG_NOSCRIPTS);
+ psm->scriptTag = RPMTAG_PREIN;
+ psm->progTag = RPMTAG_PREINPROG;
+ rc = runInstScript(psm);
if (rc) {
rpmError(RPMERR_SCRIPT,
_("skipping %s-%s-%s install, %%pre scriptlet failed rc %d\n"),
rpmMessage(RPMMESS_DEBUG, _("%s: running %s script(s) (if any)\n"),
stepName, "post-install");
- rc = runInstScript(ts, fi->h, RPMTAG_POSTIN, RPMTAG_POSTINPROG,
- fi->scriptArg, (ts->transFlags & RPMTRANS_FLAG_NOSCRIPTS));
+ psm->scriptTag = RPMTAG_POSTIN;
+ psm->progTag = RPMTAG_POSTINPROG;
+ rc = runInstScript(psm);
if (rc)
goto exit;
if (!(ts->transFlags & RPMTRANS_FLAG_NOTRIGGERS)) {
/* Run triggers this package sets off */
- if (runTriggers(psm, RPMSENSE_TRIGGERIN, 0))
+ psm->sense = RPMSENSE_TRIGGERIN;
+ psm->countCorrection = 0;
+ rc = runTriggers(psm);
+ if (rc)
goto exit;
/*
* Run triggers in this package which are set off by other packages in
* the database.
*/
- if (runImmedTriggers(psm, RPMSENSE_TRIGGERIN, 0))
+ rc = runImmedTriggers(psm);
+ if (rc)
goto exit;
}
* When we run scripts, we pass an argument which is the number of
* versions of this package that will be installed when we are finished.
*/
- fi->scriptArg = rpmdbCountPackages(ts->rpmdb, fi->name) - 1;
- if (fi->scriptArg < 0) {
+ psm->scriptArg = rpmdbCountPackages(ts->rpmdb, fi->name) - 1;
+ if (psm->scriptArg < 0) {
rc = 1;
goto exit;
}
if (!(ts->transFlags & RPMTRANS_FLAG_NOTRIGGERS)) {
/* run triggers from this package which are keyed on installed
packages */
- rc = runImmedTriggers(psm, RPMSENSE_TRIGGERUN, -1);
+ psm->sense = RPMSENSE_TRIGGERUN;
+ psm->countCorrection = -1;
+ rc = runImmedTriggers(psm);
if (rc) {
rc = 2;
goto exit;
}
/* run triggers which are set off by the removal of this package */
- rc = runTriggers(psm, RPMSENSE_TRIGGERUN, -1);
+ psm->sense = RPMSENSE_TRIGGERUN;
+ psm->countCorrection = -1;
+ rc = runTriggers(psm);
if (rc) {
rc = 1;
goto exit;
rpmMessage(RPMMESS_DEBUG, _("%s: running %s script(s) (if any)\n"),
stepName, "pre-erase");
- rc = runInstScript(ts, fi->h, RPMTAG_PREUN, RPMTAG_PREUNPROG, fi->scriptArg,
- (ts->transFlags & RPMTRANS_FLAG_NOSCRIPTS));
+ psm->scriptTag = RPMTAG_PREUN;
+ psm->progTag = RPMTAG_PREUNPROG;
+ rc = runInstScript(psm);
if (rc) {
rc = 1;
goto exit;
rpmMessage(RPMMESS_DEBUG, _("%s: running %s script(s) (if any)\n"),
stepName, "post-erase");
- rc = runInstScript(ts, fi->h, RPMTAG_POSTUN, RPMTAG_POSTUNPROG,
- fi->scriptArg, (ts->transFlags & RPMTRANS_FLAG_NOSCRIPTS));
+ psm->scriptTag = RPMTAG_POSTUN;
+ psm->progTag = RPMTAG_POSTUNPROG;
+ rc = runInstScript(psm);
/* XXX WTFO? postun failures are not cause for erasure failure. */
if (!(ts->transFlags & RPMTRANS_FLAG_NOTRIGGERS)) {
/* Run postun triggers which are set off by this package's removal. */
- rc = runTriggers(psm, RPMSENSE_TRIGGERPOSTUN, -1);
+ psm->sense = RPMSENSE_TRIGGERPOSTUN;
+ psm->countCorrection = -1;
+ rc = runTriggers(psm);
if (rc) {
rc = 2;
goto exit;
cfd = Fdopen(fdDup(Fileno(fd)), rpmio_flags);
/* XXX failedFile? */
- rc = fsmSetup(fi->fsm, FSM_PKGBUILD, ts, fi, cfd, NULL, NULL);
+ rc = fsmSetup(fi->fsm, FSM_PKGSAVE, ts, fi, cfd, NULL, NULL);
(void) fsmTeardown(fi->fsm);
saveerrno = errno; /* XXX FIXME: Fclose with libio destroys errno */
* /bin/sh will be used. If the interpreter is /bin/sh, then the args from
* the header will be ignored, passing instead arg1 and arg2.
*
- * @param ts transaction set
+ * @param psm package state machine data
* @param h header
* @param sln name of scriptlet section
* @param progArgc no. of args from header
* @param arg2 ditto, but for the target package
* @return 0 on success, 1 on error
*/
-static int runScript(const rpmTransactionSet ts, Header h,
+static int runScript(PSM_t psm, Header h,
const char * sln,
int progArgc, const char ** progArgv,
const char * script, int arg1, int arg2)
{
+ const rpmTransactionSet ts = psm->ts;
+ TFI_t fi = psm->fi;
+ HGE_t hge = fi->hge;
+ HFD_t hfd = fi->hfd;
const char ** argv = NULL;
int argc = 0;
const char ** prefixes = NULL;
int numPrefixes;
+ int_32 ipt;
const char * oldPrefix;
int maxPrefixLength;
int len;
}
headerNVR(h, &n, &v, &r);
- if (headerGetEntry(h, RPMTAG_INSTPREFIXES, NULL, (void **) &prefixes,
- &numPrefixes)) {
+ if (hge(h, RPMTAG_INSTPREFIXES, &ipt, (void **) &prefixes, &numPrefixes)) {
freePrefixes = 1;
- } else if (headerGetEntry(h, RPMTAG_INSTALLPREFIX, NULL,
- (void **) &oldPrefix, NULL))
- {
+ } else if (hge(h, RPMTAG_INSTALLPREFIX, NULL, (void **) &oldPrefix, NULL)) {
prefixes = &oldPrefix;
numPrefixes = 1;
} else {
}
}
- if (freePrefixes) free(prefixes);
+ if (freePrefixes) prefixes = hfd(prefixes, ipt);
Fclose(out); /* XXX dup'd STDOUT_FILENO */
return rc;
}
-int runInstScript(const rpmTransactionSet ts, Header h,
- int scriptTag, int progTag, int arg, int norunScripts)
+int runInstScript(PSM_t psm)
{
+ const rpmTransactionSet ts = psm->ts;
+ TFI_t fi = psm->fi;
+ HGE_t hge = fi->hge;
+ HFD_t hfd = fi->hfd;
void ** programArgv;
int programArgc;
const char ** argv;
- int programType;
- char * script;
+ int_32 ptt, stt;
+ const char * script;
int rc;
- if (norunScripts) return 0;
+ if (ts->transFlags & RPMTRANS_FLAG_NOSCRIPTS)
+ return 0;
- /* headerGetEntry() sets the data pointer to NULL if the entry does
- not exist */
- headerGetEntry(h, progTag, &programType, (void **) &programArgv,
- &programArgc);
- headerGetEntry(h, scriptTag, NULL, (void **) &script, NULL);
+ /*
+ * headerGetEntry() sets the data pointer to NULL if the entry does
+ * not exist.
+ */
+ hge(fi->h, psm->progTag, &ptt, (void **) &programArgv, &programArgc);
+ hge(fi->h, psm->scriptTag, &stt, (void **) &script, NULL);
- if (programArgv && programType == RPM_STRING_TYPE) {
+ if (programArgv && ptt == RPM_STRING_TYPE) {
argv = alloca(sizeof(char *));
*argv = (const char *) programArgv;
} else {
argv = (const char **) programArgv;
}
- rc = runScript(ts, h, tag2sln(scriptTag), programArgc, argv, script,
- arg, -1);
- programArgv = headerFreeData(programArgv, programType);
+ rc = runScript(psm, fi->h, tag2sln(psm->scriptTag), programArgc, argv,
+ script, psm->scriptArg, -1);
+ programArgv = hfd(programArgv, ptt);
+ script = hfd(script, stt);
return rc;
}
/**
- * @param ts transaction set
- * @param sense
+ * @param psm package state machine data
* @param sourceH
* @param triggeredH
- * @param arg1correction
* @param arg2
* @param triggersAlreadyRun
* @return
*/
-static int handleOneTrigger(const rpmTransactionSet ts, int sense,
- Header sourceH, Header triggeredH,
- int arg1correction, int arg2,
- char * triggersAlreadyRun)
+static int handleOneTrigger(PSM_t psm, Header sourceH, Header triggeredH,
+ int arg2, char * triggersAlreadyRun)
{
+ const rpmTransactionSet ts = psm->ts;
+ TFI_t fi = psm->fi;
+ HGE_t hge = fi->hge;
+ HFD_t hfd = fi->hfd;
const char ** triggerNames;
const char ** triggerEVR;
const char ** triggerScripts;
const char ** triggerProgs;
int_32 * triggerFlags;
int_32 * triggerIndices;
+ int_32 tnt, tvt, tft;
const char * triggerPackageName;
const char * sourceName;
int numTriggers;
int i;
int skip;
- if (!headerGetEntry(triggeredH, RPMTAG_TRIGGERNAME, NULL,
- (void **) &triggerNames, &numTriggers)) {
+ if (!hge(triggeredH, RPMTAG_TRIGGERNAME, &tnt,
+ (void **) &triggerNames, &numTriggers))
return 0;
- }
headerNVR(sourceH, &sourceName, NULL, NULL);
- headerGetEntry(triggeredH, RPMTAG_TRIGGERFLAGS, NULL,
- (void **) &triggerFlags, NULL);
- headerGetEntry(triggeredH, RPMTAG_TRIGGERVERSION, NULL,
- (void **) &triggerEVR, NULL);
+ hge(triggeredH, RPMTAG_TRIGGERFLAGS, &tft, (void **) &triggerFlags, NULL);
+ hge(triggeredH, RPMTAG_TRIGGERVERSION, &tvt, (void **) &triggerEVR, NULL);
for (i = 0; i < numTriggers; i++) {
+ int_32 tit, tst, tpt;
- if (!(triggerFlags[i] & sense)) continue;
+ if (!(triggerFlags[i] & psm->sense)) continue;
if (strcmp(triggerNames[i], sourceName)) continue;
/*
triggerEVR[i] + skip, triggerFlags[i]))
continue;
- headerGetEntry(triggeredH, RPMTAG_TRIGGERINDEX, NULL,
+ hge(triggeredH, RPMTAG_TRIGGERINDEX, &tit,
(void **) &triggerIndices, NULL);
- headerGetEntry(triggeredH, RPMTAG_TRIGGERSCRIPTS, NULL,
+ hge(triggeredH, RPMTAG_TRIGGERSCRIPTS, &tst,
(void **) &triggerScripts, NULL);
- headerGetEntry(triggeredH, RPMTAG_TRIGGERSCRIPTPROG, NULL,
+ hge(triggeredH, RPMTAG_TRIGGERSCRIPTPROG, &tpt,
(void **) &triggerProgs, NULL);
headerNVR(triggeredH, &triggerPackageName, NULL, NULL);
{ int arg1;
int index;
- if ((arg1 = rpmdbCountPackages(ts->rpmdb, triggerPackageName)) < 0) {
+ arg1 = rpmdbCountPackages(ts->rpmdb, triggerPackageName);
+ if (arg1 < 0) {
rc = 1; /* XXX W2DO? same as "execution of script failed" */
} else {
- arg1 += arg1correction;
+ arg1 += psm->countCorrection;
index = triggerIndices[i];
if (!triggersAlreadyRun || !triggersAlreadyRun[index]) {
- rc = runScript(ts, triggeredH, "%trigger", 1,
+ rc = runScript(psm, triggeredH, "%trigger", 1,
triggerProgs + index, triggerScripts[index],
arg1, arg2);
if (triggersAlreadyRun) triggersAlreadyRun[index] = 1;
}
}
- free(triggerScripts);
- free(triggerProgs);
+ triggerIndices = hfd(triggerIndices, tit);
+ triggerScripts = hfd(triggerScripts, tst);
+ triggerProgs = hfd(triggerProgs, tpt);
- /* each target/source header pair can only result in a single
- script being run */
+ /*
+ * Each target/source header pair can only result in a single
+ * script being run.
+ */
break;
}
- free(triggerNames);
+ triggerNames = hfd(triggerNames, tnt);
+ triggerFlags = hfd(triggerFlags, tft);
+ triggerEVR = hfd(triggerEVR, tvt);
return rc;
}
-int runTriggers(PSM_t psm, int sense, int countCorrection)
+int runTriggers(PSM_t psm)
{
const rpmTransactionSet ts = psm->ts;
TFI_t fi = psm->fi;
int numPackage;
int rc = 0;
- numPackage = rpmdbCountPackages(ts->rpmdb, fi->name) + countCorrection;
+ numPackage = rpmdbCountPackages(ts->rpmdb, fi->name) + psm->countCorrection;
if (numPackage < 0)
return 1;
{ Header triggeredH;
rpmdbMatchIterator mi;
+ int countCorrection = psm->countCorrection;
+ psm->countCorrection = 0;
mi = rpmdbInitIterator(ts->rpmdb, RPMTAG_TRIGGERNAME, fi->name, 0);
while((triggeredH = rpmdbNextIterator(mi)) != NULL) {
- rc |= handleOneTrigger(ts, sense, fi->h, triggeredH, 0, numPackage,
- NULL);
+ rc |= handleOneTrigger(psm, fi->h, triggeredH, numPackage, NULL);
}
rpmdbFreeIterator(mi);
+ psm->countCorrection = countCorrection;
}
return rc;
}
-int runImmedTriggers(PSM_t psm, int sense, int countCorrection)
+int runImmedTriggers(PSM_t psm)
{
const rpmTransactionSet ts = psm->ts;
TFI_t fi = psm->fi;
+ HGE_t hge = fi->hge;
+ HFD_t hfd = fi->hfd;
const char ** triggerNames;
int numTriggers;
int_32 * triggerIndices;
+ int_32 tnt, tit;
int numTriggerIndices;
char * triggersRun;
int rc = 0;
- if (!headerGetEntry(fi->h, RPMTAG_TRIGGERNAME, NULL,
+ if (!hge(fi->h, RPMTAG_TRIGGERNAME, &tnt,
(void **) &triggerNames, &numTriggers))
return 0;
- headerGetEntry(fi->h, RPMTAG_TRIGGERINDEX, NULL, (void **) &triggerIndices,
+
+ hge(fi->h, RPMTAG_TRIGGERINDEX, &tit, (void **) &triggerIndices,
&numTriggerIndices);
triggersRun = alloca(sizeof(*triggersRun) * numTriggerIndices);
memset(triggersRun, 0, sizeof(*triggersRun) * numTriggerIndices);
for (i = 0; i < numTriggers; i++) {
rpmdbMatchIterator mi;
- const char * name = triggerNames[i];
if (triggersRun[triggerIndices[i]]) continue;
- mi = rpmdbInitIterator(ts->rpmdb, RPMTAG_NAME, name, 0);
+ mi = rpmdbInitIterator(ts->rpmdb, RPMTAG_NAME, triggerNames[i], 0);
while((sourceH = rpmdbNextIterator(mi)) != NULL) {
- rc |= handleOneTrigger(ts, sense, sourceH, fi->h,
- countCorrection, rpmdbGetIteratorCount(mi),
- triggersRun);
+ rc |= handleOneTrigger(psm, sourceH, fi->h,
+ rpmdbGetIteratorCount(mi),
+ triggersRun);
}
rpmdbFreeIterator(mi);
}
}
+ triggerIndices = hfd(triggerNames, tit);
+ triggerNames = hfd(triggerNames, tnt);
return rc;
}