From 39c09f865a00568bbdefc74a93ffc284187fb8a9 Mon Sep 17 00:00:00 2001 From: AndSDev Date: Tue, 10 Jun 2025 15:13:58 +0300 Subject: [PATCH] refactor: Create the directory for media only if the `directory_structure` is `Deep` --- src/service/media/mod.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/service/media/mod.rs b/src/service/media/mod.rs index 3cececf6..502996e9 100644 --- a/src/service/media/mod.rs +++ b/src/service/media/mod.rs @@ -681,8 +681,10 @@ pub async fn create_file(sha256_hex: &str, file: &[u8]) -> Result<()> { .get_media_path(path, directory_structure, sha256_hex)?; // Create all directories leading up to file - if let Some(parent) = path.parent() { - fs::create_dir_all(&parent).await.inspect_err(|e| error!("Error creating leading directories for media with sha256 hash of {sha256_hex}: {e}"))?; + if let DirectoryStructure::Deep { .. } = directory_structure { + if let Some(parent) = path.parent() { + fs::create_dir_all(&parent).await.inspect_err(|e| error!("Error creating leading directories for media with sha256 hash of {sha256_hex}: {e}"))?; + } } let mut f = File::create(path).await?;