src.nth.io/

summaryrefslogtreecommitdiff
path: root/src/controller/mod.rs
diff options
context:
space:
mode:
authorLuke Hoersten <[email protected]>2026-07-28 18:09:57 -0500
committerLuke Hoersten <[email protected]>2026-07-28 18:09:57 -0500
commitcf5eabb9647e6d53ec29a3f7de599a38dbfd5490 (patch)
tree89fcd6f00437c168f042760cc605277a957efc16 /src/controller/mod.rs
parent4129dcaeceab060d9f1cac599e9e29cab0f44fd7 (diff)
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.
Diffstat (limited to 'src/controller/mod.rs')
-rw-r--r--src/controller/mod.rs17
1 files changed, 6 insertions, 11 deletions
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::<Identity>(&raw).ok())
{
@@ -349,8 +350,8 @@ fn ensure_fabric<C: Crypto>(
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;
}