Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 1 addition & 47 deletions crates/goose/src/config/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,15 +452,6 @@ impl Config {
paths.push(self.config_path.with_file_name(backup_name));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep legacy .bak.N files in recovery search order

try_restore_from_backup now only checks the single .bak path because get_backup_paths no longer includes .bak.1-.bak.5, which regresses recovery for users upgrading from versions that already created those files. In the scenario where .bak is missing/corrupted but a legacy .bak.1 is still valid, load_values_with_recovery will now fall through to creating a fresh default config and silently discard recoverable settings; keeping legacy backup paths for reads (even if you stop writing them) avoids this data-loss path.

Useful? React with 👍 / 👎.

}

// 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
}

Expand Down Expand Up @@ -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();
Expand All @@ -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(&current_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(&current_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<HashMap<String, Value>, ConfigError> {
let mut cache = self.secrets_cache.lock().unwrap();

Expand Down Expand Up @@ -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

Expand Down