Browse Source

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).
merge-requests/181/merge
AndSDev 9 months ago committed by Matthias Ahouansou
parent
commit
1f7f74af65
No known key found for this signature in database
  1. 3
      src/service/globals/mod.rs
  2. 7
      src/service/media/mod.rs

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

7
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?;
}

Loading…
Cancel
Save