From 39be50c773742b39ab10a0b9fa82af2ae501d658 Mon Sep 17 00:00:00 2001 From: Akhil Narang Date: Thu, 18 Jan 2024 17:37:23 +0530 Subject: [PATCH] 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 --- frappe/utils/backups.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/frappe/utils/backups.py b/frappe/utils/backups.py index ac3414d805..295aff2b4d 100644 --- a/frappe/utils/backups.py +++ b/frappe/utils/backups.py @@ -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(