Skip to content
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

Fix docs for fs::create_dir_all() #1051

Open
riveroon opened this issue Jan 14, 2023 · 0 comments
Open

Fix docs for fs::create_dir_all() #1051

riveroon opened this issue Jan 14, 2023 · 0 comments

Comments

@riveroon
Copy link

So... correct me if I'm wrong, but fs::create_dir_all()'s docs seems to have a minor issue - it has the wrong behavior documented:

An error will be returned in the following situations: path already points to an existing file or directory.

However, async_std's create_dir_all() uses std's create_dir_all() internally, which does NOT return an error from an existing path:

Recursively create a directory and all of its parent components if they are missing.

and the DirBuilder::create() (which std::fs::create_dir_all() uses internally) states:

It is considered an error if the directory already exists unless recursive mode is enabled.

This can be demonstrated with the following code:

fn main() {
    async_std::task::block_on(async {
        let x = Path::new("./hello/world");
        println!("{:?}", fs::create_dir_all(x).await);
    });
}

Running the above code twice prints Ok(()) twice, instead of printing an Err(...) after an Ok(()).

As a side note, a statement similar to the one in std's create_dir_all() documentation exists, but is phrased ambiguously, making it look like only the parent directory creation is optional when paired with the bad documentation:

Creates a new directory and all of its parents if they are missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant