From eef4ae28bc6b0ba19f8bff33d3f6b58174d7bca9 Mon Sep 17 00:00:00 2001 From: Nir Bar Date: Thu, 2 May 2024 18:13:09 +0300 Subject: [PATCH] Not overwriting log files when retrying to execute a package Creating a new log file with a '_' appended to the previous file name before the extension --- Readme.md | 1 + src/burn/engine/apply.cpp | 6 ++++ src/burn/engine/logging.cpp | 72 +++++++++++++++++++++++++++++++++++++ src/burn/engine/logging.h | 5 +++ 4 files changed, 84 insertions(+) diff --git a/Readme.md b/Readme.md index 5c564d2b4..04aaf4111 100644 --- a/Readme.md +++ b/Readme.md @@ -34,6 +34,7 @@ - wixstdba: Specifying "-forcerestart' on the command line forces reboot at the end of the installation - Changes by WiX up to git commit 376423b8101f4b59ee865e8a255cfe190fa5a7f1 - Build for .NET Framework 4.0 +- Not overwriting log files when retrying to execute a package # WiX Toolset on GitHub The WiX Toolset builds Windows installation packages from XML source code. The toolset supports a command-line environment that developers may integrate into their build processes to build Windows Installer (MSI) packages and executable bundles. The WiX GitHub project hosts the WiX source code Git repositories. The following links will take you to more details: diff --git a/src/burn/engine/apply.cpp b/src/burn/engine/apply.cpp index 84a3c0f66..481c9226e 100644 --- a/src/burn/engine/apply.cpp +++ b/src/burn/engine/apply.cpp @@ -1883,6 +1883,12 @@ static HRESULT DoExecuteAction( do { + if (fRetry) + { + LoggingPromoteLogFile(pExecuteAction, &pEngineState->variables); + fRetry = FALSE; + } + switch (pExecuteAction->type) { case BURN_EXECUTE_ACTION_TYPE_CHECKPOINT: diff --git a/src/burn/engine/logging.cpp b/src/burn/engine/logging.cpp index 86d51ec6a..003eb421d 100644 --- a/src/burn/engine/logging.cpp +++ b/src/burn/engine/logging.cpp @@ -255,6 +255,78 @@ extern "C" HRESULT LoggingSetMsiTransactionVariable( return hr; } +HRESULT LoggingPromoteLogFile( + __in BURN_EXECUTE_ACTION* pExecuteAction, + __in BURN_VARIABLES* pVariables + ) +{ + HRESULT hr = S_OK; + LPWSTR sczLogPath = NULL; + LPWSTR sczNewLogPath = NULL; + LPCWSTR sczLogPathVariable = NULL; + + switch (pExecuteAction->type) + { + case BURN_EXECUTE_ACTION_TYPE_EXE_PACKAGE: + sczLogPathVariable = pExecuteAction->exePackage.pPackage->sczLogPathVariable; + break; + case BURN_EXECUTE_ACTION_TYPE_MSI_PACKAGE: + sczLogPathVariable = pExecuteAction->msiPackage.pPackage->sczLogPathVariable; + break; + case BURN_EXECUTE_ACTION_TYPE_MSP_TARGET: + sczLogPathVariable = pExecuteAction->mspTarget.pPackage->sczLogPathVariable; + break; + case BURN_EXECUTE_ACTION_TYPE_MSU_PACKAGE: + sczLogPathVariable = pExecuteAction->msuPackage.pPackage->sczLogPathVariable; + break; + } + + if (!sczLogPathVariable || !*sczLogPathVariable) + { + hr = S_FALSE; + ExitFunction(); + } + + hr = VariableGetFormatted(pVariables, sczLogPathVariable, &sczLogPath); + if ((hr == E_NOTFOUND) || !sczLogPath || !*sczLogPath) + { + hr = S_FALSE; + ExitFunction(); + } + ExitOnFailure(hr, "Failed to get log path."); + + hr = FileAddSuffixToBaseName(sczLogPath, L"_", &sczNewLogPath); + ExitOnFailure(hr, "Failed to append to log path."); + + hr = VariableSetString(pVariables, sczLogPathVariable, sczNewLogPath, FALSE); + ExitOnFailure(hr, "Failed to set log path into variable."); + + switch (pExecuteAction->type) + { + case BURN_EXECUTE_ACTION_TYPE_MSI_PACKAGE: + ReleaseStr(pExecuteAction->msiPackage.sczLogPath); + pExecuteAction->msiPackage.sczLogPath = sczNewLogPath; + sczNewLogPath = NULL; + break; + case BURN_EXECUTE_ACTION_TYPE_MSP_TARGET: + ReleaseStr(pExecuteAction->mspTarget.sczLogPath); + pExecuteAction->mspTarget.sczLogPath = sczNewLogPath; + sczNewLogPath = NULL; + break; + case BURN_EXECUTE_ACTION_TYPE_MSU_PACKAGE: + ReleaseStr(pExecuteAction->msuPackage.sczLogPath); + pExecuteAction->msuPackage.sczLogPath = sczNewLogPath; + sczNewLogPath = NULL; + break; + } + +LExit: + ReleaseStr(sczLogPath); + ReleaseStr(sczNewLogPath); + + return hr; +} + extern "C" HRESULT LoggingSetPackageVariable( __in BURN_PACKAGE* pPackage, __in_z_opt LPCWSTR wzSuffix, diff --git a/src/burn/engine/logging.h b/src/burn/engine/logging.h index b4500b48d..d5d12035f 100644 --- a/src/burn/engine/logging.h +++ b/src/burn/engine/logging.h @@ -59,6 +59,11 @@ HRESULT LoggingSetMsiTransactionVariable( __in BURN_VARIABLES* pVariables ); +HRESULT LoggingPromoteLogFile( + __in BURN_EXECUTE_ACTION* pExecuteAction, + __in BURN_VARIABLES* pVariables + ); + HRESULT LoggingSetPackageVariable( __in BURN_PACKAGE* pPackage, __in_z_opt LPCWSTR wzSuffix,