You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
create_dir_all("") should complain about invalid filename #105108
$ cargo runthread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', src/main.rs:2:29
I would expect to see the same message from create_dir_all
fn create_dir_all(&self, path: &Path) -> io::Result<()> { if path == Path::new("") { return Ok(()); } on line 2393 in the fs module
I think you're right in that the proper behaviour would be just to produce an error message in the
same way as posix utils. I don't know why this check exists, it doesn't seem to produce anything.
Since Path::new("abc").parent() == Some(Path::new("")), it makes sense for create_dir_all to succeed in this case. I'd say this needs documentation at most.
Activity
rosik commentedon Nov 30, 2022
P.S.
std::fs::create_dir("")is fine:I would expect to see the same message from
create_dir_alledneedham commentedon Dec 1, 2022
Here is what I have found:
fn create_dir_all(&self, path: &Path) -> io::Result<()> { if path == Path::new("") { return Ok(()); }on line 2393 in the fs moduleI think you're right in that the proper behaviour would be just to produce an error message in the
same way as posix utils. I don't know why this check exists, it doesn't seem to produce anything.
ChrisDenton commentedon Dec 1, 2022
For some history see #23383. Though a lot has changed in 7 years.
edneedham commentedon Dec 1, 2022
Thanks for the info, Chris.
tbu- commentedon May 14, 2024
Since
Path::new("abc").parent() == Some(Path::new("")), it makes sense forcreate_dir_allto succeed in this case. I'd say this needs documentation at most.Document behavior of `create_dir_all` wrt. empty path
Document behavior of `create_dir_all` wrt. empty path
Rollup merge of rust-lang#125112 - tbu-:pr_create_dir_all_empty, r=dt…
Unrolled build for rust-lang#125112