encrypt/decrypt_file: suppress FileNotFoundError...

when removing a potentially non-existent encryption/decryption target.
This commit is contained in:
Zhiming Wang 2020-11-24 17:22:30 +08:00
parent ef9edf7594
commit 932b5e9eda
No known key found for this signature in database
GPG Key ID: 5B58F95EC95965D8

10
buku
View File

@ -23,6 +23,7 @@ import argparse
import calendar
import cgi
import collections
import contextlib
import json
import logging
import os
@ -236,7 +237,8 @@ class BukuCrypt:
print('File encrypted')
sys.exit(0)
except Exception as e:
os.remove(encfile)
with contextlib.suppress(FileNotFoundError):
os.remove(encfile)
LOGERR(e)
sys.exit(1)
@ -331,11 +333,13 @@ class BukuCrypt:
os.remove(encfile)
print('File decrypted')
except struct.error:
os.remove(dbfile)
with contextlib.suppress(FileNotFoundError):
os.remove(dbfile)
LOGERR('Tainted file')
sys.exit(1)
except Exception as e:
os.remove(dbfile)
with contextlib.suppress(FileNotFoundError):
os.remove(dbfile)
LOGERR(e)
sys.exit(1)