()
| 171 | try { |
| 172 | await this.db.write(); |
| 173 | console.log("[zpr] 配置保存成功"); |
| 174 | return true; |
| 175 | } catch (writeError: any) { |
| 176 | console.error(`[zpr] 第${attempt}次写入失败:`, writeError); |
| 177 | if (attempt === 5) { |
| 178 | // 最后一次失败,尝试恢复备份 |
| 179 | await this.restoreFromBackup(); |
| 180 | throw writeError; |
| 181 | } |
| 182 | await lifecycleDelay(attempt * 200, "zpr:config-write-retry"); |
| 183 | } |
| 184 | } |
| 185 | return false; |
| 186 | } |
| 187 | |
| 188 | private static async ensureInitialized(): Promise<void> { |
| 189 | // 插件重新加载时强制重新初始化以从磁盘加载最新配置 |
| 190 | if (!this.initialized || !this.db) { |
| 191 | await this.init(); |
| 192 | } |
| 193 | } |
no test coverage detected