Add support for mounting files and non-existing folders as volumes #40137
Add support for mounting files and non-existing folders as volumes #40137OneBlue merged 6 commits intofeature/wsl-for-appsfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR extends WSLC container volume handling to support bind-mounting single files and automatically creating non-existent host directories for volume mounts, with accompanying Windows test coverage and updated user-facing errors.
Changes:
- Add file-volume support by mounting the parent directory into the VM and binding only the specific file into the container.
- Create host volume directories on-demand when the specified host path does not exist.
- Add/adjust tests and common ACL helper for validating path rejection and access-denied propagation.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| test/windows/WSLCTests.cpp | Adds advanced volume tests (file mounts, symlinks, auto-create, invalid/relative paths, access denied) and small output-validation helpers. |
| test/windows/wslc/e2e/WSLCE2EImageBuildTests.cpp | Switches E2E access-denial setup to the shared SetPathAccess helper and removes the local helper. |
| test/windows/wslc/e2e/WSLCE2EContainerCreateTests.cpp | Updates expected stderr to reflect the new “Path is not absolute” user error output. |
| test/windows/Common.h | Declares SetPathAccess for reuse across tests. |
| test/windows/Common.cpp | Implements SetPathAccess using Windows ACL APIs. |
| src/windows/wslcsession/WSLCContainerMetadata.h | Extends volume metadata with SourceFilename for file mounts and includes it in JSON serialization. |
| src/windows/wslcsession/WSLCContainer.cpp | Implements missing-directory creation, file-mount handling, symlink canonicalization, and updated inspect source reconstruction. |
| localization/strings/en-US/Resources.resw | Adds a new localized user-facing error string for failed volume creation/mount preparation. |
|
|
||
| VerifyPatternMatch( | ||
| wsl::shared::string::WideToMultiByte(comError->Message.get()), | ||
| "Failed to create volume '*test-volume\\subfolder': Access is denied. "); |
There was a problem hiding this comment.
The expected error pattern ends with a literal trailing space after "Access is denied.". This makes the test brittle if the underlying error string changes whitespace/newline formatting (e.g., ".\r\n" vs ". "). Consider removing the trailing space dependency or adding a wildcard at the end of the pattern / trimming the actual message before matching.
| "Failed to create volume '*test-volume\\subfolder': Access is denied. "); | |
| "Failed to create volume '*test-volume\\subfolder': Access is denied.*"); |
| for (auto& volume : volumes) | ||
| { | ||
| // Create a new directory if it doesn't exist. | ||
| if (!std::filesystem::exists(volume.HostPath)) |
There was a problem hiding this comment.
this is fine now because wslcsession runs as the user.
There was a problem hiding this comment.
Yeah this is actually very handy
Summary of the Pull Request
This change adds support for mounting files and non-existing folders as volumes
PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed