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:
parent
6541402609
commit
0b5e93eeff
2 changed files with 5 additions and 3 deletions
|
@ -499,9 +499,6 @@ impl Service {
|
||||||
r.push(current_path);
|
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);
|
r.push(filename);
|
||||||
} else {
|
} else {
|
||||||
r.push(sha256_hex);
|
r.push(sha256_hex);
|
||||||
|
|
|
@ -660,6 +660,11 @@ pub async fn create_file(sha256_hex: &str, file: &[u8]) -> Result<()> {
|
||||||
.globals
|
.globals
|
||||||
.get_media_path(path, directory_structure, sha256_hex)?;
|
.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?;
|
let mut f = File::create(path).await?;
|
||||||
f.write_all(file).await?;
|
f.write_all(file).await?;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue