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
5 changes: 2 additions & 3 deletions src/windows/common/WslClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1218,9 +1218,8 @@ int Unmount(_In_ const std::wstring& arg)
wsl::windows::common::SvcComm service;
const HRESULT result = wil::ResultFromException([&] { value = service.DetachDisk(disk); });

// support relative paths in unmount
// check is the result is the error code for "file not found" and the path is relative
if (result == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) && PathIsRelative(disk))
// Retry with the normalized path to handle relative paths and \\?\ prefix mismatches.
if (result == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND))
{
// retry dismounting with the absolute path
const auto absoluteDisk = wsl::windows::common::filesystem::GetFullPath(filesystem::UnquotePath(disk).c_str());
Expand Down
23 changes: 23 additions & 0 deletions test/windows/MountTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,29 @@ class MountTests
VERIFY_ARE_EQUAL(LxsstuLaunchWsl(L"--unmount " + absolutePath.wstring()), (DWORD)0);
}

TEST_METHOD(AbsolutePathVhdUnmountAfterVMTimeout)
{
SKIP_UNSUPPORTED_ARM64_MOUNT_TEST();
WSL2_TEST_ONLY();

WslKeepAlive keepAlive;

VERIFY_ARE_EQUAL(LxsstuLaunchWsl(L"--mount " TEST_MOUNT_VHD L" --vhd --bare"), (DWORD)0);

const auto disk = GetBlockDeviceInWsl();
VERIFY_IS_TRUE(IsBlockDevicePresent(disk));

WaitForVmTimeout(keepAlive);

const auto absolutePath = std::filesystem::absolute(TEST_MOUNT_VHD);

// Validate that the vhd path doesn't start with '\\?'
VERIFY_IS_FALSE(absolutePath.wstring().starts_with(L"\\"));

// Validate the unmounting by absolute path is successful
VERIFY_ARE_EQUAL(LxsstuLaunchWsl(L"--unmount " + absolutePath.wstring()), (DWORD)0);
}

// Attach a disk, but don't mount it
TEST_METHOD(TestBareMount)
{
Expand Down
Loading