-
Notifications
You must be signed in to change notification settings - Fork 1.7k
CLI: Relative volume path support, improved error detection and messaging, more volume tests #40193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dkbennett
wants to merge
5
commits into
feature/wsl-for-apps
Choose a base branch
from
user/dkbennett/relativevolumepaths
base: feature/wsl-for-apps
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c9f722d
Implement relative paths and tests
dkbennett ed8ebdd
Merge branch 'feature/wsl-for-apps' into user/dkbennett/relativevolum…
dkbennett db71708
Update localization/strings/en-US/Resources.resw
dkbennett 21605c9
Feedback
dkbennett 4881ce7
Merge branch 'user/dkbennett/relativevolumepaths' of https://github.c…
dkbennett File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -150,13 +150,21 @@ void PublishPort::Validate() const | |
| } | ||
| } | ||
|
|
||
| // Returns true if the given string is a valid Docker named volume name. | ||
| // Based on Docker's named volume validation: ^[a-zA-Z0-9][a-zA-Z0-9_.-]{1,}$ | ||
| // Source: https://github.com/moby/moby/blob/master/volume/validate.go | ||
| bool VolumeMount::IsValidNamedVolumeName(const std::wstring& name) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for adding this validation and the original reference! |
||
| { | ||
| static const std::wregex namedVolumeRegex(LR"(^[a-zA-Z0-9][a-zA-Z0-9_.-]{1,}$)"); | ||
| return std::regex_match(name, namedVolumeRegex); | ||
| } | ||
|
|
||
| VolumeMount VolumeMount::Parse(const std::wstring& value) | ||
| { | ||
| auto lastColon = value.rfind(':'); | ||
| if (lastColon == std::wstring::npos) | ||
| { | ||
| THROW_HR_WITH_USER_ERROR( | ||
| E_INVALIDARG, std::format(L"Invalid volume specifications: '{}'. Expected format: <host path>:<container path>[:mode]", value)); | ||
| THROW_HR_WITH_USER_ERROR(E_INVALIDARG, Localization::WSLCCLI_VolumeInvalidSpec(value, Localization::WSLCCLI_VolumeFormatUsage())); | ||
| } | ||
|
dkbennett marked this conversation as resolved.
|
||
|
|
||
| VolumeMount vm; | ||
|
|
@@ -167,17 +175,13 @@ VolumeMount VolumeMount::Parse(const std::wstring& value) | |
| vm.m_isReadOnlyMode = IsReadOnlyMode(lastToken); | ||
| if (lastColon == 0) | ||
| { | ||
| THROW_HR_WITH_USER_ERROR( | ||
| E_INVALIDARG, | ||
| std::format(L"Invalid volume specifications: '{}'. Expected format: <host path>:<container path>[:mode]", value)); | ||
| THROW_HR_WITH_USER_ERROR(E_INVALIDARG, Localization::WSLCCLI_VolumeInvalidSpec(value, Localization::WSLCCLI_VolumeFormatUsage())); | ||
| } | ||
|
|
||
| splitColon = value.rfind(':', lastColon - 1); | ||
| if (splitColon == std::wstring::npos) | ||
| { | ||
| THROW_HR_WITH_USER_ERROR( | ||
| E_INVALIDARG, | ||
| std::format(L"Invalid volume specifications: '{}'. Expected format: <host path>:<container path>[:mode]", value)); | ||
| THROW_HR_WITH_USER_ERROR(E_INVALIDARG, Localization::WSLCCLI_VolumeInvalidSpec(value, Localization::WSLCCLI_VolumeFormatUsage())); | ||
| } | ||
|
|
||
| vm.m_containerPath = WideToMultiByte(value.substr(splitColon + 1, lastColon - splitColon - 1)); | ||
|
dkbennett marked this conversation as resolved.
|
||
|
|
@@ -187,22 +191,49 @@ VolumeMount VolumeMount::Parse(const std::wstring& value) | |
| vm.m_containerPath = WideToMultiByte(lastToken); | ||
| } | ||
|
|
||
| vm.m_hostPath = value.substr(0, splitColon); | ||
|
|
||
| if (vm.m_hostPath.empty()) | ||
| if (vm.m_containerPath.empty()) | ||
| { | ||
| THROW_HR_WITH_USER_ERROR( | ||
| E_INVALIDARG, | ||
| std::format(L"Invalid volume specifications: '{}'. Host path cannot be empty. Expected format: <host path>:<container path>[:mode]", value)); | ||
| E_INVALIDARG, Localization::WSLCCLI_VolumeContainerPathEmpty(value, Localization::WSLCCLI_VolumeFormatUsage())); | ||
| } | ||
|
|
||
| if (!vm.m_containerPath.empty() && vm.m_containerPath[0] != '/') | ||
| if (vm.m_containerPath[0] != '/') | ||
| { | ||
| THROW_HR_WITH_USER_ERROR( | ||
| E_INVALIDARG, | ||
| std::format(L"Invalid volume specifications: '{}'. Container path must be an absolute path (starting with '/'). Expected format: <host path>:<container path>[:mode]", value)); | ||
| E_INVALIDARG, Localization::WSLCCLI_VolumeContainerPathNotAbsolute(value, Localization::WSLCCLI_VolumeFormatUsage())); | ||
| } | ||
|
|
||
| const auto rawHostPath = value.substr(0, splitColon); | ||
| if (rawHostPath.empty()) | ||
| { | ||
| THROW_HR_WITH_USER_ERROR(E_INVALIDARG, Localization::WSLCCLI_VolumeHostPathEmpty(value, Localization::WSLCCLI_VolumeFormatUsage())); | ||
| } | ||
|
|
||
| // This is where we need to check if the user is referencing a named volume. | ||
| // This can be either an existing named volume or a new named volume that will be created. | ||
| if (VolumeMount::IsValidNamedVolumeName(rawHostPath)) | ||
| { | ||
| // TODO: Handle named volume reference in the request. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for adding this block. I will investigate what is needed to wire this up |
||
| // For now we will ignore this and treat named volumes as a relative path. | ||
|
dkbennett marked this conversation as resolved.
|
||
| } | ||
|
|
||
| // Not a named volume, so it must be a path. | ||
| // Use wil::GetFullPathNameW to resolve relative paths against the CWD. | ||
| std::wstring resolvedHostPath; | ||
| if (FAILED(wil::GetFullPathNameW(rawHostPath.c_str(), resolvedHostPath))) | ||
| { | ||
| THROW_HR_WITH_USER_ERROR(E_INVALIDARG, Localization::WSLCCLI_VolumeHostPathInvalid(value, rawHostPath)); | ||
|
dkbennett marked this conversation as resolved.
|
||
| } | ||
|
|
||
| // GetFileAttributesW validates the resolved path syntax without requiring existence. | ||
| // ERROR_INVALID_NAME indicates illegal characters in the path (e.g. ":" as a component). | ||
| if (GetFileAttributesW(resolvedHostPath.c_str()) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_INVALID_NAME) | ||
| { | ||
| THROW_HR_WITH_USER_ERROR(E_INVALIDARG, Localization::WSLCCLI_VolumeHostPathInvalid(value, rawHostPath)); | ||
|
dkbennett marked this conversation as resolved.
|
||
| } | ||
|
|
||
| vm.m_hostPath = std::move(resolvedHostPath); | ||
|
|
||
| return vm; | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.