Skip to content
Open
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
11 changes: 10 additions & 1 deletion src/windows/service/exe/LxssUserSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1431,7 +1431,16 @@ HRESULT LxssUserSessionImpl::RegisterDistribution(

if (TargetDirectory == nullptr)
{
distributionPath = config.DefaultDistributionLocation / wsl::shared::string::GuidToString<wchar_t>(DistributionId);
// If a custom name is provided, use it as the folder name instead of a GUID.
// This improves usability when distributionInstallPath is configured in .wslconfig.
if (DistributionName != nullptr)
{
distributionPath = config.DefaultDistributionLocation / DistributionName;
}
else
{
distributionPath = config.DefaultDistributionLocation / wsl::shared::string::GuidToString<wchar_t>(DistributionId);
}
}
else
{
Expand Down
50 changes: 50 additions & 0 deletions test/windows/UnitTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4337,6 +4337,12 @@ Error code: Wsl/Service/RegisterDistro/WSL_E_DISTRIBUTION_NAME_NEEDED\r\n";
// Validate that the distribution was created in the correct path
VERIFY_ARE_EQUAL(std::filesystem::path(basePath).parent_path().string(), currentPath.string());

// Validate that the folder name matches the instance name (not a GUID)
VERIFY_ARE_EQUAL(std::filesystem::path(basePath).filename().wstring(), L"test-overridden-default-location");

// Validate that the folder name matches the instance name (not a GUID)
VERIFY_ARE_EQUAL(std::filesystem::path(basePath).filename().wstring(), L"test-overridden-default-location");

ValidateDistributionShortcut(L"test-overridden-default-location", nullptr);

cleanup.reset();
Expand All @@ -4346,6 +4352,50 @@ Error code: Wsl/Service/RegisterDistro/WSL_E_DISTRIBUTION_NAME_NEEDED\r\n";
VERIFY_IS_FALSE(std::filesystem::exists(basePath));
}

// Distribution with overridden default location but without explicit name (should use GUID)
{
constexpr auto distroName = L"test-guid-folder";

auto cleanup = wil::scope_exit_log(
WI_DIAGNOSTICS_INFO, [&]() {
LxsstuLaunchWsl(std::format(L"--unregister {}", distroName));
DeleteFile(L"test-guid-folder.tar");
});

auto currentPath = std::filesystem::current_path();
WslConfigChange wslconfig(std::format(L"[general]\ndistributionInstallPath = {}", EscapePath(currentPath.wstring())));

// Create a tar with a default name, then install without --name
CreateTarFromManifest(std::format(L"[oobe]\ndefaultName = {}", distroName).c_str(), L"test-guid-folder.tar");

// Install without --name, so the folder should use a GUID despite having a default name
InstallFromTar(L"test-guid-folder.tar", L"");

ValidateDistributionStarts(distroName);

auto distroKey = OpenDistributionKey(distroName);
VERIFY_IS_TRUE(!!distroKey);

auto basePath = wsl::windows::common::registry::ReadString(distroKey.get(), nullptr, L"BasePath", L"");
VERIFY_IS_TRUE(std::filesystem::exists(basePath));

// Validate that the distribution was created in the correct path
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)
// The GUID should match the distribution ID
wsl::windows::common::SvcComm service;
auto distroGuid = service.GetDistributionId(distroName);
auto expectedFolderName = wsl::shared::string::GuidToString<wchar_t>(distroGuid);
auto actualFolderName = std::filesystem::path(basePath).filename().wstring();
VERIFY_ARE_EQUAL(expectedFolderName, actualFolderName);

cleanup.reset();

// Validate that the base path is removed
VERIFY_IS_FALSE(std::filesystem::exists(basePath));
}

// Distribution installed in a custom location

{
Expand Down