Always remove all dependencies the bundle could have registered.
#6297
Sean Hall committed
Feb 24, 2021 at 17:02 UTC
b5c4d92528dd088d0065c634eb1a353c424a4441
7 files changed
+37
-13
src/engine/apply.cpp
+1
-1
@@ -435,7 +435,7 @@ extern "C" HRESULT ApplyUnregister(
435
}
436
else
437
{
438
- hr = RegistrationSessionEnd(&pEngineState->registration, resumeMode, restart, pEngineState->plan.dependencyRegistrationAction);
438
+ hr = RegistrationSessionEnd(&pEngineState->registration, &pEngineState->packages, resumeMode, restart, pEngineState->plan.dependencyRegistrationAction);
439
ExitOnFailure(hr, "Failed to end session in per-user process.");
440
}
441
src/engine/dependency.cpp
+16
-1
@@ -680,10 +680,12 @@ LExit:
680
}
681
682
extern "C" void DependencyUnregisterBundle(
683
- __in const BURN_REGISTRATION* pRegistration
683
+ __in const BURN_REGISTRATION* pRegistration,
684
+ __in const BURN_PACKAGES* pPackages
685
)
686
{
687
HRESULT hr = S_OK;
688
+ LPCWSTR wzDependentProviderKey = pRegistration->sczId;
689
690
// Remove the bundle provider key.
691
hr = DepUnregisterDependency(pRegistration->hkRoot, pRegistration->sczProviderKey);
@@ -695,6 +697,19 @@ extern "C" void DependencyUnregisterBundle(
697
{
698
LogId(REPORT_VERBOSE, MSG_DEPENDENCY_BUNDLE_UNREGISTERED_FAILED, pRegistration->sczProviderKey, hr);
699
}
700
+
701
+ // Best effort to make sure this bundle is not registered as a dependent for anything.
702
+ for (DWORD i = 0; i < pPackages->cPackages; ++i)
703
+ {
704
+ const BURN_PACKAGE* pPackage = pPackages->rgPackages + i;
705
+ UnregisterPackageDependency(pPackage->fPerMachine, pPackage, wzDependentProviderKey);
706
+ }
707
+
708
+ for (DWORD i = 0; i < pRegistration->relatedBundles.cRelatedBundles; ++i)
709
+ {
710
+ const BURN_PACKAGE* pPackage = &pRegistration->relatedBundles.rgRelatedBundles[i].package;
711
+ UnregisterPackageDependency(pPackage->fPerMachine, pPackage, wzDependentProviderKey);
712
+ }
713
}
714
715
// internal functions
src/engine/dependency.h
+2
-1
@@ -169,7 +169,8 @@ HRESULT DependencyProcessDependentRegistration(
169
Note: Does not check for existing dependents before removing the key.
170
*********************************************************************/
171
void DependencyUnregisterBundle(
172
- __in const BURN_REGISTRATION* pRegistration
172
+ __in const BURN_REGISTRATION* pRegistration,
173
+ __in const BURN_PACKAGES* pPackages
174
);
175
176
#if defined(__cplusplus)
src/engine/elevation.cpp
+4
-2
@@ -154,6 +154,7 @@ static HRESULT OnSessionResume(
154
__in DWORD cbData
155
);
156
static HRESULT OnSessionEnd(
157
+ __in BURN_PACKAGES* pPackages,
158
__in BURN_REGISTRATION* pRegistration,
159
__in BYTE* pbData,
160
__in DWORD cbData
@@ -1637,7 +1638,7 @@ static HRESULT ProcessElevatedChildMessage(
1638
break;
1639
1640
case BURN_ELEVATION_MESSAGE_TYPE_SESSION_END:
1640
- hrResult = OnSessionEnd(pContext->pRegistration, (BYTE*)pMsg->pvData, pMsg->cbData);
1641
+ hrResult = OnSessionEnd(pContext->pPackages, pContext->pRegistration, (BYTE*)pMsg->pvData, pMsg->cbData);
1642
break;
1643
1644
case BURN_ELEVATION_MESSAGE_TYPE_SAVE_STATE:
@@ -1954,6 +1955,7 @@ LExit:
1955
}
1956
1957
static HRESULT OnSessionEnd(
1958
+ __in BURN_PACKAGES* pPackages,
1959
__in BURN_REGISTRATION* pRegistration,
1960
__in BYTE* pbData,
1961
__in DWORD cbData
@@ -1976,7 +1978,7 @@ static HRESULT OnSessionEnd(
1978
ExitOnFailure(hr, "Failed to read dependency registration action.");
1979
1980
// suspend session in per-machine process
1979
- hr = RegistrationSessionEnd(pRegistration, (BURN_RESUME_MODE)dwResumeMode, (BOOTSTRAPPER_APPLY_RESTART)dwRestart, (BURN_DEPENDENCY_REGISTRATION_ACTION)dwDependencyRegistrationAction);
1981
+ hr = RegistrationSessionEnd(pRegistration, pPackages, (BURN_RESUME_MODE)dwResumeMode, (BOOTSTRAPPER_APPLY_RESTART)dwRestart, (BURN_DEPENDENCY_REGISTRATION_ACTION)dwDependencyRegistrationAction);
1982
ExitOnFailure(hr, "Failed to suspend registration session.");
1983
1984
LExit:
src/engine/registration.cpp
+2
-1
@@ -869,6 +869,7 @@ LExit:
869
*******************************************************************/
870
extern "C" HRESULT RegistrationSessionEnd(
871
__in BURN_REGISTRATION* pRegistration,
872
+ __in BURN_PACKAGES* pPackages,
873
__in BURN_RESUME_MODE resumeMode,
874
__in BOOTSTRAPPER_APPLY_RESTART restart,
875
__in BURN_DEPENDENCY_REGISTRATION_ACTION dependencyRegistrationAction
@@ -912,7 +913,7 @@ extern "C" HRESULT RegistrationSessionEnd(
913
BURN_DEPENDENCY_REGISTRATION_ACTION_UNREGISTER == dependencyRegistrationAction)
914
{
915
// Remove the bundle dependency key.
915
- DependencyUnregisterBundle(pRegistration);
916
+ DependencyUnregisterBundle(pRegistration, pPackages);
917
}
918
919
// Delete update registration key.
src/engine/registration.h
+1
@@ -196,6 +196,7 @@ HRESULT RegistrationSessionResume(
196
);
197
HRESULT RegistrationSessionEnd(
198
__in BURN_REGISTRATION* pRegistration,
199
+ __in BURN_PACKAGES* pPackages,
200
__in BURN_RESUME_MODE resumeMode,
201
__in BOOTSTRAPPER_APPLY_RESTART restart,
202
__in BURN_DEPENDENCY_REGISTRATION_ACTION dependencyRegistrationAction
src/test/BurnUnitTest/RegistrationTest.cpp
+11
-7
@@ -71,6 +71,7 @@ namespace Bootstrapper
71
BOOTSTRAPPER_COMMAND command = { };
72
BURN_REGISTRATION registration = { };
73
BURN_LOGGING logging = { };
74
+ BURN_PACKAGES packages = { };
75
String^ cacheDirectory = Path::Combine(Path::Combine(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), gcnew String(L"Package Cache")), gcnew String(L"{D54F896D-1952-43e6-9C67-B5652240618C}"));
76
try
77
{
@@ -121,7 +122,7 @@ namespace Bootstrapper
122
Assert::Equal<String^>(String::Concat(L"\"", Path::Combine(cacheDirectory, gcnew String(L"setup.exe")), L"\" /burn.runonce"), (String^)(Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(L"{D54F896D-1952-43e6-9C67-B5652240618C}"), nullptr)));
123
124
// end session
124
- hr = RegistrationSessionEnd(®istration, BURN_RESUME_MODE_NONE, BOOTSTRAPPER_APPLY_RESTART_NONE, BURN_DEPENDENCY_REGISTRATION_ACTION_UNREGISTER);
125
+ hr = RegistrationSessionEnd(®istration, &packages, BURN_RESUME_MODE_NONE, BOOTSTRAPPER_APPLY_RESTART_NONE, BURN_DEPENDENCY_REGISTRATION_ACTION_UNREGISTER);
126
TestThrowOnFailure(hr, L"Failed to unregister bundle.");
127
128
// verify that registration was removed
@@ -159,6 +160,7 @@ namespace Bootstrapper
160
BOOTSTRAPPER_COMMAND command = { };
161
BURN_REGISTRATION registration = { };
162
BURN_LOGGING logging = { };
163
+ BURN_PACKAGES packages = { };
164
String^ cacheDirectory = Path::Combine(Path::Combine(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), gcnew String(L"Package Cache")), gcnew String(L"{D54F896D-1952-43e6-9C67-B5652240618C}"));
165
try
166
{
@@ -210,7 +212,7 @@ namespace Bootstrapper
212
Assert::Equal<String^>(String::Concat(L"\"", Path::Combine(cacheDirectory, gcnew String(L"setup.exe")), L"\" /burn.runonce"), (String^)Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(L"{D54F896D-1952-43e6-9C67-B5652240618C}"), nullptr));
213
214
// complete registration
213
- hr = RegistrationSessionEnd(®istration, BURN_RESUME_MODE_ARP, BOOTSTRAPPER_APPLY_RESTART_NONE, BURN_DEPENDENCY_REGISTRATION_ACTION_REGISTER);
215
+ hr = RegistrationSessionEnd(®istration, &packages, BURN_RESUME_MODE_ARP, BOOTSTRAPPER_APPLY_RESTART_NONE, BURN_DEPENDENCY_REGISTRATION_ACTION_REGISTER);
216
TestThrowOnFailure(hr, L"Failed to unregister bundle.");
217
218
// verify that registration was updated
@@ -232,7 +234,7 @@ namespace Bootstrapper
234
Assert::Equal<String^>(String::Concat(L"\"", Path::Combine(cacheDirectory, gcnew String(L"setup.exe")), L"\" /burn.runonce"), (String^)Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(L"{D54F896D-1952-43e6-9C67-B5652240618C}"), nullptr));
235
236
// delete registration
235
- hr = RegistrationSessionEnd(®istration, BURN_RESUME_MODE_NONE, BOOTSTRAPPER_APPLY_RESTART_NONE, BURN_DEPENDENCY_REGISTRATION_ACTION_UNREGISTER);
237
+ hr = RegistrationSessionEnd(®istration, &packages, BURN_RESUME_MODE_NONE, BOOTSTRAPPER_APPLY_RESTART_NONE, BURN_DEPENDENCY_REGISTRATION_ACTION_UNREGISTER);
238
TestThrowOnFailure(hr, L"Failed to unregister bundle.");
239
240
// verify that registration was removed
@@ -269,6 +271,7 @@ namespace Bootstrapper
271
BOOTSTRAPPER_COMMAND command = { };
272
BURN_REGISTRATION registration = { };
273
BURN_LOGGING logging = { };
274
+ BURN_PACKAGES packages = { };
275
String^ cacheDirectory = Path::Combine(Path::Combine(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), gcnew String(L"Package Cache")), gcnew String(L"{D54F896D-1952-43e6-9C67-B5652240618C}"));
276
try
277
{
@@ -322,7 +325,7 @@ namespace Bootstrapper
325
Assert::Equal<String^>(String::Concat(L"\"", Path::Combine(cacheDirectory, gcnew String(L"setup.exe")), L"\" /burn.runonce"), (String^)Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(L"{D54F896D-1952-43e6-9C67-B5652240618C}"), nullptr));
326
327
// finish registration
325
- hr = RegistrationSessionEnd(®istration, BURN_RESUME_MODE_ARP, BOOTSTRAPPER_APPLY_RESTART_NONE, BURN_DEPENDENCY_REGISTRATION_ACTION_REGISTER);
328
+ hr = RegistrationSessionEnd(®istration, &packages, BURN_RESUME_MODE_ARP, BOOTSTRAPPER_APPLY_RESTART_NONE, BURN_DEPENDENCY_REGISTRATION_ACTION_REGISTER);
329
TestThrowOnFailure(hr, L"Failed to register bundle.");
330
331
// verify that registration was updated
@@ -355,7 +358,7 @@ namespace Bootstrapper
358
Assert::Equal<String^>(String::Concat(L"\"", Path::Combine(cacheDirectory, gcnew String(L"setup.exe")), L"\" /burn.runonce"), (String^)Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(L"{D54F896D-1952-43e6-9C67-B5652240618C}"), nullptr));
359
360
// delete registration
358
- hr = RegistrationSessionEnd(®istration, BURN_RESUME_MODE_NONE, BOOTSTRAPPER_APPLY_RESTART_NONE, BURN_DEPENDENCY_REGISTRATION_ACTION_UNREGISTER);
361
+ hr = RegistrationSessionEnd(®istration, &packages, BURN_RESUME_MODE_NONE, BOOTSTRAPPER_APPLY_RESTART_NONE, BURN_DEPENDENCY_REGISTRATION_ACTION_UNREGISTER);
362
TestThrowOnFailure(hr, L"Failed to unregister bundle.");
363
364
// verify that registration was removed
@@ -392,6 +395,7 @@ namespace Bootstrapper
395
BOOTSTRAPPER_COMMAND command = { };
396
BURN_REGISTRATION registration = { };
397
BURN_LOGGING logging = { };
398
+ BURN_PACKAGES packages = { };
399
BYTE rgbData[256] = { };
400
BOOTSTRAPPER_RESUME_TYPE resumeType = BOOTSTRAPPER_RESUME_TYPE_NONE;
401
BYTE* pbBuffer = NULL;
@@ -459,7 +463,7 @@ namespace Bootstrapper
463
Assert::Equal((int)BOOTSTRAPPER_RESUME_TYPE_INTERRUPTED, (int)resumeType);
464
465
// suspend session
462
- hr = RegistrationSessionEnd(®istration, BURN_RESUME_MODE_SUSPEND, BOOTSTRAPPER_APPLY_RESTART_NONE, BURN_DEPENDENCY_REGISTRATION_ACTION_REGISTER);
466
+ hr = RegistrationSessionEnd(®istration, &packages, BURN_RESUME_MODE_SUSPEND, BOOTSTRAPPER_APPLY_RESTART_NONE, BURN_DEPENDENCY_REGISTRATION_ACTION_REGISTER);
467
TestThrowOnFailure(hr, L"Failed to suspend session.");
468
469
// verify that run key was removed
@@ -486,7 +490,7 @@ namespace Bootstrapper
490
Assert::NotEqual((Object^)nullptr, Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(L"{D54F896D-1952-43e6-9C67-B5652240618C}"), nullptr));
491
492
// end session
489
- hr = RegistrationSessionEnd(®istration, BURN_RESUME_MODE_NONE, BOOTSTRAPPER_APPLY_RESTART_NONE, BURN_DEPENDENCY_REGISTRATION_ACTION_UNREGISTER);
493
+ hr = RegistrationSessionEnd(®istration, &packages, BURN_RESUME_MODE_NONE, BOOTSTRAPPER_APPLY_RESTART_NONE, BURN_DEPENDENCY_REGISTRATION_ACTION_UNREGISTER);
494
TestThrowOnFailure(hr, L"Failed to unregister bundle.");
495
496
// read resume type after session