From b6a3ab5edb76597d0f64cbb8a4f8a33fa4a44a0b Mon Sep 17 00:00:00 2001 From: Songlin Yang <511121939@qq.com> Date: Thu, 5 Mar 2026 06:39:32 +0800 Subject: [PATCH] opt: remove timestamped config file backup (#7618) Signed-off-by: lsytj0413 <511121939@qq.com> --- crates/goose/src/config/base.rs | 48 +-------------------------------- 1 file changed, 1 insertion(+), 47 deletions(-) diff --git a/crates/goose/src/config/base.rs b/crates/goose/src/config/base.rs index aec6f3b329..dbfa787496 100644 --- a/crates/goose/src/config/base.rs +++ b/crates/goose/src/config/base.rs @@ -452,15 +452,6 @@ impl Config { paths.push(self.config_path.with_file_name(backup_name)); } - // Timestamped backups - for i in 1..=5 { - if let Some(file_name) = self.config_path.file_name() { - let mut backup_name = file_name.to_os_string(); - backup_name.push(format!(".bak.{}", i)); - paths.push(self.config_path.with_file_name(backup_name)); - } - } - paths } @@ -529,9 +520,6 @@ impl Config { return Ok(()); } - // Rotate existing backups - self.rotate_backups()?; - // Create new backup if let Some(file_name) = self.config_path.file_name() { let mut backup_name = file_name.to_os_string(); @@ -549,40 +537,6 @@ impl Config { Ok(()) } - // Rotate backup files to keep the most recent ones - fn rotate_backups(&self) -> Result<(), ConfigError> { - if let Some(file_name) = self.config_path.file_name() { - // Move .bak.4 to .bak.5, .bak.3 to .bak.4, etc. - for i in (1..5).rev() { - let mut current_backup = file_name.to_os_string(); - current_backup.push(format!(".bak.{}", i)); - let current_path = self.config_path.with_file_name(¤t_backup); - - let mut next_backup = file_name.to_os_string(); - next_backup.push(format!(".bak.{}", i + 1)); - let next_path = self.config_path.with_file_name(&next_backup); - - if current_path.exists() { - let _ = std::fs::rename(¤t_path, &next_path); - } - } - - // Move .bak to .bak.1 - let mut backup_name = file_name.to_os_string(); - backup_name.push(".bak"); - let backup_path = self.config_path.with_file_name(&backup_name); - - if backup_path.exists() { - let mut backup_1_name = file_name.to_os_string(); - backup_1_name.push(".bak.1"); - let backup_1_path = self.config_path.with_file_name(&backup_1_name); - let _ = std::fs::rename(&backup_path, &backup_1_path); - } - } - - Ok(()) - } - pub fn all_secrets(&self) -> Result, ConfigError> { let mut cache = self.secrets_cache.lock().unwrap(); @@ -1488,7 +1442,7 @@ mod tests { // Should have backups but not more than our limit let existing_backups: Vec<_> = backup_paths.iter().filter(|p| p.exists()).collect(); assert!( - existing_backups.len() <= 6, + existing_backups.len() == 1, "Should not exceed backup limit" ); // .bak + .bak.1 through .bak.5