(file)
| 196 | } |
| 197 | |
| 198 | function backupExistingFile(file) { |
| 199 | try { |
| 200 | if (!file || !fs.existsSync(file)) return null; |
| 201 | const stamp = new Date().toISOString().replace(/[-:]/g, '').replace(/\.\d{3}Z$/, 'Z'); |
| 202 | const backupDir = path.join(path.dirname(file), 'backups'); |
| 203 | fs.mkdirSync(backupDir, { recursive: true }); |
| 204 | for (let i = 0; i < 10; i++) { |
| 205 | const suffix = i === 0 ? '' : `-${i}`; |
| 206 | const backupFile = path.join(backupDir, `settings.json.pre-evomap-proxy-sync-${stamp}${suffix}`); |
| 207 | try { |
| 208 | fs.copyFileSync(file, backupFile, fs.constants.COPYFILE_EXCL); |
| 209 | try { fs.chmodSync(backupFile, 0o600); } catch { /* best-effort */ } |
| 210 | return backupFile; |
| 211 | } catch (err) { |
| 212 | if (!err || err.code !== 'EEXIST') return null; |
| 213 | } |
| 214 | } |
| 215 | return null; |
| 216 | } catch { |
| 217 | return null; |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | function syncClaudeProxySettings(info = {}) { |
| 222 | const env = info.env || process.env; |
no outgoing calls
no test coverage detected