feat(fs): atomic writes for JSON and TOML saves\n\n- Introduce atomic_write utility and use it in write_json_file\n- Add write_text_file for TOML/strings and use in Codex paths\n- Reduce risk of partial writes and ensure directory creation
This commit is contained in:
@@ -320,16 +320,16 @@ pub async fn switch_provider(
|
||||
toml::from_str::<toml::Table>(cfg_str)
|
||||
.map_err(|e| format!("config.toml 格式错误: {}", e))?;
|
||||
}
|
||||
std::fs::write(&config_path, cfg_str)
|
||||
crate::config::write_text_file(&config_path, cfg_str)
|
||||
.map_err(|e| format!("写入 config.toml 失败: {}", e))?;
|
||||
} else {
|
||||
// 非字符串时,写空
|
||||
std::fs::write(&config_path, "")
|
||||
crate::config::write_text_file(&config_path, "")
|
||||
.map_err(|e| format!("写入空的 config.toml 失败: {}", e))?;
|
||||
}
|
||||
} else {
|
||||
// 缺失则写空
|
||||
std::fs::write(&config_path, "")
|
||||
crate::config::write_text_file(&config_path, "")
|
||||
.map_err(|e| format!("写入空的 config.toml 失败: {}", e))?;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user