Skip to content

Add support for mounting files and non-existing folders as volumes #40137

Merged
OneBlue merged 6 commits intofeature/wsl-for-appsfrom
user/oneblue/mount-files
Apr 9, 2026
Merged

Add support for mounting files and non-existing folders as volumes #40137
OneBlue merged 6 commits intofeature/wsl-for-appsfrom
user/oneblue/mount-files

Conversation

@OneBlue
Copy link
Copy Markdown
Collaborator

@OneBlue OneBlue commented Apr 8, 2026

Summary of the Pull Request

This change adds support for mounting files and non-existing folders as volumes

PR Checklist

  • Closes: Link to issue #xxx
  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • Tests: Added/updated if needed and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated if needed
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

Copilot AI review requested due to automatic review settings April 8, 2026 23:11
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/windows/wslcsession/WSLCContainer.cpp
Comment thread src/windows/wslcsession/WSLCContainer.cpp Outdated
Comment thread localization/strings/en-US/Resources.resw Outdated
Comment thread test/windows/WSLCTests.cpp
Comment thread test/windows/WSLCTests.cpp Outdated
@OneBlue OneBlue marked this pull request as ready for review April 9, 2026 00:34
@OneBlue OneBlue requested a review from a team as a code owner April 9, 2026 00:34
Copilot AI review requested due to automatic review settings April 9, 2026 00:34
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.


VerifyPatternMatch(
wsl::shared::string::WideToMultiByte(comError->Message.get()),
"Failed to create volume '*test-volume\\subfolder': Access is denied. ");
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
"Failed to create volume '*test-volume\\subfolder': Access is denied. ");
"Failed to create volume '*test-volume\\subfolder': Access is denied.*");

Copilot uses AI. Check for mistakes.
for (auto& volume : volumes)
{
// Create a new directory if it doesn't exist.
if (!std::filesystem::exists(volume.HostPath))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is fine now because wslcsession runs as the user.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this is actually very handy

Copilot AI review requested due to automatic review settings April 9, 2026 19:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.

@OneBlue OneBlue merged commit e950342 into feature/wsl-for-apps Apr 9, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants