about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2023-07-17 01:32:12 +0300
committerVika <vika@fireburn.ru>2023-07-17 01:53:42 +0300
commitb13b4fc66dd069e6d5263a8f6a9cc9a6da798e27 (patch)
tree813b8fa7f0d9948bf5505a1d966e4e1b2998eded
parent2b59a731eb5099fda4a31922e7b9c44fd9f9ab9d (diff)
downloadkittybox-b13b4fc66dd069e6d5263a8f6a9cc9a6da798e27.tar.zst
database/file: tokio::fs::create_dir_all is idempotent
-rw-r--r--kittybox-rs/src/database/file/mod.rs9
1 files changed, 3 insertions, 6 deletions
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)