bytecodealliance / bytecodealliance/cap-std

Create directory if not exists, and return `Dir`

Open
#372 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
821
Forks
57
Avg merge
1h 16m
Merged PRs (30d)
4

Description

Is there a simple way to create a directory if it does not yet exist and to return the `Dir`?

Something along the lines of:

```rs
async fn create_dir(parent: &Dir, path: &str) -> anyhow::Result {
match parent.create_dir(path) {
Ok(_) => {}
Err(e) => match e.kind() {
std::io::ErrorKind::AlreadyExists => {}
_ => {
Err(e)?;
}
},
}
Ok(parent.open_dir(path).await?) // could maybe be a TOCTOU?
}
```

I couldn't find a `create_dir_with` that would allow specifying e.g. `OpenOptions`, and all the create_dir functions don't return the `Dir` itself.

If not, would the project be open to contributions on this?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.