File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1218,9 +1218,8 @@ int Unmount(_In_ const std::wstring& arg)
12181218 wsl::windows::common::SvcComm service;
12191219 const HRESULT result = wil::ResultFromException ([&] { value = service.DetachDisk (disk); });
12201220
1221- // support relative paths in unmount
1222- // check is the result is the error code for "file not found" and the path is relative
1223- if (result == HRESULT_FROM_WIN32 (ERROR_FILE_NOT_FOUND) && PathIsRelative (disk))
1221+ // Retry with the normalized path to handle relative paths and \\?\ prefix mismatches.
1222+ if (result == HRESULT_FROM_WIN32 (ERROR_FILE_NOT_FOUND))
12241223 {
12251224 // retry dismounting with the absolute path
12261225 const auto absoluteDisk = wsl::windows::common::filesystem::GetFullPath (filesystem::UnquotePath (disk).c_str ());
Original file line number Diff line number Diff line change @@ -450,6 +450,29 @@ class MountTests
450450 VERIFY_ARE_EQUAL (LxsstuLaunchWsl (L" --unmount " + absolutePath.wstring ()), (DWORD)0 );
451451 }
452452
453+ TEST_METHOD (AbsolutePathVhdUnmountAfterVMTimeout)
454+ {
455+ SKIP_UNSUPPORTED_ARM64_MOUNT_TEST ();
456+ WSL2_TEST_ONLY ();
457+
458+ WslKeepAlive keepAlive;
459+
460+ VERIFY_ARE_EQUAL (LxsstuLaunchWsl (L" --mount " TEST_MOUNT_VHD L" --vhd --bare" ), (DWORD)0 );
461+
462+ const auto disk = GetBlockDeviceInWsl ();
463+ VERIFY_IS_TRUE (IsBlockDevicePresent (disk));
464+
465+ WaitForVmTimeout (keepAlive);
466+
467+ const auto absolutePath = std::filesystem::absolute (TEST_MOUNT_VHD);
468+
469+ // Validate that the vhd path doesn't start with '\\?'
470+ VERIFY_IS_FALSE (absolutePath.wstring ().starts_with (L" \\ " ));
471+
472+ // Validate the unmounting by absolute path is successful
473+ VERIFY_ARE_EQUAL (LxsstuLaunchWsl (L" --unmount " + absolutePath.wstring ()), (DWORD)0 );
474+ }
475+
453476 // Attach a disk, but don't mount it
454477 TEST_METHOD (TestBareMount)
455478 {
You can’t perform that action at this time.
0 commit comments