users: do not fail to remove nonexisting avatars

Configuration changes and manual editions can cause this error, which is
unimportant, so we can ignore it to improve stability.
This commit is contained in:
Lephe 2020-07-20 15:15:14 +02:00
parent c4bfef4765
commit 8f43933521
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
1 changed files with 6 additions and 2 deletions

View File

@ -214,8 +214,12 @@ class Member(User):
db.session.commit()
# Save the new avatar
im.save(V5Config.AVATARS_FOLDER + self.avatar, 'PNG')
# If nothing has failed, remove old one
os.remove(old_avatar)
# If nothing has failed, remove old one (allow failure to regularize
# exceptional situations like missing avatar or folder migration)
try:
os.remove(old_avatar)
except FileNotFoundError:
pass
def get_public_data(self):
""" Returns the public information of the member."""