diff --git a/src/service/globals/mod.rs b/src/service/globals/mod.rs index d634f080..3c2069e6 100644 --- a/src/service/globals/mod.rs +++ b/src/service/globals/mod.rs @@ -499,9 +499,6 @@ impl Service { r.push(current_path); } - // Create all directories leading up to file - fs::create_dir_all(&r).inspect_err(|e| error!("Error creating leading directories for media with sha256 hash of {sha256_hex}: {e}"))?; - r.push(filename); } else { r.push(sha256_hex); diff --git a/src/service/media/mod.rs b/src/service/media/mod.rs index 16060dfb..a7c26dbd 100644 --- a/src/service/media/mod.rs +++ b/src/service/media/mod.rs @@ -631,6 +631,13 @@ pub async fn create_file(sha256_hex: &str, file: &[u8]) -> Result<()> { .globals .get_media_path(path, directory_structure, sha256_hex)?; + // Create all directories leading up to file + if let DirectoryStructure::Deep { .. } = directory_structure { + if let Some(parent) = path.parent() { + fs::create_dir_all(&parent).inspect_err(|e| error!("Error creating leading directories for media with sha256 hash of {sha256_hex}: {e}"))?; + } + } + let mut f = File::create(path).await?; f.write_all(file).await?; }