fix(maintenance): confirm before deleting Time Machine snapshots, add --dry-run/--yes - #85
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
Conversation
… --dry-run/--yes maintenance --timemachine deleted every local snapshot immediately, with no confirmation and no dry run, unlike every other destructive path in the CLI. Snapshots are also listed once up front so tmutil output that cannot be parsed is reported instead of being silently reported as 'no snapshots found', and the sudo capability probe now runs tmutil itself so a tmutil-scoped NOPASSWD sudoers entry is detected. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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.
What does this PR do?
Follow-up to #55.
maintenance --timemachinedeleted every local snapshot the moment it was invoked — no confirmation, no dry run, no tests — whileclean(a less consequential operation) has confirm +-y+-d. Local snapshots are the user's only rollback point while the backup disk is disconnected, so this brings it in line:--yesskips the prompt,--dry-runreports[DRY RUN] Would delete N Time Machine snapshotsand spawns nothing.listTimeMachineSnapshotDates) and the dates are passed intoclearTimeMachineSnapshots({ dates, dryRun }), so the prompt isn't drawn over by theoraspinner and tmutil is only invoked once for listing.clearTimeMachineSnapshots()with no arguments still lists on its own, and re-validates any caller-supplied date against the regex before it reachestmutil.Three other bugs in the same module:
^\d{4}-\d{2}-\d{2}-\d{6}$was dropped, so a format/locale change would producesuccess: true, "No Time Machine local snapshots found". Now "output present but nothing recognized" returns a distinctCould not parse tmutil output (N unrecognized line(s)), while genuinely empty output still means no snapshots.sudo -n truefails for a sudoers entry scopedNOPASSWD: /usr/bin/tmutil— the recommended setup — so the tool wrongly claimed it could not delete. It now probessudo -n /usr/bin/tmutil listlocalsnapshotdates.Process exited with code null. On thespawntimeout path Node kills the child andclosefires withcode === null; that branch now reportsTimed out after 60000ms (killed by SIGTERM).Plus docs: README's maintenance section only listed
--dns/--purgeable;--timemachineis now documented with the sudo requirement and the irreversibility caveat.Type of change
Related issue
Follow-up to #55.
Checklist
bun run lintpassesbun run testpasses (361 tests, +17:src/maintenance/timemachine.test.tsis new — date parsing, dry run, invalid dates, sudo-required, partial failure, timeout — plus the--timemachinebranches ofmaintenanceCommand, previously uncovered)bun run buildsucceedsmaintenance --helpshows the new flags and that a missingtmutilsurfaces asFailed to list Time Machine snapshots: tmutil not available.... The real-Mac paths (confirm → delete,--dry-runcount, sudo probe) need one manual run on macOS.Notes for reviewer
Not addressed here, to keep the diff focused:
execCommandnow exists in three near-identical copies (dns-cache.ts,purgeable.ts,timemachine.ts) and only this copy has the timeout fix. Worth extracting into a shared helper, butdns-cache.tsuseschild_process.execrather thanspawnand its tests mockexec, so that consolidation belongs in its own PR.Link to Devin session: https://app.devin.ai/sessions/9d4d3a6c910b43ecb8efd09fe9129ae5
Requested by: @guhcostan