From b13b4fc66dd069e6d5263a8f6a9cc9a6da798e27 Mon Sep 17 00:00:00 2001 From: Vika Date: Mon, 17 Jul 2023 01:32:12 +0300 Subject: database/file: tokio::fs::create_dir_all is idempotent --- kittybox-rs/src/database/file/mod.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'kittybox-rs/src/database') diff --git a/kittybox-rs/src/database/file/mod.rs b/kittybox-rs/src/database/file/mod.rs index 8514717..fe53ea5 100644 --- a/kittybox-rs/src/database/file/mod.rs +++ b/kittybox-rs/src/database/file/mod.rs @@ -316,9 +316,7 @@ impl Storage for FileStorage { .parent() .expect("Parent for this directory should always exist") .to_owned(); - if !(spawn_blocking(move || parent.is_dir()).await.unwrap()) { - tokio::fs::create_dir_all(path.parent().unwrap()).await?; - } + tokio::fs::create_dir_all(&parent).await?; let mut file = tokio::fs::OpenOptions::new() .write(true) @@ -378,6 +376,7 @@ impl Storage for FileStorage { path.to_path(&self.root_dir) }; + tokio::fs::create_dir_all(path.parent().unwrap()).await?; tracing::debug!("Channels file path: {}", path.display()); let tempfilename = path.with_extension("tmp"); let channel_name = post["properties"]["name"][0] @@ -643,9 +642,7 @@ impl Storage for FileStorage { let temppath = path.with_extension("tmp"); let parent = path.parent().unwrap().to_owned(); - if !spawn_blocking(move || parent.is_dir()).await.unwrap() { - tokio::fs::create_dir_all(path.parent().unwrap()).await?; - } + tokio::fs::create_dir_all(&parent).await?; let mut tempfile = OpenOptions::new() .write(true) -- cgit 1.4.1