1
0
Fork 0
mirror of https://gitlab.com/famedly/conduit.git synced 2025-06-27 16:35:59 +00:00

fix(service/media): create directory for media file only on new file creation

Any access to a media file created a directory for it, which led to unnecessary operations. Especially if this media file had already been deleted (as well as its directory).
This commit is contained in:
AndSDev 2025-06-06 10:34:02 +03:00
parent 6541402609
commit 0b5e93eeff
2 changed files with 5 additions and 3 deletions

View file

@ -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);

View file

@ -660,6 +660,11 @@ 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 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?;
}