-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
Implement create_dir_all() to operate iteratively instead of recursively #148196
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
base: main
Are you sure you want to change the base?
Implement create_dir_all() to operate iteratively instead of recursively #148196
Conversation
This comment has been minimized.
This comment has been minimized.
|
Why does this need to manipulate a list of |
|
🥴 Answer to jubilee: It's not a reversible iterator!!! |
|
jubilee's counterargument to jubilee's counterargument: Okay, so we'd have to use |
|
Please feel free to question/reject my comment/suggestion if you feel it is incorrect/scope-creeping, I only am bringing it up because I had precisely this thought after wondering why code I had earlier written elsewhere was doing |
|
Followup response to jubilee: what about in the tune of "Khaaan!": RELATIVE PAAATHS! |
|
Hey jubilee, I took your suggestion and iterate through the Ancestors Iterator. One thing that I did differently however is that instead of using Does this approach look good to you? |
|
Yes, allocating once instead of many times sounds like a reasonable improvement in the spirit of my note, so if others are cool with it, then I'm cool! That way it's "just" a classic space vs. time tradeoff and getting the main improvement we're looking for. |
|
Hi @tgross35, I noticed that you were the assignee for this pull request. I wanted to ask if there is anything I should change with this PR/commits or if everything looks alright? |
|
I haven't looked at this yet so I'm going to who has. (I know it's at your limit so feel free to reroll again or throw it back if you want) |
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This now always allocates something on the heap when there's at least two directories that are created. Probably not worth optimizing away.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
r? libs |
|
Reminder, once the PR becomes ready for a review, use |
This comment has been minimized.
This comment has been minimized.
|
r=me with commits squashed into one. I agree that adding the reverse-ancestors would be out of scope for this PR. |
e069969 to
4081c14
Compare
|
|
@Mark-Simulacrum I ended up using git reset to create the combined commits, hope that is alright with you. |
|
@bors r+ |
…dir-all, r=Mark-Simulacrum Implement create_dir_all() to operate iteratively instead of recursively The current implementation of `create_dir_all(...)` in std::fs operates recursively. As mentioned in rust-lang#124309, this could run into a stack overflow with big paths. To avoid this stack overflow issue, this PR implements the method in an iterative manner, preserving the documented behavior of: ``` Recursively create a directory and all of its parent components if they are missing. This function is not atomic. If it returns an error, any parent components it was able to create will remain. If the empty path is passed to this function, it always succeeds without creating any directories. ```
Rollup of 7 pull requests Successful merges: - #146794 (std: reorganize pipe implementations) - #148196 (Implement create_dir_all() to operate iteratively instead of recursively) - #148490 (dangling pointer from temp cleanup) - #149864 (std: Don't use `linkat` on the `wasm32-wasi*` targets) - #149885 (replace addr_of_mut with &raw mut in maybeuninit docs) - #149949 (Cleanup of attribute parsing errors) - #149969 (don't use no_main and no_core to test IBT) Failed merges: - #148847 (Share Timespec between Unix and Hermit) r? `@ghost` `@rustbot` modify labels: rollup
The current implementation of
create_dir_all(...)in std::fs operates recursively. As mentioned in #124309, this could run into a stack overflow with big paths. To avoid this stack overflow issue, this PR implements the method in an iterative manner, preserving the documented behavior of: