-
Notifications
You must be signed in to change notification settings - Fork 5.2k
fix: CreateSubdirectory failing for root directories #121906
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
Neo-vortex
wants to merge
6
commits into
dotnet:main
Choose a base branch
from
Neo-vortex:fix-directory-creating-root-folder
base: main
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
fix: CreateSubdirectory failing for root directories #121906
Neo-vortex
wants to merge
6
commits into
dotnet:main
from
Neo-vortex:fix-directory-creating-root-folder
+75
−0
Conversation
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
Path.TrimEndingDirectorySeparator preserves trailing separators for root paths like "C:\" or "/", causing boundary validation to check the wrong index. Added explicit trim of trailing separator from trimmedCurrentPath to fix the boundary check for root directory cases. Signed-off-by: Mohamadreza Nakhleh <[email protected]>
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-io |
Signed-off-by: Mohamadreza Nakhleh <[email protected]>
Contributor
that can be a test case |
Signed-off-by: Mohamadreza Nakhleh <[email protected]>
Contributor
Author
|
I added a test |
Signed-off-by: Mohamadreza Nakhleh <[email protected]>
…ortex/runtime into fix-directory-creating-root-folder
Contributor
Author
|
it seems Linux is also effected. var dir = new DirectoryInfo("/");
dir.CreateSubdirectory("test");I added a test for linux as well |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
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.
fixes #116087
Fix CreateSubdirectory failing for root directories
Summary
Fixes a bug where
DirectoryInfo.CreateSubdirectory(path)incorrectly throwsArgumentExceptionwhen called on root directory instances (e.g.,C:\).Problem
Path.TrimEndingDirectorySeparatorpreserves trailing separators for root paths to maintain valid path format. This causes the boundary validation logic to use an incorrect index when checking for directory separators.Example failure:
The check at index
[3]evaluates the character't'instead of the separator'\'at index[2], causing validation to fail.Solution
After calling
Path.TrimEndingDirectorySeparator, explicitly check iftrimmedCurrentPathstill has a trailing separator (root directory case) and remove it manually before performing boundary validation.This ensures consistent behavior:
trimmedCurrentPathnever ends with a separator, making the boundary index check work correctly for all directory types.Impact
C:\,D:\, )Testing