Document behavior of create_dir_all wrt. empty path#125112
Conversation
|
rustbot has assigned @Mark-Simulacrum. Use |
|
r? dtolnay - technically a new stable guarantee, I think? So probably needs libs-api FCP. |
|
@rust-lang/libs-api:
fn main() {
let tempdir = tempfile::tempdir().unwrap();
let repro = tempdir.path().join("repro");
std::fs::create_dir(&repro).unwrap();
std::env::set_current_dir(&repro).unwrap();
std::fs::remove_dir(&repro).unwrap();
std::fs::write(&repro, "").unwrap();
std::fs::create_dir_all(&repro).unwrap_err(); // FAIL
std::fs::create_dir_all("").unwrap(); // ok
} |
|
Team member @dtolnay has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
|
Our previous empty paths topic: #114149. In that case we decided not to regard the empty path as current dir for |
|
Interestingly |
I'd add that this case is a bit different, because |
On Linux, $ mkdir .
mkdir: cannot create directory ‘.’: File exists |
|
I think the wording here is a little vague. It says that it always "succeeds," but doesn't say what "succeeds" means. Can we elaborate on what success means for this case? |
The behavior makes sense because `Path::new("one_component").parent() ==
Some(Path::new(""))`, so if one naively wants to create the parent
directory for a file to be written, it simply works.
Closes rust-lang#105108 by documenting the current behavior.
04d2e35 to
6add5c9
Compare
Done. |
|
@tbu- Yeah, that's a good point. Even if we wanted to create the current directory, we can't. |
|
🔔 This is now entering its final comment period, as per the review above. 🔔 |
|
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. This will be merged soon. |
|
@bors r+ rollup |
Rollup of 4 pull requests Successful merges: - rust-lang#125112 (Document behavior of `create_dir_all` wrt. empty path) - rust-lang#126127 (Spell out other trait diagnostic) - rust-lang#126309 (unify git command preperation) - rust-lang#126539 (Update `Arc::try_unwrap()` docs) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#125112 - tbu-:pr_create_dir_all_empty, r=dtolnay Document behavior of `create_dir_all` wrt. empty path The behavior makes sense because `Path::new("one_component").parent() == Some(Path::new(""))`, so if one naively wants to create the parent directory for a file to be written, it simply works. Closes rust-lang#105108 by documenting the current behavior.
The behavior makes sense because
Path::new("one_component").parent() == Some(Path::new("")), so if one naively wants to create the parent directory for a file to be written, it simply works.Closes #105108 by documenting the current behavior.