fix: dont panic on hash missing when deleting files (#755)

Signed-off-by: Zomatree <me@zomatree.live>
This commit is contained in:
Angelo Kontaxis
2026-05-17 18:59:56 +01:00
committed by GitHub
parent 19ee535f45
commit c902077cf5

View File

@@ -11,14 +11,15 @@ pub async fn task(db: Database) -> Result<()> {
let files = db.fetch_deleted_attachments().await?; let files = db.fetch_deleted_attachments().await?;
for file in files { for file in files {
if let Some(hash) = &file.hash {
let count = db let count = db
.count_file_hash_references(file.hash.as_ref().expect("no `hash` present")) .count_file_hash_references(hash)
.await?; .await?;
// No other files reference this file on disk anymore // No other files reference this file on disk anymore
if count <= 1 { if count <= 1 {
let file_hash = db let file_hash = db
.fetch_attachment_hash(file.hash.as_ref().expect("no `hash` present")) .fetch_attachment_hash(hash)
.await?; .await?;
// Delete from S3 // Delete from S3
@@ -28,6 +29,7 @@ pub async fn task(db: Database) -> Result<()> {
db.delete_attachment_hash(&file_hash.id).await?; db.delete_attachment_hash(&file_hash.id).await?;
info!("Deleted file hash {}", file_hash.id); info!("Deleted file hash {}", file_hash.id);
} }
}
// Delete the file // Delete the file
db.delete_attachment(&file.id).await?; db.delete_attachment(&file.id).await?;