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}")