From cf5eabb9647e6d53ec29a3f7de599a38dbfd5490 Mon Sep 17 00:00:00 2001 From: Luke Hoersten Date: Tue, 28 Jul 2026 18:09:57 -0500 Subject: Merge the two device state files and reduce mutation The registry (device names) and service-state (sync results) were two JSON files keyed the same way, split only for a TypeScript-compatibility that is moot now that the fabric identity cannot migrate between implementations. Merge them into one devices.json with a DeviceRecord per node, which also removes the parallel-map join in status and collapses the per-command load/store pairs. identity.json stays separate as a write-once secret. Also, from a reduction/immutability review: - Fix with_timeout passing a literal "{what}" instead of the error context - Drop needless mut: CompactDuration and parse_wall_clock become immutable expressions; run_status filters with a predicate instead of a mutator; sync_one extracts write_zone_and_dst; InspectOutcome gains Default plus a failed() constructor - Share a join_ids helper and a devices_path helper; add IdentityReport From; minor combinator tidy-ups 35 unit tests, clippy clean. --- src/controller/mod.rs | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'src/controller/mod.rs') diff --git a/src/controller/mod.rs b/src/controller/mod.rs index c85efdd..739615c 100644 --- a/src/controller/mod.rs +++ b/src/controller/mod.rs @@ -100,7 +100,8 @@ pub enum IdentityStatus { /// Inspects the identity pair on disk. A fabric blob is any k_* file in the /// matter/ KV directory. pub fn identity_status(storage: &Path) -> IdentityStatus { - let identity_exists = identity_path(storage).exists(); + let identity_file = identity_path(storage); + let identity_exists = identity_file.exists(); let fabric_exists = std::fs::read_dir(matter_kv_path(storage)) .map(|entries| { entries.flatten().any(|e| { @@ -119,7 +120,7 @@ pub fn identity_status(storage: &Path) -> IdentityStatus { (false, true) => { IdentityStatus::Inconsistent("fabric storage exists but identity.json is missing") } - (true, true) => match std::fs::read_to_string(identity_path(storage)) + (true, true) => match std::fs::read_to_string(&identity_file) .ok() .and_then(|raw| serde_json::from_str::(&raw).ok()) { @@ -349,8 +350,8 @@ fn ensure_fabric( let identity_file = identity_path(&config.storage_path); let existing = matter.with_state(|state| state.fabrics.iter().map(|f| f.fab_idx()).next()); - let registry: crate::state::NodeRegistry = - state::load_or_default(&state::registry_path(&config.storage_path)); + let registry: crate::state::Devices = + state::load_or_default(&state::devices_path(&config.storage_path)); if let Some(fab_idx) = existing { match std::fs::read_to_string(&identity_file) { @@ -602,13 +603,7 @@ fn prepare_storage_dir(path: &Path) -> anyhow::Result<()> { /// so is safe to claim and tighten. #[cfg(unix)] fn is_our_storage_dir(path: &Path) -> bool { - const MARKERS: [&str; 5] = [ - "identity.json", - "matter", - ".lock", - "nodes.json", - "service-state.json", - ]; + const MARKERS: [&str; 4] = ["identity.json", "matter", ".lock", "devices.json"]; if MARKERS.iter().any(|m| path.join(m).exists()) { return true; } -- cgit v1.2.3