From 6fd9a7d37f2b273b0171ab77af35dde506e2fb2e Mon Sep 17 00:00:00 2001 From: masavini Date: Mon, 5 Dec 2022 11:31:31 +0100 Subject: [PATCH] remove zombie thumbnails (#657) remove zombie thumbnails --- files/models.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/files/models.py b/files/models.py index 66299ea..52c833c 100644 --- a/files/models.py +++ b/files/models.py @@ -1,3 +1,4 @@ +import glob import json import logging import os @@ -1405,6 +1406,13 @@ def media_file_delete(sender, instance, **kwargs): helpers.rm_dir(p) instance.user.update_user_media() + # remove extra zombie thumbnails + if instance.thumbnail: + thumbnails_path = os.path.dirname(instance.thumbnail.path) + thumbnails = glob.glob(f'{thumbnails_path}/{instance.uid.hex}.*') + for thumbnail in thumbnails: + helpers.rm_file(thumbnail) + @receiver(m2m_changed, sender=Media.category.through) def media_m2m(sender, instance, **kwargs):