From dbd55be5e707f07eb044c8c7f13c3dfd246148c0 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Mon, 15 Feb 2021 17:36:45 -0600 Subject: Initialize exe package ancestors during CoreInitialize instead of Plan. --- src/engine/core.cpp | 43 +++++++++++++++++++++++++++++++++++--- src/engine/core.h | 3 +++ src/engine/exeengine.cpp | 9 ++++---- src/engine/package.h | 2 +- src/engine/plan.cpp | 29 ++----------------------- src/engine/pseudobundle.cpp | 4 ++-- src/engine/pseudobundle.h | 4 ++-- src/engine/registration.cpp | 1 + src/engine/registration.h | 1 + src/test/BurnUnitTest/PlanTest.cpp | 3 ++- 10 files changed, 58 insertions(+), 41 deletions(-) diff --git a/src/engine/core.cpp b/src/engine/core.cpp index 0ece3f44..b90d4b92 100644 --- a/src/engine/core.cpp +++ b/src/engine/core.cpp @@ -104,9 +104,9 @@ extern "C" HRESULT CoreInitialize( ExitOnFailure(hr, "Failed to parse command line."); LogId(REPORT_STANDARD, MSG_BURN_COMMAND_LINE, sczSanitizedCommandLine ? sczSanitizedCommandLine : L""); - - hr = DependencyInitialize(&pEngineState->registration, pEngineState->sczIgnoreDependencies); - ExitOnFailure(hr, "Failed to initialize dependency data."); + + hr = CoreInitializeConstants(pEngineState); + ExitOnFailure(hr, "Failed to initialize contants."); // Retain whether bundle was initially run elevated. ProcElevated(::GetCurrentProcess(), &fElevated); @@ -173,6 +173,43 @@ LExit: return hr; } +extern "C" HRESULT CoreInitializeConstants( + __in BURN_ENGINE_STATE* pEngineState + ) +{ + HRESULT hr = S_OK; + BURN_REGISTRATION* pRegistration = &pEngineState->registration; + + hr = DependencyInitialize(pRegistration, pEngineState->sczIgnoreDependencies); + ExitOnFailure(hr, "Failed to initialize dependency data."); + + // Support passing Ancestors to embedded burn bundles. + if (pRegistration->sczAncestors && *pRegistration->sczAncestors) + { + hr = StrAllocFormatted(&pRegistration->sczBundlePackageAncestors, L"%ls;%ls", pRegistration->sczAncestors, pRegistration->sczId); + ExitOnFailure(hr, "Failed to copy ancestors and self to bundle package ancestors."); + } + else + { + hr = StrAllocString(&pRegistration->sczBundlePackageAncestors, pRegistration->sczId, 0); + ExitOnFailure(hr, "Failed to copy self to bundle package ancestors."); + } + + for (DWORD i = 0; i < pEngineState->packages.cPackages; ++i) + { + BURN_PACKAGE* pPackage = pEngineState->packages.rgPackages + i; + + if (BURN_PACKAGE_TYPE_EXE == pPackage->type && BURN_EXE_PROTOCOL_TYPE_BURN == pPackage->Exe.protocol) // TODO: Don't assume exePackages with burn protocol are bundles. + { + // Pass along any ancestors and ourself to prevent infinite loops. + pPackage->Exe.wzAncestors = pRegistration->sczBundlePackageAncestors; + } + } + +LExit: + return hr; +} + extern "C" HRESULT CoreSerializeEngineState( __in BURN_ENGINE_STATE* pEngineState, __inout BYTE** ppbBuffer, diff --git a/src/engine/core.h b/src/engine/core.h index f23738c3..d98c7646 100644 --- a/src/engine/core.h +++ b/src/engine/core.h @@ -138,6 +138,9 @@ typedef struct _BURN_ENGINE_STATE HRESULT CoreInitialize( __in BURN_ENGINE_STATE* pEngineState ); +HRESULT CoreInitializeConstants( + __in BURN_ENGINE_STATE* pEngineState + ); HRESULT CoreSerializeEngineState( __in BURN_ENGINE_STATE* pEngineState, __inout BYTE** ppbBuffer, diff --git a/src/engine/exeengine.cpp b/src/engine/exeengine.cpp index 1ca28473..f734edca 100644 --- a/src/engine/exeengine.cpp +++ b/src/engine/exeengine.cpp @@ -105,7 +105,6 @@ extern "C" void ExeEnginePackageUninitialize( ReleaseStr(pPackage->Exe.sczRepairArguments); ReleaseStr(pPackage->Exe.sczUninstallArguments); ReleaseStr(pPackage->Exe.sczIgnoreDependencies); - ReleaseStr(pPackage->Exe.sczAncestors); //ReleaseStr(pPackage->Exe.sczProgressSwitch); ReleaseMem(pPackage->Exe.rgExitCodes); @@ -334,9 +333,9 @@ extern "C" HRESULT ExeEnginePlanAddPackage( ExitOnFailure(hr, "Failed to allocate the list of dependencies to ignore."); } - if (pPackage->Exe.sczAncestors) + if (pPackage->Exe.wzAncestors) { - hr = StrAllocString(&pAction->exePackage.sczAncestors, pPackage->Exe.sczAncestors, 0); + hr = StrAllocString(&pAction->exePackage.sczAncestors, pPackage->Exe.wzAncestors, 0); ExitOnFailure(hr, "Failed to allocate the list of ancestors."); } @@ -359,9 +358,9 @@ extern "C" HRESULT ExeEnginePlanAddPackage( ExitOnFailure(hr, "Failed to allocate the list of dependencies to ignore."); } - if (pPackage->Exe.sczAncestors) + if (pPackage->Exe.wzAncestors) { - hr = StrAllocString(&pAction->exePackage.sczAncestors, pPackage->Exe.sczAncestors, 0); + hr = StrAllocString(&pAction->exePackage.sczAncestors, pPackage->Exe.wzAncestors, 0); ExitOnFailure(hr, "Failed to allocate the list of ancestors."); } diff --git a/src/engine/package.h b/src/engine/package.h index d3225fbc..71aecd95 100644 --- a/src/engine/package.h +++ b/src/engine/package.h @@ -250,7 +250,7 @@ typedef struct _BURN_PACKAGE LPWSTR sczRepairArguments; LPWSTR sczUninstallArguments; LPWSTR sczIgnoreDependencies; - LPWSTR sczAncestors; + LPCWSTR wzAncestors; // points directly into engine state. BOOL fPseudoBundle; diff --git a/src/engine/plan.cpp b/src/engine/plan.cpp index a11d0e78..99c87163 100644 --- a/src/engine/plan.cpp +++ b/src/engine/plan.cpp @@ -475,7 +475,7 @@ LExit: } extern "C" HRESULT PlanPackages( - __in BURN_REGISTRATION* pRegistration, + __in BURN_REGISTRATION* /*pRegistration*/, __in BURN_USER_EXPERIENCE* pUX, __in BURN_PACKAGES* pPackages, __in BURN_PLAN* pPlan, @@ -498,22 +498,6 @@ extern "C" HRESULT PlanPackages( DWORD iPackage = (BOOTSTRAPPER_ACTION_UNINSTALL == pPlan->action) ? pPackages->cPackages - 1 - i : i; BURN_PACKAGE* pPackage = pPackages->rgPackages + iPackage; - // Support passing Ancestors to embedded burn bundles - if (BURN_PACKAGE_TYPE_EXE == pPackage->type && BURN_EXE_PROTOCOL_TYPE_BURN == pPackage->Exe.protocol) - { - // Pass along any ancestors and ourself to prevent infinite loops. - if (pRegistration->sczAncestors && *pRegistration->sczAncestors) - { - hr = StrAllocFormatted(&pPackage->Exe.sczAncestors, L"%ls;%ls", pRegistration->sczAncestors, pRegistration->sczId); - ExitOnFailure(hr, "Failed to copy ancestors and self to related bundle ancestors."); - } - else - { - hr = StrAllocString(&pPackage->Exe.sczAncestors, pRegistration->sczId, 0); - ExitOnFailure(hr, "Failed to copy self to related bundle ancestors."); - } - } - hr = ProcessPackage(fBundlePerMachine, pUX, pPlan, pPackage, pLog, pVariables, display, relationType, wzLayoutDirectory, phSyncpointEvent, &pRollbackBoundary); ExitOnFailure(hr, "Failed to process package."); } @@ -1230,16 +1214,7 @@ extern "C" HRESULT PlanRelatedBundlesBegin( } // Pass along any ancestors and ourself to prevent infinite loops. - if (pRegistration->sczAncestors && *pRegistration->sczAncestors) - { - hr = StrAllocFormatted(&pRelatedBundle->package.Exe.sczAncestors, L"%ls;%ls", pRegistration->sczAncestors, pRegistration->sczId); - ExitOnFailure(hr, "Failed to copy ancestors and self to related bundle ancestors."); - } - else - { - hr = StrAllocString(&pRelatedBundle->package.Exe.sczAncestors, pRegistration->sczId, 0); - ExitOnFailure(hr, "Failed to copy self to related bundle ancestors."); - } + pRelatedBundle->package.Exe.wzAncestors = pRegistration->sczBundlePackageAncestors; hr = PlanDefaultRelatedBundleRequestState(relationType, pRelatedBundle->relationType, pPlan->action, pRegistration->pVersion, pRelatedBundle->pVersion, &pRelatedBundle->package.requested); ExitOnFailure(hr, "Failed to get default request state for related bundle."); diff --git a/src/engine/pseudobundle.cpp b/src/engine/pseudobundle.cpp index 0864be3a..3b05ea0b 100644 --- a/src/engine/pseudobundle.cpp +++ b/src/engine/pseudobundle.cpp @@ -159,8 +159,8 @@ extern "C" HRESULT PseudoBundleInitializePassthrough( __in BURN_PACKAGE* pPassthroughPackage, __in BOOTSTRAPPER_COMMAND* pCommand, __in_z_opt LPCWSTR wzAppendLogPath, - __in_z_opt LPWSTR wzActiveParent, - __in_z_opt LPWSTR wzAncestors, + __in_z_opt LPCWSTR wzActiveParent, + __in_z_opt LPCWSTR wzAncestors, __in BURN_PACKAGE* pPackage ) { diff --git a/src/engine/pseudobundle.h b/src/engine/pseudobundle.h index 4d3d3052..3b8157a0 100644 --- a/src/engine/pseudobundle.h +++ b/src/engine/pseudobundle.h @@ -29,8 +29,8 @@ HRESULT PseudoBundleInitializePassthrough( __in BURN_PACKAGE* pPassthroughPackage, __in BOOTSTRAPPER_COMMAND* pCommand, __in_z_opt LPCWSTR wzAppendLogPath, - __in_z_opt LPWSTR wzActiveParent, - __in_z_opt LPWSTR wzAncestors, + __in_z_opt LPCWSTR wzActiveParent, + __in_z_opt LPCWSTR wzAncestors, __in BURN_PACKAGE* pPackage ); diff --git a/src/engine/registration.cpp b/src/engine/registration.cpp index a2ed2a0d..9c821422 100644 --- a/src/engine/registration.cpp +++ b/src/engine/registration.cpp @@ -396,6 +396,7 @@ extern "C" void RegistrationUninitialize( ReleaseStr(pRegistration->sczDetectedProviderKeyBundleId); ReleaseStr(pRegistration->sczAncestors); + ReleaseStr(pRegistration->sczBundlePackageAncestors); RelatedBundlesUninitialize(&pRegistration->relatedBundles); // clear struct diff --git a/src/engine/registration.h b/src/engine/registration.h index 55d5a4c8..56bcb1f0 100644 --- a/src/engine/registration.h +++ b/src/engine/registration.h @@ -150,6 +150,7 @@ typedef struct _BURN_REGISTRATION LPWSTR sczDetectedProviderKeyBundleId; LPWSTR sczAncestors; + LPWSTR sczBundlePackageAncestors; BOOL fEnabledForwardCompatibleBundle; BURN_PACKAGE forwardCompatibleBundle; diff --git a/src/test/BurnUnitTest/PlanTest.cpp b/src/test/BurnUnitTest/PlanTest.cpp index 81447ca1..42c11968 100644 --- a/src/test/BurnUnitTest/PlanTest.cpp +++ b/src/test/BurnUnitTest/PlanTest.cpp @@ -679,7 +679,8 @@ namespace Bootstrapper ReleaseStr(sczFilePath); } - DependencyInitialize(&pEngineState->registration, NULL); + hr = CoreInitializeConstants(pEngineState); + NativeAssert::Succeeded(hr, "Failed to initialize core constants"); pEngineState->userExperience.pfnBAProc = PlanTestBAProc; } -- cgit v1.2.3-55-g6feb