git_repository_init: stop traversing at windows root#5050
Conversation
|
Note that there's at least one other obvious way to fix this, and that's to make This change certainly seems correct, but also risky. It's possibly that other parts of the system may be relying on that behavior. More importantly, though, there's now a single definition of a root path from As a result, I'm not touching |
| * root path length on Windows, where `C:` == `C:/`. | ||
| */ | ||
| if ((len == 1 && parent_path.ptr[0] == '.') || len == root_len+1) { | ||
| if ((len == 1 && parent_path.ptr[0] == '.') || len < root_len + 1) { |
There was a problem hiding this comment.
len <= root_len? A bit easier to read in my opinion. Other than that this fix looks good to me
96e0465 to
abe663b
Compare
Stop traversing the filesystem at the Windows directory root. We were calculating the filesystem root for the given directory to create, and walking up the filesystem hierarchy. We intended to stop when the traversal path length is equal to the root path length (ie, stopping at the root, since no path may be shorter than the root path). However, on Windows, the root path may be specified in two different ways, as either `Z:` or `Z:\`, where `Z:` is the current drive letter. `git_path_dirname_r` returns the path _without_ a trailing slash, even for the Windows root. As a result, during traversal, we need to test that the traversal path is _less than or equal to_ the root path length to determine if we've hit the root to ensure that we stop when our traversal path is `Z:` and our calculated root path was `Z:\`.
abe663b to
45f24e7
Compare
Stop traversing the filesystem at the Windows directory root. We were calculating the filesystem root for the given directory to create, and walking up the filesystem hierarchy. We intended to stop when the traversal path length is equal to the root path length (ie, stopping at the root, since no path may be shorter than the root path).
However, on Windows, the root path may be specified in two different ways, as either
Z:orZ:\, whereZ:is the current drive letter.git_path_dirname_rreturns the path without a trailing slash, even for the Windows root. As a result, during traversal, we need to test that the traversal path is less than or equal to the root path length to determine if we've hit the root to ensure that we stop when our traversal path isZ:and our calculated root path wasZ:\.Without this change, when we're traversing through a nonexistent directory (eg,
Z:\nonexistent), we will never detect the filesystem root (Z:!=Z:\) and loop infinitely.Fixes #5013.