fix(decrypt): wrap the yield and cleanup code in try-finally

Without this, the cleanup code won't run after if `sys.exit()` is called when we yield

Signed-off-by: Akhil Narang <me@akhilnarang.dev>
This commit is contained in:
Akhil Narang 2024-01-18 17:37:23 +05:30
parent 53d4153bcd
commit 39be50c773
No known key found for this signature in database
GPG key ID: 9DCC61E211BF645F

View file

@ -661,13 +661,15 @@ def decrypt_backup(file_path: str, passphrase: str):
decrypted_file=file_path,
)
frappe.utils.execute_in_shell(command)
yield
if os.path.exists(file_path + ".gpg"):
if os.path.exists(file_path):
os.remove(file_path)
if os.path.exists(file_path.rstrip(".gz")):
os.remove(file_path.rstrip(".gz"))
os.rename(file_path + ".gpg", file_path)
try:
yield
finally:
if os.path.exists(file_path_with_ext):
if os.path.exists(file_path):
os.remove(file_path)
if os.path.exists(file_path.rstrip(".gz")):
os.remove(file_path.rstrip(".gz"))
os.rename(file_path_with_ext, file_path)
def backup(