[TrackerIcon] Fixed old-large icon removal

After downloading and resizing the new icon, we try to remove the downloaded
file, which is larger, but it fails because it tries to do so when the file
is still open, and therefor locked.
On close of the UI, we got `PermissionError` exceptions for each new icon.
This commit is contained in:
DjLegolas 2022-01-05 02:08:35 +02:00 committed by Calum Lind
commit fca08cf583
No known key found for this signature in database
GPG key ID: 90597A687B836BA3

View file

@ -479,14 +479,17 @@ class TrackerIcons(Component):
# Requires Pillow(PIL) to resize. # Requires Pillow(PIL) to resize.
if icon and Image: if icon and Image:
filename = icon.get_filename() filename = icon.get_filename()
remove_old = False
with Image.open(filename) as img: with Image.open(filename) as img:
if img.size > (16, 16): if img.size > (16, 16):
new_filename = filename.rpartition('.')[0] + '.png' new_filename = filename.rpartition('.')[0] + '.png'
img = img.resize((16, 16), Image.ANTIALIAS) img = img.resize((16, 16), Image.ANTIALIAS)
img.save(new_filename) img.save(new_filename)
if new_filename != filename: if new_filename != filename:
os.remove(filename) remove_old = True
icon = TrackerIcon(new_filename) if remove_old:
os.remove(filename)
icon = TrackerIcon(new_filename)
return icon return icon
def store_icon(self, icon, host): def store_icon(self, icon, host):