diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-06-14 20:45:50 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-06-14 20:45:59 +0300 |
| commit | d3be4f8b431587b14975d0e595e4131e3c119bdb (patch) | |
| tree | 80bbbbf6c0ab295acb67cf6bdb05cc75f435e3f5 /src/persist/plugin_registry.rs | |
| parent | 54b58bb3452bd493a2881623a01371705ff806f1 (diff) | |
fix: add best-effort windows plugin support
Diffstat (limited to 'src/persist/plugin_registry.rs')
| -rw-r--r-- | src/persist/plugin_registry.rs | 18 |
1 files changed, 18 insertions, 0 deletions
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<T: serde::Serialize + ?Sized>(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"); + } } |
