Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BA Plan & log transaction #54

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ enum BOOTSTRAPPER_APPLICATION_MESSAGE
BOOTSTRAPPER_APPLICATION_MESSAGE_ONPLANRELATEDBUNDLE,
BOOTSTRAPPER_APPLICATION_MESSAGE_ONPLANPACKAGEBEGIN,
BOOTSTRAPPER_APPLICATION_MESSAGE_ONPLANPATCHTARGET,
BOOTSTRAPPER_APPLICATION_MESSAGE_ONPLANMSITRANSACTION,
BOOTSTRAPPER_APPLICATION_MESSAGE_ONPLANMSIFEATURE,
BOOTSTRAPPER_APPLICATION_MESSAGE_ONPLANPACKAGECOMPLETE,
BOOTSTRAPPER_APPLICATION_MESSAGE_ONAPPLYBEGIN,
Expand Down Expand Up @@ -1006,6 +1007,19 @@ struct BA_ONPLANCOMPLETE_RESULTS
DWORD cbSize;
};

struct BA_ONPLANMSITRANSACTION_ARGS
{
DWORD cbSize;
LPCWSTR wzTransactionId;
BOOL fTransaction;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

};

struct BA_ONPLANMSITRANSACTION_RESULTS
{
DWORD cbSize;
BOOL fTransaction;
};

struct BA_ONPLANFORWARDCOMPATIBLEBUNDLE_ARGS
{
DWORD cbSize;
Expand Down
31 changes: 22 additions & 9 deletions src/engine/apply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,7 @@ extern "C" HRESULT ApplyExecute(
break;
}

// The action failed, roll back to previous rollback boundary.
if (pCheckpoint)
{
// If inside a MSI transaction, roll it back.
Expand All @@ -717,6 +718,7 @@ extern "C" HRESULT ApplyExecute(
}

// Move forward to next rollback boundary.
hr = S_OK;
rseanhall marked this conversation as resolved.
Show resolved Hide resolved
fSeekNextRollbackBoundary = TRUE;
}
}
Expand Down Expand Up @@ -2787,6 +2789,8 @@ static HRESULT ExecuteMsiBeginTransaction(
{
HRESULT hr = S_OK;
BOOL fBeginCalled = FALSE;
MSIHANDLE hMsiTrns = NULL;
HANDLE hMsiTrnsEvent = NULL;
Comment on lines +2792 to +2793
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you insisting on these changes?


if (pRollbackBoundary->fActiveTransaction)
{
Expand All @@ -2797,14 +2801,16 @@ static HRESULT ExecuteMsiBeginTransaction(
hr = UserExperienceOnBeginMsiTransactionBegin(&pEngineState->userExperience, pRollbackBoundary->sczId);
ExitOnRootFailure(hr, "BA aborted execute begin MSI transaction.");

LogId(REPORT_STANDARD, MSG_MSI_TRANSACTION_BEGIN, pRollbackBoundary->sczId);

Comment on lines +2804 to +2805
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you insisting on these changes?

if (pEngineState->plan.fPerMachine)
{
hr = ElevationMsiBeginTransaction(pEngineState->companionConnection.hPipe, pRollbackBoundary);
ExitOnFailure(hr, "Failed to begin an elevated MSI transaction.");
}
else
{
hr = MsiEngineBeginTransaction(pRollbackBoundary);
hr = MsiEngineBeginTransaction(pRollbackBoundary->sczId, &hMsiTrns, &hMsiTrnsEvent, pRollbackBoundary->sczLogPath);
Comment on lines -2807 to +2813
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you insisting on these changes?

}

if (SUCCEEDED(hr))
Expand All @@ -2820,6 +2826,9 @@ static HRESULT ExecuteMsiBeginTransaction(
UserExperienceOnBeginMsiTransactionComplete(&pEngineState->userExperience, pRollbackBoundary->sczId, hr);
}

ReleaseHandle(hMsiTrnsEvent);
ReleaseMsi(hMsiTrns);

return hr;
}

Expand All @@ -2830,25 +2839,27 @@ static HRESULT ExecuteMsiCommitTransaction(
)
{
HRESULT hr = S_OK;
BOOL fCommitBeginCalled = FALSE;
BOOL fCommitCalled = FALSE;
Comment on lines -2833 to +2842
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you insisting on these changes?


if (!pRollbackBoundary->fActiveTransaction)
{
ExitFunction1(hr = E_INVALIDSTATE);
}

fCommitBeginCalled = TRUE;
fCommitCalled = TRUE;
hr = UserExperienceOnCommitMsiTransactionBegin(&pEngineState->userExperience, pRollbackBoundary->sczId);
ExitOnRootFailure(hr, "BA aborted execute commit MSI transaction.");

LogId(REPORT_STANDARD, MSG_MSI_TRANSACTION_COMMIT, pRollbackBoundary->sczId);

if (pEngineState->plan.fPerMachine)
{
hr = ElevationMsiCommitTransaction(pEngineState->companionConnection.hPipe, pRollbackBoundary);
ExitOnFailure(hr, "Failed to commit an elevated MSI transaction.");
}
else
{
hr = MsiEngineCommitTransaction(pRollbackBoundary);
hr = MsiEngineCommitTransaction(NULL, NULL, pRollbackBoundary->sczLogPath);
}

if (SUCCEEDED(hr))
Expand All @@ -2859,7 +2870,7 @@ static HRESULT ExecuteMsiCommitTransaction(
}

LExit:
if (fCommitBeginCalled)
if (fCommitCalled)
{
UserExperienceOnCommitMsiTransactionComplete(&pEngineState->userExperience, pRollbackBoundary->sczId, hr);
}
Expand All @@ -2874,32 +2885,34 @@ static HRESULT ExecuteMsiRollbackTransaction(
)
{
HRESULT hr = S_OK;
BOOL fRollbackBeginCalled = FALSE;
BOOL fRlbkCalled = FALSE;
Comment on lines -2877 to +2888
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you insisting on these changes?


if (!pRollbackBoundary->fActiveTransaction)
{
ExitFunction();
}

fRollbackBeginCalled = TRUE;
fRlbkCalled = TRUE;
UserExperienceOnRollbackMsiTransactionBegin(&pEngineState->userExperience, pRollbackBoundary->sczId);

LogId(REPORT_WARNING, MSG_MSI_TRANSACTION_ROLLBACK, pRollbackBoundary->sczId);

if (pEngineState->plan.fPerMachine)
{
hr = ElevationMsiRollbackTransaction(pEngineState->companionConnection.hPipe, pRollbackBoundary);
ExitOnFailure(hr, "Failed to rollback an elevated MSI transaction.");
}
else
{
hr = MsiEngineRollbackTransaction(pRollbackBoundary);
hr = MsiEngineRollbackTransaction(NULL, NULL, pRollbackBoundary->sczLogPath);
}

LExit:
pRollbackBoundary->fActiveTransaction = FALSE;

ResetTransactionRegistrationState(pEngineState, FALSE);

if (fRollbackBeginCalled)
if (fRlbkCalled)
{
UserExperienceOnRollbackMsiTransactionComplete(&pEngineState->userExperience, pRollbackBoundary->sczId, hr);
}
Expand Down
86 changes: 21 additions & 65 deletions src/engine/elevation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,17 +285,14 @@ static HRESULT OnLaunchApprovedExe(
__in DWORD cbData
);
static HRESULT OnMsiBeginTransaction(
__in BURN_PACKAGES* pPackages,
__in BYTE* pbData,
__in DWORD cbData
);
static HRESULT OnMsiCommitTransaction(
__in BURN_PACKAGES* pPackages,
__in BYTE* pbData,
__in DWORD cbData
);
static HRESULT OnMsiRollbackTransaction(
__in BURN_PACKAGES* pPackages,
__in BYTE* pbData,
__in DWORD cbData
);
Expand Down Expand Up @@ -846,9 +843,6 @@ extern "C" HRESULT ElevationMsiCommitTransaction(
DWORD dwResult = ERROR_SUCCESS;

// serialize message data
hr = BuffWriteString(&pbData, &cbData, pRollbackBoundary->sczId);
ExitOnFailure(hr, "Failed to write transaction name to message buffer.");

hr = BuffWriteString(&pbData, &cbData, pRollbackBoundary->sczLogPath);
ExitOnFailure(hr, "Failed to write transaction log path to message buffer.");

Expand All @@ -858,6 +852,8 @@ extern "C" HRESULT ElevationMsiCommitTransaction(
hr = static_cast<HRESULT>(dwResult);

LExit:
ReleaseBuffer(pbData);

Comment on lines +855 to +856
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this. But why are you insisting on all the other changes here?

return hr;
}

Expand All @@ -872,9 +868,6 @@ extern "C" HRESULT ElevationMsiRollbackTransaction(
DWORD dwResult = ERROR_SUCCESS;

// serialize message data
hr = BuffWriteString(&pbData, &cbData, pRollbackBoundary->sczId);
ExitOnFailure(hr, "Failed to write transaction name to message buffer.");

hr = BuffWriteString(&pbData, &cbData, pRollbackBoundary->sczLogPath);
ExitOnFailure(hr, "Failed to write transaction log path to message buffer.");

Expand All @@ -884,6 +877,8 @@ extern "C" HRESULT ElevationMsiRollbackTransaction(
hr = static_cast<HRESULT>(dwResult);

LExit:
ReleaseBuffer(pbData);

return hr;
}

Expand Down Expand Up @@ -1758,15 +1753,15 @@ static HRESULT ProcessElevatedChildMessage(
switch (pMsg->dwMessage)
{
case BURN_ELEVATION_MESSAGE_TYPE_BEGIN_MSI_TRANSACTION:
hrResult = OnMsiBeginTransaction(pContext->pPackages, (BYTE*)pMsg->pvData, pMsg->cbData);
hrResult = OnMsiBeginTransaction((BYTE*)pMsg->pvData, pMsg->cbData);
break;

case BURN_ELEVATION_MESSAGE_TYPE_COMMIT_MSI_TRANSACTION:
hrResult = OnMsiCommitTransaction(pContext->pPackages, (BYTE*)pMsg->pvData, pMsg->cbData);
hrResult = OnMsiCommitTransaction((BYTE*)pMsg->pvData, pMsg->cbData);
break;

case BURN_ELEVATION_MESSAGE_TYPE_ROLLBACK_MSI_TRANSACTION:
hrResult = OnMsiRollbackTransaction(pContext->pPackages, (BYTE*)pMsg->pvData, pMsg->cbData);
hrResult = OnMsiRollbackTransaction((BYTE*)pMsg->pvData, pMsg->cbData);
break;

case BURN_ELEVATION_MESSAGE_TYPE_APPLY_INITIALIZE:
Expand Down Expand Up @@ -3049,116 +3044,77 @@ static HRESULT OnLaunchApprovedExe(
}

static HRESULT OnMsiBeginTransaction(
__in BURN_PACKAGES* pPackages,
__in BYTE* pbData,
__in DWORD cbData
)
{
HRESULT hr = S_OK;
SIZE_T iData = 0;
LPWSTR sczId = NULL;
LPWSTR szName = NULL;
LPWSTR sczLogPath = NULL;
BURN_ROLLBACK_BOUNDARY* pRollbackBoundary = NULL;
MSIHANDLE hMsiTrns = NULL;
HANDLE hMsiTrnsEvent = NULL;

// Deserialize message data.
hr = BuffReadString(pbData, cbData, &iData, &sczId);
ExitOnFailure(hr, "Failed to read rollback boundary id.");
hr = BuffReadString(pbData, cbData, &iData, &szName);
ExitOnFailure(hr, "Failed to read transaction name.");

hr = BuffReadString(pbData, cbData, &iData, &sczLogPath);
ExitOnFailure(hr, "Failed to read transaction log path.");

PackageFindRollbackBoundaryById(pPackages, sczId, &pRollbackBoundary);
ExitOnFailure(hr, "Failed to find rollback boundary: %ls", sczId);

pRollbackBoundary->sczLogPath = sczLogPath;

hr = MsiEngineBeginTransaction(pRollbackBoundary);
hr = MsiEngineBeginTransaction(szName, &hMsiTrns, &hMsiTrnsEvent, sczLogPath);
ExitOnFailure(hr, "Failed beginning an MSI transaction");
Comment on lines -3070 to +3066
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you insisting on these changes?


LExit:
ReleaseStr(sczId);
ReleaseStr(szName);
ReleaseStr(sczLogPath);

if (pRollbackBoundary)
{
pRollbackBoundary->sczLogPath = NULL;
}
ReleaseHandle(hMsiTrnsEvent);
ReleaseMsi(hMsiTrns);

return hr;
}

static HRESULT OnMsiCommitTransaction(
__in BURN_PACKAGES* pPackages,
__in BYTE* pbData,
__in DWORD cbData
)
{
HRESULT hr = S_OK;
SIZE_T iData = 0;
LPWSTR sczId = NULL;
LPWSTR sczLogPath = NULL;
BURN_ROLLBACK_BOUNDARY* pRollbackBoundary = NULL;

// Deserialize message data.
hr = BuffReadString(pbData, cbData, &iData, &sczId);
ExitOnFailure(hr, "Failed to read rollback boundary id.");

hr = BuffReadString(pbData, cbData, &iData, &sczLogPath);
ExitOnFailure(hr, "Failed to read transaction log path.");

PackageFindRollbackBoundaryById(pPackages, sczId, &pRollbackBoundary);
ExitOnFailure(hr, "Failed to find rollback boundary: %ls", sczId);

pRollbackBoundary->sczLogPath = sczLogPath;

hr = MsiEngineCommitTransaction(pRollbackBoundary);
hr = MsiEngineCommitTransaction(NULL, NULL, sczLogPath);
ExitOnFailure(hr, "Failed committing an MSI transaction");

LExit:
ReleaseStr(sczId);
ReleaseStr(sczLogPath);

if (pRollbackBoundary)
{
pRollbackBoundary->sczLogPath = NULL;
}

return hr;
}

static HRESULT OnMsiRollbackTransaction(
__in BURN_PACKAGES* pPackages,
__in BYTE* pbData,
__in DWORD cbData
)
{
HRESULT hr = S_OK;
SIZE_T iData = 0;
LPWSTR sczId = NULL;
LPWSTR sczLogPath = NULL;
BURN_ROLLBACK_BOUNDARY* pRollbackBoundary = NULL;

// Deserialize message data.
hr = BuffReadString(pbData, cbData, &iData, &sczId);
ExitOnFailure(hr, "Failed to read rollback boundary id.");

hr = BuffReadString(pbData, cbData, &iData, &sczLogPath);
ExitOnFailure(hr, "Failed to read transaction log path.");

PackageFindRollbackBoundaryById(pPackages, sczId, &pRollbackBoundary);
ExitOnFailure(hr, "Failed to find rollback boundary: %ls", sczId);

pRollbackBoundary->sczLogPath = sczLogPath;

hr = MsiEngineRollbackTransaction(pRollbackBoundary);
hr = MsiEngineRollbackTransaction(NULL, NULL, sczLogPath);
ExitOnFailure(hr, "Failed rolling back an MSI transaction");

LExit:
ReleaseStr(sczId);
ReleaseStr(sczLogPath);

if (pRollbackBoundary)
{
pRollbackBoundary->sczLogPath = NULL;
}

return hr;
}

Expand Down
7 changes: 7 additions & 0 deletions src/engine/engine.mc
Original file line number Diff line number Diff line change
Expand Up @@ -1088,3 +1088,10 @@ SymbolicName=MSG_PENDING_REBOOT_DETECTED
Language=English
A reboot is pending from a prior execution of this bundle: %1!ls!. Apply will be blocked. Continuing...
.

MessageId=702
Severity=Success
SymbolicName=MSG_UX_DECLINED_MSI_TRANSACTION
Language=English
UX voted against MSI transaction on rollback boundary '%1!ls!'
.
Loading