Allow elevation through non-linux commands #1881
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We use @vscode/sudo-prompt to elevate. This way we don't need to handle the user password.
As discussed here #1620 Sudo-prompt does not store elevation permission, so every time it makes a request, it makes a new password request. For linux this is extremely annoying so there is a ton of extra setup I do to prevent this requirement.
For windows and mac, we can just call into the API directly since we dont need to elevate multiple times, it's less annoying.
This codepath was never used before (
runUnderSudo
only ever provided on linux.)The prompt looks like this on Mac.
Windows.
There isn't much we can do to change that, since that's part of vscode's library.
On Windows, sometimes we will fail to run due to denied permissions, we can at least retry by launching the application with more permissions the first time.
For Mac and Windows when uninstalling, for some uninstallation methods, we need to be elevated from the beginning, otherwise the install will immediately fail. Example. https://github.com/dotnet/cli-lab/blob/ffb7b78931370c04f6b2a045cf8e79d299f66286/src/dotnet-core-uninstall/Shared/Commands/UninstallCommandExec.cs#L41
This PR will enable future code to elevate. Namely, #1897 cannot work without this because it needs to run
sudo rm
.