Skip to content

Commit 0b1fe69

Browse files
author
超渡法師
committed
fix: remove duplicate id fields, add id validation, handle inline comments
- 🔴 Remove duplicate id: fields caused by sed (compile error) - 🟡 Add validation: disable_on_success without id is rejected at load time - 🟡 Fix id line parser to strip inline comments before matching
1 parent 6dff2e7 commit 0b1fe69

1 file changed

Lines changed: 11 additions & 16 deletions

File tree

src/cron.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,10 @@ pub fn load_usercron_file(path: &Path, configured_platforms: &[&str]) -> Vec<Cro
321321
warn!(index = i, platform = %job.platform, "usercron: platform not configured, skipping");
322322
return false;
323323
}
324+
if job.disable_on_success.is_some() && job.id.is_none() {
325+
warn!(index = i, "usercron: job with disable_on_success must have an id field, skipping");
326+
return false;
327+
}
324328
true
325329
}).map(|(_, job)| job).collect()
326330
}
@@ -758,10 +762,11 @@ fn disable_job_in_usercron(path: &Path, job: &CronJobConfig) -> Result<(), Strin
758762

759763
// Detect id field to identify target job
760764
if line.trim().starts_with("id") {
761-
let value = line
762-
.split('=')
763-
.nth(1)
764-
.map(|v| v.trim().trim_matches('"').trim_matches('\'').to_string());
765+
let value = line.split('=').nth(1).map(|v| {
766+
// Strip inline comments before trimming quotes
767+
let v = v.split('#').next().unwrap_or(v);
768+
v.trim().trim_matches('"').trim_matches('\'').to_string()
769+
});
765770
if value.as_deref() == Some(job_id) {
766771
in_target_job = true;
767772
found = true;
@@ -1482,7 +1487,6 @@ command = "echo"
14821487
let job = CronJobConfig {
14831488
id: None,
14841489
enabled: true,
1485-
id: None,
14861490
schedule: "* * * * *".into(),
14871491
channel: "ch".into(),
14881492
message: "msg".into(),
@@ -1503,7 +1507,6 @@ command = "echo"
15031507
let job = CronJobConfig {
15041508
id: None,
15051509
enabled: true,
1506-
id: None,
15071510
schedule: "* * * * *".into(),
15081511
channel: "ch".into(),
15091512
message: "msg".into(),
@@ -1524,7 +1527,6 @@ command = "echo"
15241527
let job = CronJobConfig {
15251528
id: None,
15261529
enabled: true,
1527-
id: None,
15281530
schedule: "* * * * *".into(),
15291531
channel: "ch".into(),
15301532
message: "msg".into(),
@@ -1545,7 +1547,6 @@ command = "echo"
15451547
let job = CronJobConfig {
15461548
id: None,
15471549
enabled: true,
1548-
id: None,
15491550
schedule: "* * * * *".into(),
15501551
channel: "ch".into(),
15511552
message: "msg".into(),
@@ -1566,7 +1567,6 @@ command = "echo"
15661567
let job = CronJobConfig {
15671568
id: None,
15681569
enabled: true,
1569-
id: None,
15701570
schedule: "* * * * *".into(),
15711571
channel: "ch".into(),
15721572
message: "msg".into(),
@@ -1587,7 +1587,6 @@ command = "echo"
15871587
let job = CronJobConfig {
15881588
id: None,
15891589
enabled: true,
1590-
id: None,
15911590
schedule: "* * * * *".into(),
15921591
channel: "ch".into(),
15931592
message: "msg".into(),
@@ -1609,7 +1608,6 @@ command = "echo"
16091608
let job = CronJobConfig {
16101609
id: None,
16111610
enabled: true,
1612-
id: None,
16131611
schedule: "* * * * *".into(),
16141612
channel: "ch".into(),
16151613
message: "msg".into(),
@@ -1642,7 +1640,6 @@ disable_on_success = "npm test"
16421640
let job = CronJobConfig {
16431641
id: None,
16441642
enabled: true,
1645-
id: Some("test-goal".into()),
16461643
schedule: "*/10 * * * *".into(),
16471644
channel: "123".into(),
16481645
message: "test goal".into(),
@@ -1684,9 +1681,8 @@ disable_on_success = "npm test"
16841681
std::fs::write(&path, content).unwrap();
16851682

16861683
let job = CronJobConfig {
1687-
id: None,
1688-
enabled: true,
16891684
id: Some("test-goal".into()),
1685+
enabled: true,
16901686
schedule: "*/10 * * * *".into(),
16911687
channel: "123".into(),
16921688
message: "test goal".into(),
@@ -1731,9 +1727,8 @@ disable_on_success = "npm test"
17311727
std::fs::write(&path, content).unwrap();
17321728

17331729
let job = CronJobConfig {
1734-
id: None,
1735-
enabled: true,
17361730
id: Some("test-goal".into()),
1731+
enabled: true,
17371732
schedule: "*/10 * * * *".into(),
17381733
channel: "123".into(),
17391734
message: "test goal".into(),

0 commit comments

Comments
 (0)