fix: dont panic on hash missing when deleting files (#755)
Signed-off-by: Zomatree <me@zomatree.live>
This commit is contained in:
@@ -11,22 +11,24 @@ 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 {
|
||||||
let count = db
|
if let Some(hash) = &file.hash {
|
||||||
.count_file_hash_references(file.hash.as_ref().expect("no `hash` present"))
|
let count = db
|
||||||
.await?;
|
.count_file_hash_references(hash)
|
||||||
|
|
||||||
// No other files reference this file on disk anymore
|
|
||||||
if count <= 1 {
|
|
||||||
let file_hash = db
|
|
||||||
.fetch_attachment_hash(file.hash.as_ref().expect("no `hash` present"))
|
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// Delete from S3
|
// No other files reference this file on disk anymore
|
||||||
delete_from_s3(&file_hash.bucket_id, &file_hash.path).await?;
|
if count <= 1 {
|
||||||
|
let file_hash = db
|
||||||
|
.fetch_attachment_hash(hash)
|
||||||
|
.await?;
|
||||||
|
|
||||||
// Delete the hash
|
// Delete from S3
|
||||||
db.delete_attachment_hash(&file_hash.id).await?;
|
delete_from_s3(&file_hash.bucket_id, &file_hash.path).await?;
|
||||||
info!("Deleted file hash {}", file_hash.id);
|
|
||||||
|
// Delete the hash
|
||||||
|
db.delete_attachment_hash(&file_hash.id).await?;
|
||||||
|
info!("Deleted file hash {}", file_hash.id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete the file
|
// Delete the file
|
||||||
|
|||||||
Reference in New Issue
Block a user