From 6c2ec64660def187d35c31efee386159a233458f Mon Sep 17 00:00:00 2001 From: mercury Date: Tue, 23 Feb 2021 18:40:50 +0400 Subject: [PATCH] fix rename backup history file #30 --- core/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/__init__.py b/core/__init__.py index 92ada79..870c14c 100644 --- a/core/__init__.py +++ b/core/__init__.py @@ -410,5 +410,9 @@ def write_json_file(data, path): path_backup = path + '.bkp' with open(path_temp, 'w') as f: f.write(json.dumps(data)) # write to temp file to ensure no data loss if exception raised here + try: + os.remove(path_backup) + except OSError: + pass os.rename(path, path_backup) # create backup file in case rename is unsuccessful os.rename(path_temp, path)