dirname with DOS prefixes#4111
Merged
ethomson merged 4 commits intolibgit2:masterlibgit2/libgit2:masterfrom Feb 10, 2017
Merged
dirname with DOS prefixes#4111ethomson merged 4 commits intolibgit2:masterlibgit2/libgit2:masterfrom
ethomson merged 4 commits intolibgit2:masterlibgit2/libgit2:masterfrom
Conversation
Extract code which determines if a path is at a Windows system's root. This incluses drive prefixes (e.g. "C:\") as well as network computer names (e.g. "//computername/").
Getting the dirname of a filesystem root should return the filesystem root itself. E.g. the dirname of "/" is always "/". On Windows, we emulate this behavior and as such, we should return e.g. "C:/" if calling dirname on "C:/". But we currently fail to do so and instead return ".", as we do not check if we actually have a Windows prefix before stripping off the last directory component. Fix this by calling out to `win32_prefix_length` immediately after stripping trailing slashes, returning early if we have a prefix.
When calling `git_path_dirname_r` on a Win32 prefix, e.g. a drive or network share prefix, we always want to return the trailing '/'. This does not work currently when passing in a path like 'C:', where the '/' would not be appended correctly. Fix this by appending a '/' if we try to normalize a Win32 prefix and there is no trailing '/'.
As of recently, we failed to correctly discover repositories at a
Win32 system root. Instead of aborting the upwards-traversal of
the file system, we were looping infinitely when traversal
started at either a Win32 drive prefix ("C:/") or a network path
("//somehost").
The issue has been fixed, so add a test to catch regressions.
Member
Author
|
Okay, wrapped this up now. This fixes #4106 |
Member
Author
|
By the way, I'm open to bikeshedding on the |
Member
|
Thanks for fixing this. 😀 |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This is part 1/2 of the fix to #4106. I already debugged into the issue and have a fix in mind, but I'm currently stuck at a copy shop and cannot fire up my Windows VM to actually test it. I'll post the second part tomorrow.
The actual problem fixed here is that e.g.
git_path_dirname_r("C:/")returns ".", which is simply wrong. It has been fixed to instead return "C:/". The same for network names ("//networkname/").