fix: config migration and CI windows build fixes for opencode (#254)
* Fix windows build * chore: bump version to 0.0.50 * Add config migration for old opencode executor * tolerate bad config files --------- Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
@@ -358,6 +358,7 @@ pub enum ExecutorConfig {
|
||||
ClaudeCodeRouter,
|
||||
#[serde(alias = "charmopencode")]
|
||||
CharmOpencode,
|
||||
#[serde(alias = "opencode")]
|
||||
SstOpencode,
|
||||
// Future executors can be added here
|
||||
// Shell { command: String },
|
||||
@@ -428,7 +429,14 @@ impl ExecutorConfig {
|
||||
dirs::home_dir().map(|home| home.join(".gemini").join("settings.json"))
|
||||
}
|
||||
ExecutorConfig::SstOpencode => {
|
||||
xdg::BaseDirectories::with_prefix("opencode").get_config_file("opencode.json")
|
||||
#[cfg(unix)]
|
||||
{
|
||||
xdg::BaseDirectories::with_prefix("opencode").get_config_file("opencode.json")
|
||||
}
|
||||
#[cfg(not(unix))]
|
||||
{
|
||||
dirs::config_dir().map(|config| config.join("opencode").join("opencode.json"))
|
||||
}
|
||||
}
|
||||
ExecutorConfig::SetupScript { .. } => None,
|
||||
}
|
||||
|
||||
@@ -281,9 +281,26 @@ impl Config {
|
||||
Ok(config)
|
||||
}
|
||||
Err(_) => {
|
||||
// If full deserialization fails, merge with defaults
|
||||
let config = Self::load_with_defaults(&content, config_path)?;
|
||||
Ok(config)
|
||||
// If full deserialization fails, try to merge with defaults
|
||||
match Self::load_with_defaults(&content, config_path) {
|
||||
Ok(config) => Ok(config),
|
||||
Err(_) => {
|
||||
// Even partial loading failed - backup the corrupted file
|
||||
if let Err(e) = Self::backup_corrupted_config(config_path) {
|
||||
tracing::error!("Failed to backup corrupted config: {}", e);
|
||||
}
|
||||
|
||||
// Remove corrupted file and create a default config
|
||||
if let Err(e) = std::fs::remove_file(config_path) {
|
||||
tracing::error!("Failed to remove corrupted config file: {}", e);
|
||||
}
|
||||
|
||||
// Create and save default config
|
||||
let config = Config::default();
|
||||
config.save(config_path)?;
|
||||
Ok(config)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -334,6 +351,21 @@ impl Config {
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a backup of the corrupted config file
|
||||
fn backup_corrupted_config(config_path: &PathBuf) -> anyhow::Result<()> {
|
||||
let timestamp = chrono::Utc::now().format("%Y%m%d_%H%M%S");
|
||||
let backup_filename = format!("config_backup_{}.json", timestamp);
|
||||
|
||||
let backup_path = config_path
|
||||
.parent()
|
||||
.unwrap_or_else(|| std::path::Path::new("."))
|
||||
.join(backup_filename);
|
||||
|
||||
std::fs::copy(config_path, &backup_path)?;
|
||||
tracing::info!("Corrupted config backed up to: {}", backup_path.display());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn save(&self, config_path: &PathBuf) -> anyhow::Result<()> {
|
||||
let content = serde_json::to_string_pretty(self)?;
|
||||
std::fs::write(config_path, content)?;
|
||||
|
||||
Reference in New Issue
Block a user