bytecodealliance / bytecodealliance/cap-std

Create directory if not exists, and return `Dir`

Abierto
#372 7 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Rust
Estrellas
821
Forks
57
Merge medio
1 h 16 min
PR fusionados (30 d)
4

Descripción

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?

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.