Skip to content

Commit

Permalink
fix(backup): 优化文件备份逻辑,避免重复备份
Browse files Browse the repository at this point in the history
- 在进行 main.js 和配置文件备份时,先检查备份文件是否存在
- 如果备份文件已存在,则跳过备份步骤
- 这样可以避免重复备份,节省存储空间和提高效率
  • Loading branch information
wqjuser committed Feb 9, 2025
1 parent 3becf9d commit 6adeac7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
6 changes: 5 additions & 1 deletion patch_cursor_get_machine_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

Expand Down
13 changes: 8 additions & 5 deletions reset_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down

0 comments on commit 6adeac7

Please sign in to comment.