[codex] Preserve unrelated crontab entries#38
Merged
Conversation
Use marked Mihoto cron blocks so enable, disable, and status operate on owned entries without replacing unrelated user jobs. Add backup, verification, rollback, and legacy-entry cleanup around crontab writes. Verification: - cargo test cron -- --nocapture - cargo test - cargo fmt --all -- --check - cargo clippy - cargo check --all-targets Co-Authored-By: Codex GPT-5 <noreply@openai.com>
There was a problem hiding this comment.
Pull request overview
This PR hardens mihoro cron management so enabling/disabling auto-update preserves unrelated user crontab lines, using stable Mihoto-owned marker blocks plus migration from legacy “current binary” entries, and adding backup + verification/rollback around writes.
Changes:
- Introduces Mihoto-managed
# mihoto: begin/end auto-updatemarkers and merges/removes only the managed block. - Reads live
crontab -lstate forstatus/enable/disable, with legacy entry migration to prevent duplicates. - Adds pre-write backups and post-write verification with rollback on failure.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+255
to
+267
| fn verify_auto_update_enabled(expected_block: &str, bin_path: &str) -> Result<()> { | ||
| let snapshot = read_current_crontab()?; | ||
| if count_managed_cron_blocks(&snapshot.content) != 1 { | ||
| anyhow::bail!("Expected exactly one mihoto-managed cron block after enable"); | ||
| } | ||
| if !snapshot.content.contains(expected_block) { | ||
| anyhow::bail!("Installed crontab does not contain the expected mihoto cron block"); | ||
| } | ||
| if remove_legacy_current_binary_entries(&snapshot.content, bin_path) != snapshot.content { | ||
| anyhow::bail!("Installed crontab still contains a legacy mihoto cron entry"); | ||
| } | ||
| Ok(()) | ||
| } |
Comment on lines
+238
to
+245
| fn write_crontab_backup(snapshot: &CrontabSnapshot) -> Result<PathBuf> { | ||
| let backup_path = crontab_backup_path(); | ||
| if let Some(parent) = backup_path.parent() { | ||
| fs::create_dir_all(parent)?; | ||
| } | ||
| fs::write(&backup_path, &snapshot.content)?; | ||
| Ok(backup_path) | ||
| } |
Comment on lines
+37
to
+41
| let secs = SystemTime::now() | ||
| .duration_since(UNIX_EPOCH) | ||
| .map(|duration| duration.as_secs()) | ||
| .unwrap_or(0); | ||
| base.join("mihoro").join(format!("crontab-{}.bak", secs)) |
Comment on lines
+206
to
+214
| fn install_crontab(content: &str) -> Result<()> { | ||
| let crontab_file = crontab_path(); | ||
| fs::write(&crontab_file, content)?; | ||
| let status = Command::new("crontab").arg(&crontab_file).status()?; | ||
| if !status.success() { | ||
| anyhow::bail!("Failed to install crontab"); | ||
| } | ||
| Ok(()) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
mihoro cron enableormihoro cron disable.# mihoto: begin/end auto-updatemarkers and migrate exact legacy current-binary entries.mihoro cron status, with backup, post-write verification, and rollback around writes.Closes #2.
Upstream references
cron enableandcron disabledestroy all existing crontab entries spencerwooo/mihoro#196Safety differences from upstream PR #197
crontab -lfailures.Migration, security, and rollback impact
Verification
cargo test cron -- --nocapturecargo testcargo fmt --all -- --checkcargo clippycargo check --all-targets