()
| 108 | const configExists = await fs.access(this.configPath).then(() => true).catch(() => false); |
| 109 | if (!configExists) return; |
| 110 | |
| 111 | const configContent = await fs.readFile(this.configPath, 'utf8'); |
| 112 | JSON.parse(configContent); // 验证JSON格式 |
| 113 | } catch (error) { |
| 114 | console.warn("[zpr] 配置文件损坏,尝试从备份恢复"); |
| 115 | await this.restoreFromBackup(); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | private static async restoreFromBackup(): Promise<void> { |
| 120 | try { |
| 121 | const backupExists = await fs.access(this.backupPath).then(() => true).catch(() => false); |
| 122 | if (backupExists) { |
| 123 | await fs.copyFile(this.backupPath, this.configPath); |
| 124 | console.log("[zpr] 从备份恢复配置成功"); |
no test coverage detected