From 32602bb04be4a01e4b857d2071e07dd4cc2b38d4 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Fri, 1 Apr 2022 19:29:10 -0500 Subject: Use Burn's parent switch with BundlePackages. --- src/burn/engine/bundlepackageengine.cpp | 30 ++++++++++++++++++++++++------ src/burn/engine/elevation.cpp | 8 +++++++- src/burn/engine/plan.cpp | 7 +++++++ src/burn/engine/plan.h | 1 + src/burn/test/BurnUnitTest/PlanTest.cpp | 12 +++++++----- 5 files changed, 46 insertions(+), 12 deletions(-) (limited to 'src/burn') diff --git a/src/burn/engine/bundlepackageengine.cpp b/src/burn/engine/bundlepackageengine.cpp index ef08d417..6336bd27 100644 --- a/src/burn/engine/bundlepackageengine.cpp +++ b/src/burn/engine/bundlepackageengine.cpp @@ -23,6 +23,7 @@ static HRESULT ExecuteBundle( __in BOOTSTRAPPER_ACTION_STATE action, __in BOOTSTRAPPER_RELATION_TYPE relationType, __in BURN_PACKAGE* pPackage, + __in_z_opt LPCWSTR wzParent, __in_z_opt LPCWSTR wzIgnoreDependencies, __in_z_opt LPCWSTR wzAncestors, __in_z_opt LPCWSTR wzEngineWorkingDirectory, @@ -239,7 +240,7 @@ extern "C" void BundlePackageEnginePackageUninitialize( extern "C" HRESULT BundlePackageEngineDetectPackage( __in BURN_PACKAGE* pPackage, - __in BURN_REGISTRATION* /*pRegistration*/, + __in BURN_REGISTRATION* pRegistration, __in BURN_USER_EXPERIENCE* pUserExperience ) { @@ -291,9 +292,8 @@ extern "C" HRESULT BundlePackageEngineDetectPackage( pPackage->installRegistrationState = BOOTSTRAPPER_PACKAGE_STATE_ABSENT < pPackage->currentState ? BURN_PACKAGE_REGISTRATION_STATE_PRESENT : BURN_PACKAGE_REGISTRATION_STATE_ABSENT; } - // TODO: The bundle is registering itself as a dependent when installed as a chain package, which prevents us from uninstalling it. - //hr = DependencyDetectChainPackage(pPackage, pRegistration); - //ExitOnFailure(hr, "Failed to detect dependencies for BUNDLE package."); + hr = DependencyDetectChainPackage(pPackage, pRegistration); + ExitOnFailure(hr, "Failed to detect dependencies for BUNDLE package."); // TODO: uninstalling compatible Bundles like MsiEngine supports? @@ -447,6 +447,9 @@ extern "C" HRESULT BundlePackageEnginePlanAddPackage( pAction->bundlePackage.pPackage = pPackage; pAction->bundlePackage.action = pPackage->rollback; + hr = StrAllocString(&pAction->bundlePackage.sczParent, pPlan->wzBundleId, 0); + ExitOnFailure(hr, "Failed to allocate the parent."); + if (pPackage->Bundle.wzAncestors) { hr = StrAllocString(&pAction->bundlePackage.sczAncestors, pPackage->Bundle.wzAncestors, 0); @@ -475,6 +478,9 @@ extern "C" HRESULT BundlePackageEnginePlanAddPackage( pAction->bundlePackage.pPackage = pPackage; pAction->bundlePackage.action = pPackage->execute; + hr = StrAllocString(&pAction->bundlePackage.sczParent, pPlan->wzBundleId, 0); + ExitOnFailure(hr, "Failed to allocate the parent."); + if (pPackage->Bundle.wzAncestors) { hr = StrAllocString(&pAction->bundlePackage.sczAncestors, pPackage->Bundle.wzAncestors, 0); @@ -597,13 +603,14 @@ extern "C" HRESULT BundlePackageEngineExecutePackage( ) { BOOTSTRAPPER_ACTION_STATE action = pExecuteAction->bundlePackage.action; + LPCWSTR wzParent = pExecuteAction->bundlePackage.sczParent; LPCWSTR wzIgnoreDependencies = pExecuteAction->bundlePackage.sczIgnoreDependencies; LPCWSTR wzAncestors = pExecuteAction->bundlePackage.sczAncestors; LPCWSTR wzEngineWorkingDirectory = pExecuteAction->bundlePackage.sczEngineWorkingDirectory; BOOTSTRAPPER_RELATION_TYPE relationType = BOOTSTRAPPER_RELATION_CHAIN_PACKAGE; BURN_PACKAGE* pPackage = pExecuteAction->bundlePackage.pPackage; - return ExecuteBundle(pCache, pVariables, fRollback, pfnGenericMessageHandler, pvContext, action, relationType, pPackage, wzIgnoreDependencies, wzAncestors, wzEngineWorkingDirectory, pRestart); + return ExecuteBundle(pCache, pVariables, fRollback, pfnGenericMessageHandler, pvContext, action, relationType, pPackage, wzParent, wzIgnoreDependencies, wzAncestors, wzEngineWorkingDirectory, pRestart); } extern "C" HRESULT BundlePackageEngineExecuteRelatedBundle( @@ -617,6 +624,7 @@ extern "C" HRESULT BundlePackageEngineExecuteRelatedBundle( ) { BOOTSTRAPPER_ACTION_STATE action = pExecuteAction->relatedBundle.action; + LPCWSTR wzParent = NULL; LPCWSTR wzIgnoreDependencies = pExecuteAction->relatedBundle.sczIgnoreDependencies; LPCWSTR wzAncestors = pExecuteAction->relatedBundle.sczAncestors; LPCWSTR wzEngineWorkingDirectory = pExecuteAction->relatedBundle.sczEngineWorkingDirectory; @@ -624,7 +632,7 @@ extern "C" HRESULT BundlePackageEngineExecuteRelatedBundle( BOOTSTRAPPER_RELATION_TYPE relationType = ConvertRelationType(pRelatedBundle->planRelationType); BURN_PACKAGE* pPackage = &pRelatedBundle->package; - return ExecuteBundle(pCache, pVariables, fRollback, pfnGenericMessageHandler, pvContext, action, relationType, pPackage, wzIgnoreDependencies, wzAncestors, wzEngineWorkingDirectory, pRestart); + return ExecuteBundle(pCache, pVariables, fRollback, pfnGenericMessageHandler, pvContext, action, relationType, pPackage, wzParent, wzIgnoreDependencies, wzAncestors, wzEngineWorkingDirectory, pRestart); } extern "C" void BundlePackageEngineUpdateInstallRegistrationState( @@ -721,6 +729,7 @@ static HRESULT ExecuteBundle( __in BOOTSTRAPPER_ACTION_STATE action, __in BOOTSTRAPPER_RELATION_TYPE relationType, __in BURN_PACKAGE* pPackage, + __in_z_opt LPCWSTR wzParent, __in_z_opt LPCWSTR wzIgnoreDependencies, __in_z_opt LPCWSTR wzAncestors, __in_z_opt LPCWSTR wzEngineWorkingDirectory, @@ -848,6 +857,15 @@ static HRESULT ExecuteBundle( ExitOnFailure(hr, "Failed to append relation type argument."); } + if (wzParent) + { + hr = StrAllocConcatFormatted(&sczBaseCommand, L" -%ls", BURN_COMMANDLINE_SWITCH_PARENT); + ExitOnFailure(hr, "Failed to append the parent switch to the command line."); + + hr = AppAppendCommandLineArgument(&sczBaseCommand, wzParent); + ExitOnFailure(hr, "Failed to append the parent to the command line."); + } + // Add the list of dependencies to ignore, if any, to the burn command line. if (BOOTSTRAPPER_RELATION_CHAIN_PACKAGE == relationType) { diff --git a/src/burn/engine/elevation.cpp b/src/burn/engine/elevation.cpp index 504ddaea..56a62955 100644 --- a/src/burn/engine/elevation.cpp +++ b/src/burn/engine/elevation.cpp @@ -949,6 +949,9 @@ extern "C" HRESULT ElevationExecuteBundlePackage( hr = BuffWriteNumber(&pbData, &cbData, fRollback); ExitOnFailure(hr, "Failed to write rollback."); + hr = BuffWriteString(&pbData, &cbData, pExecuteAction->bundlePackage.sczParent); + ExitOnFailure(hr, "Failed to write the parent to the message buffer."); + hr = BuffWriteString(&pbData, &cbData, pExecuteAction->bundlePackage.sczIgnoreDependencies); ExitOnFailure(hr, "Failed to write the list of dependencies to ignore to the message buffer."); @@ -2929,7 +2932,7 @@ static HRESULT OnExecuteBundlePackage( // Deserialize message data. hr = BuffReadString(pbData, cbData, &iData, &sczPackage); - ExitOnFailure(hr, "Failed to read EXE package id."); + ExitOnFailure(hr, "Failed to read BUNDLE package id."); hr = BuffReadNumber(pbData, cbData, &iData, (DWORD*)&executeAction.bundlePackage.action); ExitOnFailure(hr, "Failed to read action."); @@ -2937,6 +2940,9 @@ static HRESULT OnExecuteBundlePackage( hr = BuffReadNumber(pbData, cbData, &iData, &dwRollback); ExitOnFailure(hr, "Failed to read rollback."); + hr = BuffReadString(pbData, cbData, &iData, &executeAction.bundlePackage.sczParent); + ExitOnFailure(hr, "Failed to read the parent."); + hr = BuffReadString(pbData, cbData, &iData, &sczIgnoreDependencies); ExitOnFailure(hr, "Failed to read the list of dependencies to ignore."); diff --git a/src/burn/engine/plan.cpp b/src/burn/engine/plan.cpp index 1d008dba..183ac62a 100644 --- a/src/burn/engine/plan.cpp +++ b/src/burn/engine/plan.cpp @@ -291,6 +291,13 @@ extern "C" void PlanUninitializeExecuteAction( ReleaseStr(pExecuteAction->relatedBundle.sczEngineWorkingDirectory); break; + case BURN_EXECUTE_ACTION_TYPE_BUNDLE_PACKAGE: + ReleaseStr(pExecuteAction->bundlePackage.sczParent); + ReleaseStr(pExecuteAction->bundlePackage.sczIgnoreDependencies); + ReleaseStr(pExecuteAction->bundlePackage.sczAncestors); + ReleaseStr(pExecuteAction->bundlePackage.sczEngineWorkingDirectory); + break; + case BURN_EXECUTE_ACTION_TYPE_EXE_PACKAGE: ReleaseStr(pExecuteAction->exePackage.sczAncestors); ReleaseStr(pExecuteAction->exePackage.sczEngineWorkingDirectory); diff --git a/src/burn/engine/plan.h b/src/burn/engine/plan.h index 5b6ee0fb..a8b16705 100644 --- a/src/burn/engine/plan.h +++ b/src/burn/engine/plan.h @@ -165,6 +165,7 @@ typedef struct _BURN_EXECUTE_ACTION { BURN_PACKAGE* pPackage; BOOTSTRAPPER_ACTION_STATE action; + LPWSTR sczParent; LPWSTR sczIgnoreDependencies; LPWSTR sczAncestors; LPWSTR sczEngineWorkingDirectory; diff --git a/src/burn/test/BurnUnitTest/PlanTest.cpp b/src/burn/test/BurnUnitTest/PlanTest.cpp index 536e5351..fcba0f1a 100644 --- a/src/burn/test/BurnUnitTest/PlanTest.cpp +++ b/src/burn/test/BurnUnitTest/PlanTest.cpp @@ -399,7 +399,7 @@ namespace Bootstrapper ValidateExecuteCheckpoint(pPlan, fRollback, dwIndex++, dwExecuteCheckpointId++); ValidateExecuteWaitCachePackage(pPlan, fRollback, dwIndex++, L"PackageA"); ValidateExecuteCheckpoint(pPlan, fRollback, dwIndex++, dwExecuteCheckpointId++); - ValidateExecuteBundlePackage(pPlan, fRollback, dwIndex++, L"PackageA", BOOTSTRAPPER_ACTION_STATE_INSTALL); + ValidateExecuteBundlePackage(pPlan, fRollback, dwIndex++, L"PackageA", BOOTSTRAPPER_ACTION_STATE_INSTALL, L"{35192ED0-C70A-49B2-9D12-3B1FA39B5E6F}"); ValidateExecuteCheckpoint(pPlan, fRollback, dwIndex++, dwExecuteCheckpointId++); ValidateExecutePackageDependency(pPlan, fRollback, dwIndex++, L"PackageA", L"{35192ED0-C70A-49B2-9D12-3B1FA39B5E6F}", registerActions1, 1); ValidateExecuteCheckpoint(pPlan, fRollback, dwIndex++, dwExecuteCheckpointId++); @@ -407,7 +407,7 @@ namespace Bootstrapper ValidateExecuteCheckpoint(pPlan, fRollback, dwIndex++, dwExecuteCheckpointId++); ValidateExecuteWaitCachePackage(pPlan, fRollback, dwIndex++, L"PackageB"); ValidateExecuteCheckpoint(pPlan, fRollback, dwIndex++, dwExecuteCheckpointId++); - ValidateExecuteBundlePackage(pPlan, fRollback, dwIndex++, L"PackageB", BOOTSTRAPPER_ACTION_STATE_INSTALL); + ValidateExecuteBundlePackage(pPlan, fRollback, dwIndex++, L"PackageB", BOOTSTRAPPER_ACTION_STATE_INSTALL, L"{35192ED0-C70A-49B2-9D12-3B1FA39B5E6F}"); ValidateExecuteCheckpoint(pPlan, fRollback, dwIndex++, dwExecuteCheckpointId++); ValidateExecutePackageDependency(pPlan, fRollback, dwIndex++, L"PackageB", L"{35192ED0-C70A-49B2-9D12-3B1FA39B5E6F}", registerActions1, 1); ValidateExecuteCheckpoint(pPlan, fRollback, dwIndex++, dwExecuteCheckpointId++); @@ -420,14 +420,14 @@ namespace Bootstrapper dwExecuteCheckpointId = 2; ValidateExecuteRollbackBoundaryStart(pPlan, fRollback, dwIndex++, L"WixDefaultBoundary", TRUE, FALSE); ValidateExecuteCheckpoint(pPlan, fRollback, dwIndex++, dwExecuteCheckpointId++); - ValidateExecuteBundlePackage(pPlan, fRollback, dwIndex++, L"PackageA", BOOTSTRAPPER_ACTION_STATE_UNINSTALL); + ValidateExecuteBundlePackage(pPlan, fRollback, dwIndex++, L"PackageA", BOOTSTRAPPER_ACTION_STATE_UNINSTALL, L"{35192ED0-C70A-49B2-9D12-3B1FA39B5E6F}"); ValidateExecuteCheckpoint(pPlan, fRollback, dwIndex++, dwExecuteCheckpointId++); ValidateExecutePackageDependency(pPlan, fRollback, dwIndex++, L"PackageA", L"{35192ED0-C70A-49B2-9D12-3B1FA39B5E6F}", unregisterActions1, 1); ValidateExecuteCheckpoint(pPlan, fRollback, dwIndex++, dwExecuteCheckpointId++); ValidateExecuteCheckpoint(pPlan, fRollback, dwIndex++, dwExecuteCheckpointId++); dwExecuteCheckpointId += 1; // cache checkpoints ValidateExecuteCheckpoint(pPlan, fRollback, dwIndex++, dwExecuteCheckpointId++); - ValidateExecuteBundlePackage(pPlan, fRollback, dwIndex++, L"PackageB", BOOTSTRAPPER_ACTION_STATE_UNINSTALL); + ValidateExecuteBundlePackage(pPlan, fRollback, dwIndex++, L"PackageB", BOOTSTRAPPER_ACTION_STATE_UNINSTALL, L"{35192ED0-C70A-49B2-9D12-3B1FA39B5E6F}"); ValidateExecuteCheckpoint(pPlan, fRollback, dwIndex++, dwExecuteCheckpointId++); ValidateExecutePackageDependency(pPlan, fRollback, dwIndex++, L"PackageB", L"{35192ED0-C70A-49B2-9D12-3B1FA39B5E6F}", unregisterActions1, 1); ValidateExecuteCheckpoint(pPlan, fRollback, dwIndex++, dwExecuteCheckpointId++); @@ -2799,13 +2799,15 @@ namespace Bootstrapper __in BOOL fRollback, __in DWORD dwIndex, __in LPCWSTR wzPackageId, - __in BOOTSTRAPPER_ACTION_STATE action + __in BOOTSTRAPPER_ACTION_STATE action, + __in LPCWSTR wzParent ) { BURN_EXECUTE_ACTION* pAction = ValidateExecuteActionExists(pPlan, fRollback, dwIndex); Assert::Equal(BURN_EXECUTE_ACTION_TYPE_BUNDLE_PACKAGE, pAction->type); NativeAssert::StringEqual(wzPackageId, pAction->bundlePackage.pPackage->sczId); Assert::Equal(action, pAction->bundlePackage.action); + NativeAssert::StringEqual(wzParent, pAction->bundlePackage.sczParent); Assert::Equal(FALSE, pAction->fDeleted); } -- cgit v1.2.3-55-g6feb