Skip to content

Commit b4da272

Browse files
committed
Set more detect-phase values when falling back.
When configurable-scope bundle is already installed, find it during detect by falling back from machine to user. Set the scope as early as possible so detect-phase checks (e.g., cache path, state file) work as expected. Fixes wixtoolset/issues#9257
1 parent dd82774 commit b4da272

File tree

6 files changed

+45
-18
lines changed

6 files changed

+45
-18
lines changed

src/burn/engine/apply.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,8 +536,6 @@ extern "C" HRESULT ApplyUnregister(
536536
IgnoreRollbackError(hrRegistrationRollback, "Dependent registration actions failed");
537537
}
538538

539-
LogId(REPORT_STANDARD, MSG_SESSION_END, pEngineState->registration.sczRegistrationKey, LoggingInstallScopeToString(pEngineState->registration.fPerMachine), LoggingResumeModeToString(resumeMode), LoggingRestartToString(restart), LoggingBoolToString(pEngineState->registration.fDisableResume), LoggingRegistrationTypeToString(defaultRegistrationType), LoggingRegistrationTypeToString(registrationType));
540-
541539
if (BOOTSTRAPPER_ACTION_UNSAFE_UNINSTALL == pEngineState->plan.action)
542540
{
543541
registrationType = BOOTSTRAPPER_REGISTRATION_TYPE_NONE;
@@ -546,6 +544,8 @@ extern "C" HRESULT ApplyUnregister(
546544
LogId(REPORT_STANDARD, MSG_UNSAFE_SESSION_END);
547545
}
548546

547+
LogId(REPORT_STANDARD, MSG_SESSION_END, pEngineState->registration.sczRegistrationKey, LoggingInstallScopeToString(pEngineState->registration.fPerMachine), LoggingResumeModeToString(resumeMode), LoggingRestartToString(restart), LoggingBoolToString(pEngineState->registration.fDisableResume), LoggingRegistrationTypeToString(defaultRegistrationType), LoggingRegistrationTypeToString(registrationType));
548+
549549
if (pEngineState->registration.fPerMachine)
550550
{
551551
hr = ElevationSessionEnd(pEngineState->companionConnection.hPipe, resumeMode, restart, pEngineState->registration.fDetectedForeignProviderKeyBundleCode, qwEstimatedSize, registrationType);

src/burn/engine/core.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ extern "C" HRESULT CoreQueryRegistration(
256256
SIZE_T cbBuffer = 0;
257257
SIZE_T iBuffer = 0;
258258

259+
// Detect if bundle is already installed.
260+
hr = RegistrationDetectInstalled(&pEngineState->registration, &pEngineState->cache);
261+
ExitOnFailure(hr, "Failed to detect bundle install state.");
262+
259263
// detect resume type
260264
hr = RegistrationDetectResumeType(&pEngineState->registration, &pEngineState->command.resumeType);
261265
ExitOnFailure(hr, "Failed to detect resume type.");
@@ -2280,6 +2284,7 @@ static HRESULT DetectPackagePayloadsCached(
22802284
LExit:
22812285
ReleaseStr(sczPayloadCachePath);
22822286
ReleaseStr(sczCachePath);
2287+
22832288
return hr;
22842289
}
22852290

src/burn/engine/engine.mc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ MessageId=371
10551055
Severity=Success
10561056
SymbolicName=MSG_SESSION_UPDATE
10571057
Language=English
1058-
Updating session, registration key: %1!ls!, scope: %2!hs!, resume: %3!hs!, restart initiated: %4!hs!, disable resume: %5!hs!
1058+
Updating session, registration key: %1!ls!, scope: %2!hs!, resume: %3!hs!, restart initiated: %4!hs!, disable resume: %5!hs!, registration: %6!hs!
10591059
.
10601060
10611061
MessageId=372

src/burn/engine/registration.cpp

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static HRESULT EnsureRegistrationVariable(
6464
);
6565
static HRESULT UpdateResumeMode(
6666
__in BURN_REGISTRATION* pRegistration,
67-
__in HKEY hkRegistration,
67+
__in_opt HKEY hkRegistration,
6868
__in BURN_RESUME_MODE resumeMode,
6969
__in BOOTSTRAPPER_REGISTRATION_TYPE registrationType,
7070
__in BOOL fRestartInitiated
@@ -461,13 +461,7 @@ extern "C" HRESULT RegistrationSetDynamicVariables(
461461
)
462462
{
463463
HRESULT hr = S_OK;
464-
LONGLONG llInstalled = 0;
465-
466-
// Detect if bundle is already installed.
467-
hr = RegistrationDetectInstalled(pRegistration);
468-
ExitOnFailure(hr, "Failed to detect bundle install state.");
469-
470-
llInstalled = BOOTSTRAPPER_REGISTRATION_TYPE_FULL == pRegistration->detectedRegistrationType ? 1 : 0;
464+
LONGLONG llInstalled = BOOTSTRAPPER_REGISTRATION_TYPE_FULL == pRegistration->detectedRegistrationType ? 1 : 0;
471465

472466
hr = VariableSetNumeric(pVariables, BURN_BUNDLE_INSTALLED, llInstalled, TRUE);
473467
ExitOnFailure(hr, "Failed to set the bundle installed built-in variable.");
@@ -483,7 +477,8 @@ extern "C" HRESULT RegistrationSetDynamicVariables(
483477
}
484478

485479
extern "C" HRESULT RegistrationDetectInstalled(
486-
__in BURN_REGISTRATION* pRegistration
480+
__in BURN_REGISTRATION* pRegistration,
481+
__in BURN_CACHE* pCache
487482
)
488483
{
489484
HRESULT hr = S_OK;
@@ -496,14 +491,28 @@ extern "C" HRESULT RegistrationDetectInstalled(
496491
{
497492
// For PUOM/PMOU bundles, check per-machine then fall back to per-user.
498493
hr = DetectInstalled(pRegistration, HKEY_LOCAL_MACHINE);
494+
if (SUCCEEDED(hr))
495+
{
496+
pRegistration->fPerMachine = TRUE;
499497

500-
if (FAILED(hr))
498+
hr = RegistrationSetPaths(pRegistration, pCache);
499+
ExitOnFailure(hr, "Failed to set registration paths for per-machine configurable scope.");
500+
}
501+
else
501502
{
502503
hr = DetectInstalled(pRegistration, HKEY_CURRENT_USER);
504+
505+
if (SUCCEEDED(hr))
506+
{
507+
pRegistration->fPerMachine = FALSE;
508+
509+
hr = RegistrationSetPaths(pRegistration, pCache);
510+
ExitOnFailure(hr, "Failed to set registration paths for per-user configurable scope.");
511+
}
503512
}
504513
}
505514

506-
//LExit:
515+
LExit:
507516
// Not finding the key or value is okay.
508517
if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr)
509518
{
@@ -1086,6 +1095,8 @@ extern "C" HRESULT RegistrationSetPaths(
10861095
hr = PathConcatRelativeToFullyQualifiedBase(sczCacheDirectory, pRegistration->sczExecutableName, &pRegistration->sczCacheExecutablePath);
10871096
ExitOnFailure(hr, "Failed to build cached executable path.");
10881097

1098+
pRegistration->fCached = pRegistration->sczCacheExecutablePath && FileExistsEx(pRegistration->sczCacheExecutablePath, NULL);
1099+
10891100
// build state file path
10901101
hr = StrAllocFormatted(&pRegistration->sczStateFile, L"%ls\\state.rsm", sczCacheDirectory);
10911102
ExitOnFailure(hr, "Failed to build state file path.");
@@ -1242,7 +1253,7 @@ static HRESULT EnsureRegistrationVariable(
12421253

12431254
static HRESULT UpdateResumeMode(
12441255
__in BURN_REGISTRATION* pRegistration,
1245-
__in HKEY hkRegistration,
1256+
__in_opt HKEY hkRegistration,
12461257
__in BURN_RESUME_MODE resumeMode,
12471258
__in BOOTSTRAPPER_REGISTRATION_TYPE registrationType,
12481259
__in BOOL fRestartInitiated
@@ -1254,7 +1265,7 @@ static HRESULT UpdateResumeMode(
12541265
LPWSTR sczRunOnceCommandLine = NULL;
12551266
LPCWSTR sczResumeKey = REGISTRY_RUN_ONCE_KEY;
12561267

1257-
LogId(REPORT_STANDARD, MSG_SESSION_UPDATE, pRegistration->sczRegistrationKey, LoggingInstallScopeToString(pRegistration->fPerMachine), LoggingResumeModeToString(resumeMode), LoggingBoolToString(fRestartInitiated), LoggingBoolToString(pRegistration->fDisableResume));
1268+
LogId(REPORT_STANDARD, MSG_SESSION_UPDATE, pRegistration->sczRegistrationKey, LoggingInstallScopeToString(pRegistration->fPerMachine), LoggingResumeModeToString(resumeMode), LoggingBoolToString(fRestartInitiated), LoggingBoolToString(pRegistration->fDisableResume), LoggingRegistrationTypeToString(registrationType));
12581269

12591270
// write resume information
12601271
if (hkRegistration)
@@ -1776,7 +1787,6 @@ static HRESULT DetectInstalled(
17761787
DWORD dwInstalled = 0;
17771788
DWORD dwScope = 0;
17781789

1779-
pRegistration->fCached = pRegistration->sczCacheExecutablePath && FileExistsEx(pRegistration->sczCacheExecutablePath, NULL);
17801790
pRegistration->detectedRegistrationType = BOOTSTRAPPER_REGISTRATION_TYPE_NONE;
17811791
pRegistration->detectedScope = BOOTSTRAPPER_SCOPE_DEFAULT;
17821792

src/burn/engine/registration.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ HRESULT RegistrationSetDynamicVariables(
186186
__in BURN_VARIABLES* pVariables
187187
);
188188
HRESULT RegistrationDetectInstalled(
189-
__in BURN_REGISTRATION* pRegistration
189+
__in BURN_REGISTRATION* pRegistration,
190+
__in BURN_CACHE* pCache
190191
);
191192
HRESULT RegistrationDetectResumeType(
192193
__in BURN_REGISTRATION* pRegistration,

src/test/burn/WixToolsetTest.BurnE2E/ConfigurableScopeTests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,12 @@ public void BundleUpgradeIsLockedToFirstBundlesScope()
108108

109109
Assert.True(LogVerifier.MessageInLogFile(log, "Plan begin, 3 packages, action: Install, planned scope: Default"));
110110

111+
log = bundle.Modify();
112+
Assert.True(LogVerifier.MessageInLogFile(log, "TESTBA: OnDetectBegin: Cached=True"));
113+
Assert.False(LogVerifier.MessageInLogFile(log, "Could not load or read state file:"));
114+
111115
log = bundle.Repair();
116+
Assert.False(LogVerifier.MessageInLogFile(log, "Could not load or read state file:"));
112117
Assert.True(LogVerifier.MessageInLogFile(log, "Bundle was already installed with scope: PerUser. Scope cannot change during maintenance."));
113118

114119
var bundleV2 = this.CreateBundleInstaller("AllPuomBundleTestBAv2");
@@ -132,6 +137,8 @@ public void BundleUpgradeWithSameScopeSucceeds()
132137
Assert.True(LogVerifier.MessageInLogFile(log, "Plan begin, 3 packages, action: Install, planned scope: Default"));
133138

134139
log = bundle.Repair();
140+
Assert.True(LogVerifier.MessageInLogFile(log, "TESTBA: OnDetectBegin: Cached=True"));
141+
Assert.False(LogVerifier.MessageInLogFile(log, "Could not load or read state file:"));
135142
Assert.True(LogVerifier.MessageInLogFile(log, "Bundle was already installed with scope: PerUser. Scope cannot change during maintenance."));
136143

137144
var bundleV2 = this.CreateBundleInstaller("AllPuomBundleTestBAv2");
@@ -164,6 +171,8 @@ public void PMOU_Bundle_Default_Plan_Installs_PerMachine()
164171
Assert.True(LogVerifier.MessageInLogFile(log, "Planned package: PmouPkg2.msi, state: Absent, default requested: Present, ba requested: Present, execute: Install, rollback: Uninstall, scope: PerMachine,"));
165172

166173
log = bundle.Repair();
174+
Assert.True(LogVerifier.MessageInLogFile(log, "TESTBA: OnDetectBegin: Cached=True"));
175+
Assert.False(LogVerifier.MessageInLogFile(log, "Could not load or read state file:"));
167176
Assert.True(LogVerifier.MessageInLogFile(log, "Bundle was already installed with scope: PerMachine"));
168177
Assert.True(LogVerifier.MessageInLogFile(log, "Detected package: PmouPkg1.msi, state: Present, authored scope: PerMachineOrUser, detected scope: PerMachine,"));
169178
Assert.True(LogVerifier.MessageInLogFile(log, "Detected package: PmouPkg2.msi, state: Present, authored scope: PerMachineOrUser, detected scope: PerMachine,"));
@@ -508,6 +517,8 @@ public void PM_PU_PMOU_Bundle_Default_Plan_Installs_PerMachine()
508517
Assert.True(LogVerifier.MessageInLogFile(log, "Planned package: PerUserPkg.msi, state: Absent, default requested: Present, ba requested: Present, execute: Install, rollback: Uninstall, scope: PerUser"));
509518

510519
log = bundle.Repair();
520+
Assert.True(LogVerifier.MessageInLogFile(log, "TESTBA: OnDetectBegin: Cached=True"));
521+
Assert.False(LogVerifier.MessageInLogFile(log, "Could not load or read state file:"));
511522
Assert.True(LogVerifier.MessageInLogFile(log, "Detected package: PerMachinePkg.msi, state: Present, authored scope: PerMachine, detected scope: PerMachine,"));
512523
Assert.True(LogVerifier.MessageInLogFile(log, "Detected package: PmouPkg1.msi, state: Present, authored scope: PerMachineOrUser, detected scope: PerMachine,"));
513524
Assert.True(LogVerifier.MessageInLogFile(log, "Detected package: PmouPkg2.msi, state: Present, authored scope: PerMachineOrUser, detected scope: PerMachine,"));

0 commit comments

Comments
 (0)