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

Add experimental feature for initiating reboot for single package installs #3631

Merged
merged 12 commits into from
Oct 21, 2023

Conversation

ryfu-msft
Copy link
Contributor

@ryfu-msft ryfu-msft commented Sep 15, 2023

Related to: #3165

This PR adds support for the reboot experimental feature. This only applies to single package and multiple package installs. This does not apply to any package dependencies that may require a restart.

Changes:

  • Added an AllowReboot argument flag. When provided, if the return code of an installer is either APPINSTALLER_CLI_ERROR_INSTALL_REBOOT_REQUIRED_TO_FINISH or APPINSTALLER_CLI_ERROR_INSTALL_REBOOT_REQUIRED_TO_INSTALL, winget will automatically begin restarting your machine so that the installation can be completed.
  • Reboot privilege is checked prior to kicking off a reboot and the appropriate error message is shown if the current user does not have the privilege.

Tests:

  • Verifies that a reboot is initiated for both single and multiple package installs if the return code matches the reboot required return codes.
  • Verifies that the error message is displayed to the user if the shutdown privilege is not met.
  • Manually verified that restart is kicked off if requirements for a reboot are met.
Microsoft Reviewers: Open in CodeFlow

@ryfu-msft ryfu-msft requested a review from a team as a code owner September 15, 2023 17:43
src/AppInstallerCLICore/Workflows/InstallFlow.cpp Outdated Show resolved Hide resolved
@@ -730,6 +781,11 @@ namespace AppInstaller::CLI::Workflow
}
}

if (shouldReboot)
{
InitiateRebootIfApplicable(context, true);
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should be setting a flag on the context rather than initiating a reboot at arbitrary locations in the workflow. We could then ensure that the reboot happens at the end the workflow, rather than in the middle. It would also make it easier to ensure that we know exactly what can initiate a reboot (maybe we want to forever block it from COM).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to setting a context flag so that indicates whether we should initiate a reboot so that it only takes place at the end of all the install workflows and is contained inside a single workflow function.

<value>Allows a reboot if applicable</value>
</data>
<data name="InitiatingReboot" xml:space="preserve">
<value>Initiating reboot to complete installation...</value>
Copy link
Member

Choose a reason for hiding this comment

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

This is not quite true for APPINSTALLER_CLI_ERROR_INSTALL_REBOOT_REQUIRED_TO_INSTALL until you hook up resume. I assume that is the plan: _TO_INSTALL reboots with a resume but _TO_FINISH reboots without a resume?

Side thought, we might already have an issue with _TO_FINISH results being treated as an error and thus not recorded properly. They should probably be treated as a success for post-install purposes.

Copy link
Contributor Author

@ryfu-msft ryfu-msft Oct 19, 2023

Choose a reason for hiding this comment

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

Made changes to ReportInstallerResult so that APPINSTALLER_CLI_ERROR_INSTALL_REBOOT_REQUIRED_TO_FINISH is treated as a success and no longer reported as a failed installer result.

Also added a context flag that indicates whether we should register for a restart if the return code is APPINSTALLER_CLI_ERROR_INSTALL_REBOOT_REQUIRED_TO_INSTALL for resume

@@ -1204,3 +1204,68 @@ TEST_CASE("InstallFlow_InstallAcquiresLock", "[InstallFlow][workflow]")
REQUIRE(installResultStr.find("/custom") != std::string::npos);
REQUIRE(installResultStr.find("/silentwithprogress") != std::string::npos);
}

TEST_CASE("InstallFlow_InstallMultipleWithReboot", "[InstallFlow][workflow][MultiQuery][reboot]")
Copy link
Member

Choose a reason for hiding this comment

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

Not a huge fan of a test that, if it "fails", reboots my machine...

Can we also have an override that replaces the reboot operation with a callback and you can just set a bool? That would also allow for tests that actually "reboot".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to suggested and added tests that verifies if a reboot actually succeeds

src/AppInstallerCommonCore/Public/winget/Reboot.h Outdated Show resolved Hide resolved
src/AppInstallerCLICore/Workflows/InstallFlow.cpp Outdated Show resolved Hide resolved
src/AppInstallerCLICore/Workflows/InstallFlow.cpp Outdated Show resolved Hide resolved
src/AppInstallerCommonCore/Reboot.cpp Outdated Show resolved Hide resolved
yao-msft
yao-msft previously approved these changes Oct 20, 2023
@ryfu-msft ryfu-msft merged commit a32e114 into microsoft:master Oct 21, 2023
8 checks passed
@ryfu-msft ryfu-msft deleted the initiateReboot branch October 21, 2023 02:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants