1use std::io;
2
3use polars_utils::plpath::PlPathRef;
4
5pub fn mkdir_recursive(addr: PlPathRef<'_>) -> io::Result<()> {
6 if let Some(path) = addr.as_local_path() {
7 std::fs::DirBuilder::new().recursive(true).create(
8 path.parent()
9 .ok_or(io::Error::other("path is not a file"))?,
10 )
11 } else {
12 Ok(())
13 }
14}
15
16#[cfg(feature = "tokio")]
17pub async fn tokio_mkdir_recursive(addr: PlPathRef<'_>) -> io::Result<()> {
18 if let Some(path) = addr.as_local_path() {
19 tokio::fs::DirBuilder::new()
20 .recursive(true)
21 .create(
22 path.parent()
23 .ok_or(io::Error::other("path is not a file"))?,
24 )
25 .await
26 } else {
27 Ok(())
28 }
29}