Validate custom install locations before downloading distributions - #41628
Draft
Ben Hillis (benhillis) with Copilot wants to merge 2 commits into
Draft
Ben Hillis (benhillis) with Copilot wants to merge 2 commits into
Ben Hillis (benhillis) with Copilot wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
Copilot wasn't able to review any files in this pull request.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Co-authored-by: benhillis <17727402+benhillis@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add validation for target directory existence before downloading
Validate custom install locations before downloading distributions
Sep 16, 2026
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved directory cleanup and path validation issues remain, along with a localization gap and missing regression coverage.
Get a fresh assessment by requesting another Copilot review.
Review details
Suppressed comments (3)
src/windows/common/WslInstall.cpp:294
Failed to create install location: %lsis a newly introduced English string on thewsl --installerror path, but it has no localization resource. Use aMessage...helper with the path/error details as placeholders andTHROW_HR_WITH_USER_ERRORso failures from this preflight validation follow the localized error handling used elsewhere in this component.
THROW_IF_WIN32_ERROR_MSG(error.value(), "Failed to create install location: %ls", location->c_str());
src/windows/common/WslInstall.cpp:294
create_directoriestreats an already-existing path as successful with no error even when it is a regular file. BecausedirectoryCreatedis false in that case, this proceeds to download and the service only fails later when it tries to install beneath the file, so the preflight still accepts an unusable--location. Checkis_directory(and propagate its error) after this call before starting acquisition.
directoryCreated = std::filesystem::create_directories(*location, error);
THROW_IF_WIN32_ERROR_MSG(error.value(), "Failed to create install location: %ls", location->c_str());
test/windows/UnitTests.cpp:5683
- This test only exercises the error path where
create_directoriesfails immediately becauseg_testDistroPathis a file. It does not cover the newdirectoryCreated == truebranch (successful creation followed by download/import failure), so it would not catch the incomplete cleanup cases above. Add a nested, otherwise-valid location and assert that the newly created directories are removed after failure.
auto [output, error] = LxsstuLaunchWslAndCaptureOutput(
std::format(L"--install invalid-location --no-launch --location \"{}\"", invalidLocation.native()), -1);
VERIFY_IS_TRUE(output.find(L"Downloading:") == std::wstring::npos);
VERIFY_IS_FALSE(error.empty());
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
Comment on lines
+297
to
+301
| auto directoryCleanup = wil::scope_exit_log(WI_DIAGNOSTICS_INFO, [&]() { | ||
| if (directoryCreated) | ||
| { | ||
| LOG_IF_WIN32_BOOL_FALSE(RemoveDirectoryW(location->c_str())); | ||
| } |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary of the Pull Request
wsl --install --locationdeferred path creation until after downloading the distribution. Custom locations are now created and validated before payload acquisition, failing immediately when unusable.PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed
wsl --install --locationdownloads distribution before validating target directory existence #41625