in reverie-process/src/fd.rs [393:425]
fn create_dir_all_(path: &mut [libc::c_char], mode: libc::mode_t) -> Result<(), Errno> {
if path.len() == 1 {
return Ok(());
}
// Try creating this directory
match Errno::result(unsafe { libc::mkdir(path.as_ptr(), mode) }) {
Ok(_) => return Ok(()),
Err(Errno::ENOENT) => {}
Err(_) if is_dir(path.as_ptr()) => return Ok(()),
Err(e) => return Err(e),
}
// If it doesn't exist, try creating the parent directory.
with_parent(path, |parent| {
match parent {
Some(p) => create_dir_all_(p, mode),
None => {
// Got all the way to the root without successfully creating any
// child directories. Most likely a permissions error.
Err(Errno::EPERM)
}
}
})?;
// Finally, try creating the directory again after the parent directories
// now exist.
match Errno::result(unsafe { libc::mkdir(path.as_ptr(), mode) }) {
Ok(_) => Ok(()),
Err(_) if is_dir(path.as_ptr()) => Ok(()),
Err(e) => Err(e),
}
}