diff --git a/mediarepo-daemon/mediarepo-core/src/fs/thumbnail_store.rs b/mediarepo-daemon/mediarepo-core/src/fs/thumbnail_store.rs index ce8a414..6a500ea 100644 --- a/mediarepo-daemon/mediarepo-core/src/fs/thumbnail_store.rs +++ b/mediarepo-daemon/mediarepo-core/src/fs/thumbnail_store.rs @@ -95,6 +95,20 @@ impl ThumbnailStore { fs::rename(src_dir, dst_dir).await } + /// Deletes all thumbnails of a parent + #[tracing::instrument(level = "debug")] + pub async fn delete_parent + Debug>(&self, parent: S) -> Result<()> { + let path = PathBuf::from(parent.as_ref()); + + if !path.exists() { + tracing::warn!("directory {:?} doesn't exist", path); + return Ok(()); + } + fs::remove_dir_all(&path).await?; + + Ok(()) + } + /// Returns the size of the folder #[tracing::instrument(level = "debug")] pub async fn get_size(&self) -> RepoResult { diff --git a/mediarepo-daemon/mediarepo-model/src/repo.rs b/mediarepo-daemon/mediarepo-model/src/repo.rs index 18eca9a..f81d37a 100644 --- a/mediarepo-daemon/mediarepo-model/src/repo.rs +++ b/mediarepo-daemon/mediarepo-model/src/repo.rs @@ -148,8 +148,10 @@ impl Repo { #[tracing::instrument(level = "debug", skip(self, file))] pub async fn delete_file(&self, file: File) -> RepoResult<()> { let cd = file.cd().to_owned(); + let cd_string = file.encoded_cd(); file.delete().await?; self.main_storage.delete_file(&cd).await?; + self.thumbnail_storage.delete_parent(&cd_string).await?; Ok(()) }