From 6adeac797ad212c2fb75eb42c3804fecdd92a5cd Mon Sep 17 00:00:00 2001 From: WQJ Date: Sun, 9 Feb 2025 22:36:52 +0800 Subject: [PATCH] =?UTF-8?q?fix(backup):=20=E4=BC=98=E5=8C=96=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=A4=87=E4=BB=BD=E9=80=BB=E8=BE=91=EF=BC=8C=E9=81=BF?= =?UTF-8?q?=E5=85=8D=E9=87=8D=E5=A4=8D=E5=A4=87=E4=BB=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在进行 main.js 和配置文件备份时,先检查备份文件是否存在 - 如果备份文件已存在,则跳过备份步骤 - 这样可以避免重复备份,节省存储空间和提高效率 --- patch_cursor_get_machine_id.py | 6 +++++- reset_machine.py | 13 ++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/patch_cursor_get_machine_id.py b/patch_cursor_get_machine_id.py index 540fcf09..e65e52d7 100644 --- a/patch_cursor_get_machine_id.py +++ b/patch_cursor_get_machine_id.py @@ -215,8 +215,12 @@ def backup_files(pkg_path: str, main_path: str) -> bool: """ try: # 只备份 main.js + backup_main = f"{main_path}.bak" + if os.path.exists(backup_main): + logger.info(f"备份文件已存在,跳过备份步骤: {backup_main}") + return True + if os.path.exists(main_path): - backup_main = f"{main_path}.bak" shutil.copy2(main_path, backup_main) logger.info(f"已备份 main.js: {backup_main}") diff --git a/reset_machine.py b/reset_machine.py index 601dc47f..ce06788a 100644 --- a/reset_machine.py +++ b/reset_machine.py @@ -103,12 +103,15 @@ def reset_machine_ids(self): with open(self.db_path, "r", encoding="utf-8") as f: config = json.load(f) - # 创建备份 + # 只在备份文件不存在时创建备份 backup_path = f"{self.db_path}.backup" - print(f"{Fore.CYAN}{EMOJI['BACKUP']} 创建配置文件备份...{Style.RESET_ALL}") - with open(backup_path, "w", encoding="utf-8") as f: - json.dump(config, f, indent=4) - print(f"{Fore.GREEN}{EMOJI['SUCCESS']} 备份文件已保存至: {backup_path}{Style.RESET_ALL}") + if not os.path.exists(backup_path): + print(f"{Fore.CYAN}{EMOJI['BACKUP']} 创建配置文件备份...{Style.RESET_ALL}") + with open(backup_path, "w", encoding="utf-8") as f: + json.dump(config, f, indent=4) + print(f"{Fore.GREEN}{EMOJI['SUCCESS']} 备份文件已保存至: {backup_path}{Style.RESET_ALL}") + else: + print(f"{Fore.CYAN}{EMOJI['INFO']} 已存在备份文件,跳过备份步骤{Style.RESET_ALL}") # 生成新的ID print(f"{Fore.CYAN}{EMOJI['RESET']} 生成新的机器标识...{Style.RESET_ALL}")