Convert EnsureCaseSensitiveDirectoryRecursive to iterative traversal#40347
Draft
Convert EnsureCaseSensitiveDirectoryRecursive to iterative traversal#40347
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Converts EnsureCaseSensitiveDirectoryRecursive in filesystem.cpp from recursive DFS to an iterative traversal to prevent stack overflows in the WSL service during deep directory upgrades (e.g., during distro import).
Changes:
- Replace recursive depth-first traversal with an explicit stack-based traversal.
- Preserve bottom-up (children-before-parent) case-sensitivity marking and existing retry semantics.
Replace unbounded recursive depth-first traversal with an iterative approach using an explicit stack. A deeply nested directory tree could overflow the thread stack during the recursive calls. The iterative version collects directories in reverse post-order during traversal, then marks them bottom-up (children before parents), preserving the ordering invariant that EnsureCaseSensitiveDirectory relies on for its early-exit optimization. Bug: 61964147, 61974992, 61911308, 61463090 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
4d39623 to
b1eeaa2
Compare
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.
Summary
Converts
EnsureCaseSensitiveDirectoryRecursiveinfilesystem.cppfrom unbounded recursive depth-first traversal to an iterative approach using an explicit work stack.Problem
The recursive implementation of
EnsureCaseSensitiveDirectoryRecursivehas no depth limit — a deeply nested directory tree (e.g.node_modules) can exhaust the service thread stack.Fix
EnsureCaseSensitiveDirectory)wil::unique_hfilevector; raw handles used as non-owning references in work stacks