-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Use instance name as folder name when --name is specified #13554
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
base: master
Are you sure you want to change the base?
Use instance name as folder name when --name is specified #13554
Conversation
When creating a WSL 2 instance with `--name` but without `--location`, and when `distributionInstallPath` is configured in `.wslconfig`, the folder name now uses the instance name instead of a GUID. 1. **src/windows/service/exe/LxssUserSession.cpp** - Updated `RegisterDistribution` method to use the provided distribution name as the folder name when: - `DistributionName` is provided (via `--name` parameter) - `TargetDirectory` is not provided (no `--location` parameter) - Maintains backward compatibility by using GUID when no name is provided 2. **test/windows/UnitTests.cpp** - Enhanced existing test to verify folder name matches instance name - Added new test case to verify GUID behavior is preserved when no name is provided Fixes microsoft#13530 This change improves usability by making distribution folders more identifiable and easier to manage when users explicitly provide instance names. Signed-off-by: Giovanni Magliocchetti <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements a quality-of-life improvement that uses the --name
parameter value as the folder name for new WSL distributions when distributionInstallPath
is configured but --location
is not explicitly provided. Previously, WSL would always use GUID-based folder names even when users specified a custom instance name.
Key changes:
- Modified distribution registration logic to use instance name as folder name when
--name
is provided - Preserved GUID-based naming for backward compatibility when no name is specified
- Added comprehensive test coverage for both named and auto-named distribution scenarios
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
File | Description |
---|---|
src/windows/service/exe/LxssUserSession.cpp | Updated RegisterDistribution logic to use instance name as folder name when available |
test/windows/UnitTests.cpp | Enhanced existing test and added new test case to validate both named and GUID-based folder creation |
test/windows/UnitTests.cpp
Outdated
{ | ||
std::wstring cmd = std::wstring(L"--unregister ") + name; | ||
LxsstuLaunchWsl(cmd.c_str()); | ||
break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use hardcoded name for the test distributions here, otherwise this might conflicts with pre-existing distributions and I'd rather not have the tests remove my distributions when I run them :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CreateTarFromManifest()
can be used to generate a .tar with a specific default name
test/windows/UnitTests.cpp
Outdated
// Find the installed distribution | ||
auto distros = wsl::windows::common::SvcComm().EnumerateDistributions(); | ||
std::wstring installedName; | ||
for (const auto& distro : distros) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove this block, since ValidateDistributionStarts
will validate that the distribution exists
test/windows/UnitTests.cpp
Outdated
VERIFY_ARE_EQUAL(std::filesystem::path(basePath).parent_path().string(), currentPath.string()); | ||
|
||
// Validate that the folder name is a GUID (since no --name was provided) | ||
auto folderName = std::filesystem::path(basePath).filename().wstring(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: We could use GetDistributionId(<name>)
and validate that the GUID matches the distribution ID here
Signed-off-by: Giovanni Magliocchetti <[email protected]>
Closes #13530
Summary
This PR implements a quality-of-life improvement that uses the
--name
parameter value as the folder name for new WSL distributions whendistributionInstallPath
is configured in.wslconfig
but--location
is not explicitly provided.Problem
Currently, when creating a WSL 2 instance with a specific name and a configured default installation path in
.wslconfig
, the folder created uses a GUID-based name rather than the instance name:With
.wslconfig
:Results in:
This makes it harder to manage instances and requires users to always specify
--location
explicitly.Solution
This PR modifies the distribution registration logic to use the provided instance name as the folder name when:
--name
is specified--location
is NOT specified.wslconfig
)After this change:
Results in:
Backward Compatibility
The GUID-based folder naming is preserved when no
--name
is provided, ensuring backward compatibility with existing workflows and automation that rely on auto-generated names.Changes Made
Code Changes
src/windows/service/exe/LxssUserSession.cpp
RegisterDistribution
to check if a distribution name is providedtest/windows/UnitTests.cpp
Testing
The changes include comprehensive test coverage:
--location
parameter still works as expectedBenefits