fix: correct sparse VHD command to include `true` by junhaoliao · Pull Request #13512 · microsoft/WSL

The WSL --set-sparse command requires a boolean value (true or false). The current "MessageSparseVhdDisabled" prompt omits true, which causes confusing error messages and prevented sparse VHD from being enabled.

This change ensures the command is complete in the "MessageSparseVhdDisabled" prompt:

  wsl.exe --manage <Distro> --set-sparse true --allow-unsafe

Ran .\bin\x64\Debug\test.bat /name:SimpleTests::SimpleTests::CheckSparse and observed the test case passed:

PS C:\Users\junhao\CLionProjects\WSL> .\bin\x64\Debug\test.bat /name:SimpleTests::SimpleTests::CheckSparse
Test Authoring and Execution Framework v10.97k for x64
OS build string: 26100.1.amd64fre.ge_release.240331-1435
Verify: IsTrue(config.good())
Verify: IsNotNull(g_WatchdogTimer)
Running test setup command: Powershell         -NoProfile         -ExecutionPolicy Bypass         -Command "C:/Users/junhao/CLionProjects/WSL\tools\test\test-setup.ps1 -Version '2' -DistroPath C:/Users/junhao/CLionProjects/WSL/packages/Microsoft.WSL.TestDistro.2.5.7-47/test_distro.tar.xz -DistroName test_distro -Package 'C:/Users/junhao/CLionProjects/WSL/bin/x64\Debug\installer.msix' -UnitTestsPath C:/Users/junhao/CLionProjects/WSL\test\linux\unit_tests -AllowUnsigned"
Removing previous package installation
Removing MSI package: {50D135E3-FC56-4CD3-A278-D5CD3B95DB3D}
Installing package: C:/Users/junhao/CLionProjects/WSL/bin/x64\Debug\installer.msix
WSL is finishing an upgrade...
Unregistering.
The operation completed successfully.

The operation completed successfully.
The operation completed successfully.
Verify: IsTrue(SetEnvironmentVariableW(L"WSL_UTF8", L"1"))
Verify: AreEqual(LxsstuInitialize(FALSE), TRUE)

StartGroup: SimpleTests::SimpleTests::CheckSparse
Verify: IsTrue(config.good())
Restarting WSLService
Verify: IsNotNull(manager)
Verify: IsNotNull(service)
tar C:\Users\junhao\AppData\Local\Temp\s1fd4.0.tar
vhdDir C:\Users\junhao\AppData\Local\Temp\s1fd4.1
Verify: IsTrue(std::filesystem::create_directory(vhdDir))
Export in progress, this may take a few minutes. (408 MB)

The operation completed successfully.
Verify: AreEqual(LxsstuLaunchWsl(std::format(L"{} {} {}", WSL_EXPORT_ARG, LXSS_DISTRO_NAME_TEST, tar.wstring()).c_str()), (DWORD)0)
Unregistering.
There is no distribution with the supplied name.
Error code: Wsl/Service/WSL_E_DISTRO_NOT_FOUND
Verify: AreEqual(ExpectedOutput, output)
Verify: AreEqual(ExpectedWarnings, warnings)
Verify: IsFalse(attributes == INVALID_FILE_ATTRIBUTES)
Verify: IsTrue(WI_IsFlagSet(attributes, FILE_ATTRIBUTE_SPARSE_FILE) == sparse)
Verify: AreEqual(0u, LxsstuLaunchWsl(WSL_SHUTDOWN_ARG))
Verify: AreEqual(ExpectedOutput, output)
Verify: AreEqual(ExpectedWarnings, warnings)
Verify: IsFalse(attributes == INVALID_FILE_ATTRIBUTES)
Verify: IsTrue(WI_IsFlagSet(attributes, FILE_ATTRIBUTE_SPARSE_FILE) == sparse)
Verify: AreEqual(ExpectedOutput, output)
Verify: AreEqual(ExpectedWarnings, warnings)
Verify: IsFalse(attributes == INVALID_FILE_ATTRIBUTES)
Verify: IsTrue(WI_IsFlagSet(attributes, FILE_ATTRIBUTE_SPARSE_FILE) == sparse)
Verify: AreEqual(ExpectedOutput, output)
Verify: AreEqual(ExpectedWarnings, warnings)
Verify: IsFalse(attributes == INVALID_FILE_ATTRIBUTES)
Verify: IsTrue(WI_IsFlagSet(attributes, FILE_ATTRIBUTE_SPARSE_FILE) == sparse)
Unregistering.
The operation completed successfully.

Verify: IsTrue(config.good())
Restarting WSLService
Verify: IsNotNull(manager)
Verify: IsNotNull(service)
EndGroup: SimpleTests::SimpleTests::CheckSparse [Passed]
Verify: IsTrue(SetEnvironmentVariableW(L"WSL_UTF8", nullptr))
Exiting UnitTests module
Restoring .wslconfig
Verify: IsTrue(config.good())
Previous default distro doesn't exist anymore: '{08d1a45a-41d8-4048-9c92-e9a7bb92e431}', skipping restore

Summary: Total=1, Passed=1, Failed=0, Blocked=0, Not Run=0, Skipped=0