diff --git a/src/txnupd.cpp b/src/txnupd.cpp index dacf41a..a6da1db 100644 --- a/src/txnupd.cpp +++ b/src/txnupd.cpp @@ -14,6 +14,7 @@ */ // Standard library includes +#include #include #include @@ -41,6 +42,7 @@ struct _PluginHandle { PluginMode mode; DnfContext * context; // store plugin context specific init data bool transactional_update; // flag to determine if doing a transactional update + bool ext_transactional_update; // flag to determine if within an existing transactional update TransactionalUpdate::Transaction transaction{}; // transactional update object }; @@ -67,6 +69,7 @@ PluginHandle * pluginInitHandle(int version, PluginMode mode, DnfPluginInitData handle->mode = mode; handle->context = pluginGetContext(initData); handle->transactional_update = false; + handle->ext_transactional_update = (std::getenv("TRANSACTIONAL_UPDATE") != NULL); return handle; } @@ -112,6 +115,26 @@ static bool setupTransactionalUpdate(PluginHandle * handle) { return true; } + /* Disable SWDB when in transactional update mode, as it + * it currently causes crashes with transactional updates, + * and it is not particularly useful for our case anyway. + */ + if ((handle->transactional_update) || (handle->ext_transactional_update)) { + dnf_context_set_write_history(handle->context, FALSE); + } + + /* Check if we're already in a transactional update, possibly + * externally invoked by tukit or some other consumer of tukit. + * In this scenario, bail early to stop us from attempting to + * create a transactional update inside of one in progress. + */ + if (handle->ext_transactional_update) { + auto txnupdsnap_msg = std::string(info.name) + ": " + __func__ + + ": Warning: running within transactional update, disabling snapshot handling!"; + logger->warning(txnupdsnap_msg); + return true; + } + /* Now that we've gotten the basic early-bail conditions handled, * let's set up the transaction object to configure transactional * updates. @@ -134,11 +157,6 @@ static bool setupTransactionalUpdate(PluginHandle * handle) { auto transactionRoot = handle->transaction.getRoot(); dnf_context_set_install_root(handle->context, transactionRoot.c_str()); - /* Disable SWDB as it currently causes crashes with transactional updates, - * and it is not particularly useful for our case anyway. - */ - dnf_context_set_write_history(handle->context, FALSE); - /* Mark as being in the transactional update mode, so that * other functions using the handle can do the right thing later. */ @@ -158,6 +176,16 @@ static bool setupTransactionalUpdate(PluginHandle * handle) { static bool configureTransactionContext(PluginHandle * handle) { auto logger(libdnf::Log::getLogger()); + /* Check to see if we are actually in transactional update mode, + * and bail out early if we are not. + */ + if ((!(handle->transactional_update)) && (!(handle->ext_transactional_update))) { + auto txnupd_msg = + std::string(info.name) + ": " + __func__ + ": Warning: Not a transactional update, so doing nothing!"; + logger->warning(txnupd_msg); + return true; + } + /* Set installonlypkgs to nothing to disable multiversioned kernel installation, * as we need it disabled for this type of transaction. */