remove zombie thumbnails (#657)

remove zombie thumbnails
This commit is contained in:
masavini 2022-12-05 11:31:31 +01:00 committed by GitHub
parent 9c6d13559b
commit 6fd9a7d37f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,3 +1,4 @@
import glob
import json import json
import logging import logging
import os import os
@ -1405,6 +1406,13 @@ def media_file_delete(sender, instance, **kwargs):
helpers.rm_dir(p) helpers.rm_dir(p)
instance.user.update_user_media() 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) @receiver(m2m_changed, sender=Media.category.through)
def media_m2m(sender, instance, **kwargs): def media_m2m(sender, instance, **kwargs):