From 488cadb5d9a1914ee3aef26f47b0f3f0c7475c25 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 29 Oct 2026 04:55:27 +0000 Subject: [PATCH] Sonny: restamp finds and edits a systemd trigger too #318's restamp still read the definition through Places::plist, which #344 renamed to Places::job, so main did not compile. The store id it rewrites now has a unit form too, and restamp runs at start on Linux. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013jkdGF2ShRt6WjfWgiPdZF --- sonny/src/trigger.rs | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/sonny/src/trigger.rs b/sonny/src/trigger.rs index 35ed6cacb..b6385e408 100644 --- a/sonny/src/trigger.rs +++ b/sonny/src/trigger.rs @@ -2374,15 +2374,25 @@ pub fn restamp(places: &Places, identity: &str, lineage: &str, launchd: Loader) return; }; // Read again under the lock: an `rm`, `add` or fire may have come first. - let path = places.plist(&trigger.name); + let path = places.job(&trigger.name); let Ok(text) = std::fs::read_to_string(&path) else { continue; }; - let stamped = text.replacen( - &format!("{}", escape(identity)), - &format!("{}", escape(lineage)), - 1, - ); + let stamped = match is_plist(&text) { + true => text.replacen( + &format!("{}", escape(identity)), + &format!("{}", escape(lineage)), + 1, + ), + false => { + let flag = quoted("--store-id", true); + text.replacen( + &format!("{flag} {}", quoted(identity, true)), + &format!("{flag} {}", quoted(lineage, true)), + 1, + ) + } + }; if stamped == text { continue; } @@ -2398,14 +2408,11 @@ pub fn restamp(places: &Places, identity: &str, lineage: &str, launchd: Loader) /// Once Sonny knows its daemon: [`restamp`] the triggers made on its store. pub fn restamp_at_start(identity: Option<&str>, lineage: Option<&str>) { - if !cfg!(target_os = "macos") { - return; - } let (Ok(places), Some(identity), Some(lineage)) = (Places::home(), identity, lineage) else { return; }; let (identity, lineage) = (identity.to_owned(), lineage.to_owned()); - std::thread::spawn(move || restamp(&places, &identity, &lineage, &launchctl)); + std::thread::spawn(move || restamp(&places, &identity, &lineage, &schedule)); } /// What `trigger add` was asked. @@ -4288,7 +4295,12 @@ mod tests { #[test] fn a_trigger_made_by_its_store_file_s_identity_names_its_lineage_instead() { - let w = World::new("restamp"); + for w in [World::new("restamp"), World::systemd("restamp-unit")] { + restamps(w); + } + } + + fn restamps(w: World) { let elsewhere = Trigger { name: "q.other".into(), store_id: "another-store".into(),