MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / backup_file

Function backup_file

src/agents/mod.rs:1431–1451  ·  view source on GitHub ↗

Copy `path` to ` .bak` if it exists. Used before overwriting a user config so an unexpected change is recoverable (issue #63).

(path: &Path)

Source from the content-addressed store, hash-verified

1429/// Copy `path` to `<path>.bak` if it exists. Used before overwriting a user
1430/// config so an unexpected change is recoverable (issue #63).
1431fn backup_file(path: &Path) -> Result<()> {
1432 if !path.exists() {
1433 return Ok(());
1434 }
1435 let mut backup = path.as_os_str().to_owned();
1436 backup.push(".bak");
1437 let backup = std::path::PathBuf::from(backup);
1438 std::fs::copy(path, &backup).map_err(|e| TraceDecayError::Config {
1439 message: format!(
1440 "failed to back up {} to {}: {e}",
1441 path.display(),
1442 backup.display()
1443 ),
1444 })?;
1445 eprintln!(
1446 "\x1b[32m✔\x1b[0m Backed up {} to {}",
1447 path.display(),
1448 backup.display()
1449 );
1450 Ok(())
1451}
1452
1453/// Write a TOML value to a file, backing up any existing file first.
1454pub fn write_toml_file(path: &Path, value: &toml::Value) -> Result<()> {

Callers 2

write_toml_fileFunction · 0.85
uninstall_mcp_serverFunction · 0.85

Calls 2

existsMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected