From d3be4f8b431587b14975d0e595e4131e3c119bdb Mon Sep 17 00:00:00 2001 From: Ogulcan Celik Date: Sun, 14 Jun 2026 20:45:50 +0300 Subject: fix: add best-effort windows plugin support --- src/persist/plugin_registry.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/persist') diff --git a/src/persist/plugin_registry.rs b/src/persist/plugin_registry.rs index 19db842a..b2eaac9f 100644 --- a/src/persist/plugin_registry.rs +++ b/src/persist/plugin_registry.rs @@ -17,6 +17,13 @@ fn save_json_to_path(path: &Path, value: &T) -> st let json = serde_json::to_string_pretty(value)?; let tmp_path = path.with_extension("json.tmp"); std::fs::write(&tmp_path, &json)?; + #[cfg(windows)] + if path.exists() { + if let Err(err) = std::fs::remove_file(path) { + let _ = std::fs::remove_file(&tmp_path); + return Err(err); + } + } if let Err(err) = std::fs::rename(&tmp_path, path) { let _ = std::fs::remove_file(&tmp_path); return Err(err); @@ -234,4 +241,15 @@ mod tests { ); assert!(path.exists()); } + + #[test] + fn save_replaces_existing_registry_file() { + let path = temp_registry_path("replace-existing"); + save_to_path(&path, &[sample_plugin("example.first")]).unwrap(); + save_to_path(&path, &[sample_plugin("example.second")]).unwrap(); + + let loaded = load_from_path(&path); + assert_eq!(loaded.len(), 1); + assert_eq!(loaded[0].plugin_id, "example.second"); + } } -- cgit v1.2.3