Skip to content

Attempt to improve the std::fs::create_dir_all docs related to atomicity #141472

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

Merged
merged 1 commit into from
May 26, 2025

Conversation

fluiderson
Copy link
Contributor

@fluiderson fluiderson commented May 23, 2025

The original paragraph was added in #124520. It doesn't match the actual code logic. It says "function returns an error" if "the parent components" (which also implies directories) "have been created already". The code is as follows:

Err(_) if path.is_dir() => return Ok(()),

Err(_) if path.is_dir() => Ok(()),

These lines suppress all errors if any path component is a directory. I've updated the paragraph to mirror this.

@rustbot
Copy link
Collaborator

rustbot commented May 23, 2025

r? @workingjubilee

rustbot has assigned @workingjubilee.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels May 23, 2025
Comment on lines -2806 to -2807
/// If this function returns an error, some of the parent components might have
/// been created already.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old and the new paragraph are about completely different things. The old one is still correct, if an error is encountered it may still have created some of the intermediate directories, i.e. it's not atomic.
E.g. some intermediate path component contains an invalid character or the filesystem becomes full just in the middle of the operation or something like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I thought it says that an error can be returned if some of the parent directories already exist. Perhaps it can be reworded better? For example,

This function is not atomic. In the event of an error, the intermediate parent components that were created will persist.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that's an improvement either.

@workingjubilee
Copy link
Member

workingjubilee commented May 24, 2025

"fix xyz" is often not a useful PR subject as it does not actually specify what you are fixing. there are 40 lines in the docs in question. you are only touching two.

@fluiderson fluiderson changed the title Fix the std::fs::create_dir_all docs Attempt to improve the std::fs::create_dir_all docs related to atomicity May 24, 2025
@fluiderson
Copy link
Contributor Author

I've updated the title, it should reflect the changes more precisely now. As for my proposal to make the paragraph more comprehensive, I think I'm not alone on misinterpreting it. The current text is a bit ambiguous and might be taken as "if this function returns an error, already created directories might be a cause of that error".

@workingjubilee
Copy link
Member

Then specify that the function may create some directories even if it also errors.

@workingjubilee
Copy link
Member

a bit better.

squash commits please?

@workingjubilee
Copy link
Member

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented May 25, 2025

📌 Commit 6d47489 has been approved by workingjubilee

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 25, 2025
jhpratt added a commit to jhpratt/rust that referenced this pull request May 25, 2025
Attempt to improve the `std::fs::create_dir_all` docs related to atomicity

The original paragraph was added in rust-lang#124520. It doesn't match the actual code logic. It says "function returns an error" if "the parent components" _(which also implies directories)_ "have been created already". The code is as follows:

https://github.com/rust-lang/rust/blob/e88e85463468ce5d5ce468414eb69e3b15fa8d42/library/std/src/fs.rs#L3146
https://github.com/rust-lang/rust/blob/e88e85463468ce5d5ce468414eb69e3b15fa8d42/library/std/src/fs.rs#L3160

These lines suppress all errors if any path component is a directory. I've updated the paragraph to mirror this.
bors added a commit that referenced this pull request May 26, 2025
Rollup of 9 pull requests

Successful merges:

 - #134696 (Implement `normalize_lexically`)
 - #138744 (Add methods to TCP and UDP sockets to modify hop limit (refresh of #94678))
 - #140539 (Simplify `attribute_groups`)
 - #140863 ([rustdoc] Unify type aliases rendering with other ADT)
 - #140936 (Clarify WTF-8 safety docs)
 - #140952 (Specify that split_ascii_whitespace uses the same definition as is_ascii_whitespace)
 - #141472 (Attempt to improve the `std::fs::create_dir_all` docs related to atomicity)
 - #141502 (ci: move PR job x86_64-gnu-tools to codebuild)
 - #141559 (const-check: stop recommending the use of rustc_allow_const_fn_unstable)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request May 26, 2025
Rollup of 8 pull requests

Successful merges:

 - #134696 (Implement `normalize_lexically`)
 - #140539 (Simplify `attribute_groups`)
 - #140863 ([rustdoc] Unify type aliases rendering with other ADT)
 - #140936 (Clarify WTF-8 safety docs)
 - #140952 (Specify that split_ascii_whitespace uses the same definition as is_ascii_whitespace)
 - #141472 (Attempt to improve the `std::fs::create_dir_all` docs related to atomicity)
 - #141502 (ci: move PR job x86_64-gnu-tools to codebuild)
 - #141559 (const-check: stop recommending the use of rustc_allow_const_fn_unstable)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit a49ae1c into rust-lang:master May 26, 2025
6 checks passed
@rustbot rustbot added this to the 1.89.0 milestone May 26, 2025
rust-timer added a commit that referenced this pull request May 26, 2025
Rollup merge of #141472 - fluiderson:dev, r=workingjubilee

Attempt to improve the `std::fs::create_dir_all` docs related to atomicity

The original paragraph was added in #124520. It doesn't match the actual code logic. It says "function returns an error" if "the parent components" _(which also implies directories)_ "have been created already". The code is as follows:

https://github.com/rust-lang/rust/blob/e88e85463468ce5d5ce468414eb69e3b15fa8d42/library/std/src/fs.rs#L3146
https://github.com/rust-lang/rust/blob/e88e85463468ce5d5ce468414eb69e3b15fa8d42/library/std/src/fs.rs#L3160

These lines suppress all errors if any path component is a directory. I've updated the paragraph to mirror this.
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this pull request May 30, 2025
Attempt to improve the `std::fs::create_dir_all` docs related to atomicity

The original paragraph was added in rust-lang#124520. It doesn't match the actual code logic. It says "function returns an error" if "the parent components" _(which also implies directories)_ "have been created already". The code is as follows:

https://github.com/rust-lang/rust/blob/e88e85463468ce5d5ce468414eb69e3b15fa8d42/library/std/src/fs.rs#L3146
https://github.com/rust-lang/rust/blob/e88e85463468ce5d5ce468414eb69e3b15fa8d42/library/std/src/fs.rs#L3160

These lines suppress all errors if any path component is a directory. I've updated the paragraph to mirror this.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants