MCPcopy Create free account
hub / github.com/EvoMap/evolver / backupExistingFile

Function backupExistingFile

src/proxy/clientSettings.js:198–219  ·  view source on GitHub ↗
(file)

Source from the content-addressed store, hash-verified

196}
197
198function 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
221function syncClaudeProxySettings(info = {}) {
222 const env = info.env || process.env;

Callers 1

syncClaudeProxySettingsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected