Initialize plugins much earlier

- Lazily initialize plugins when adding install or erase elements
  to the transaction already. Since this ensures the setup will
  always be performed, there's no need to do this from rpmtsRun()
  anymore, empty transaction would not get that far anyway.
- This will allow adding hooks to the places where package header
  is still available (which is required for various things) and
  in general, before transaction is actually executed.
- The downside here is that adding or removing packages to a transaction
  can now fail due to plugin initialization failure where its not
  easily distinguishable from other errors, but then they can also
  fail due to rpmdb open failure which kinda similar "shouldn't be
  here" issue. The alternative would be initializing the plugins
  in rpmtsCreate() but as that's not actually permitted to fail at
  all, its not an option really.
This commit is contained in:
Panu Matilainen 2013-04-03 16:49:50 +03:00
parent 3420601fb5
commit 51b306686c
3 changed files with 18 additions and 5 deletions

View File

@ -395,6 +395,11 @@ int rpmtsAddInstallElement(rpmts ts, Header h,
int ec = 0;
int oc = tsmem->orderCount;
if (rpmtsSetupTransactionPlugins(ts) == RPMRC_FAIL) {
ec = 1;
goto exit;
}
/* Check for supported payload format if it's a package */
if (key && headerCheckPayloadFormat(h) != RPMRC_OK) {
ec = 1;
@ -462,6 +467,8 @@ exit:
int rpmtsAddEraseElement(rpmts ts, Header h, int dboffset)
{
if (rpmtsSetupTransactionPlugins(ts) == RPMRC_FAIL)
return 1;
return removePackage(ts, h, NULL);
}

View File

@ -92,6 +92,8 @@ rpmal rpmtsCreateAl(rpmts ts, rpmElementTypes types);
RPM_GNUC_INTERNAL
int rpmtsSolve(rpmts ts, rpmds key);
RPM_GNUC_INTERNAL
rpmRC rpmtsSetupTransactionPlugins(rpmts ts);
#ifdef __cplusplus
}
#endif

View File

@ -1415,13 +1415,21 @@ static int rpmtsProcess(rpmts ts)
return rc;
}
static rpmRC rpmtsSetupTransactionPlugins(rpmts ts)
rpmRC rpmtsSetupTransactionPlugins(rpmts ts)
{
rpmRC rc = RPMRC_OK;
char *plugins = NULL, *plugin = NULL;
const char *delims = ",";
rpmPlugins tsplugins;
/*
* Assume allocated equals initialized. There are some oddball cases
* (verification of non-installed package) where this is not true
* currently but that's not a new issue.
*/
if (ts->plugins != NULL)
return RPMRC_OK;
plugins = rpmExpand("%{?__transaction_plugins}", NULL);
if (!plugins || rstreq(plugins, "")) {
goto exit;
@ -1475,10 +1483,6 @@ int rpmtsRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet)
goto exit;
}
if (rpmtsSetupTransactionPlugins(ts) == RPMRC_FAIL) {
goto exit;
}
rpmtsSetupCollections(ts);
/* Check package set for problems */