From 73af171830c94382ae3c1c7dbc83e36f77cd80a0 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 27 Aug 2024 01:46:09 +0000 Subject: [PATCH] add config option for pruning missing media Signed-off-by: Jason Volk --- conduwuit-example.toml | 8 ++++++++ src/core/config/mod.rs | 3 +++ src/service/globals/migrations.rs | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/conduwuit-example.toml b/conduwuit-example.toml index 53e9acef..a99aa05c 100644 --- a/conduwuit-example.toml +++ b/conduwuit-example.toml @@ -398,6 +398,14 @@ allow_profile_lookup_federation_requests = true # Disabled by default. #media_compat_file_link = false +# Prunes missing media from the database as part of the media startup checks. This means if you +# delete files from the media directory the corresponding entries will be removed from the +# database. This is disabled by default because if the media directory is accidentally moved or +# inaccessible the metadata entries in the database will be lost with sadness. +# +# Disabled by default. +#prune_missing_media = false + # Checks consistency of the media directory at startup: # 1. When `media_compat_file_link` is enbled, this check will upgrade media when switching back # and forth between Conduit and Conduwuit. Both options must be enabled to handle this. diff --git a/src/core/config/mod.rs b/src/core/config/mod.rs index 12b36a65..8836c2c9 100644 --- a/src/core/config/mod.rs +++ b/src/core/config/mod.rs @@ -293,6 +293,8 @@ pub struct Config { pub media_startup_check: bool, #[serde(default)] pub media_compat_file_link: bool, + #[serde(default)] + pub prune_missing_media: bool, #[serde(default = "Vec::new")] pub prevent_media_downloads_from: Vec, @@ -742,6 +744,7 @@ impl fmt::Display for Config { line("RocksDB Statistics level", &self.rocksdb_stats_level.to_string()); line("Media integrity checks on startup", &self.media_startup_check.to_string()); line("Media compatibility filesystem links", &self.media_compat_file_link.to_string()); + line("Prune missing media from database", &self.prune_missing_media.to_string()); line("Prevent Media Downloads From", { let mut lst = vec![]; for domain in &self.prevent_media_downloads_from { diff --git a/src/service/globals/migrations.rs b/src/service/globals/migrations.rs index 5e078595..3e81340e 100644 --- a/src/service/globals/migrations.rs +++ b/src/service/globals/migrations.rs @@ -833,7 +833,7 @@ async fn handle_media_check( .map_or(false, |md| md.is_symlink()) }; - if !old_exists && !new_exists { + if config.prune_missing_media && !old_exists && !new_exists { error!( media_id = ?encode_key(key), ?new_path, ?old_path, "Media is missing at all paths. Removing from database..."