Repository navigation
pitis/perch#20: Settings can restore a JSON backup, keeping a copy of the current data first - #29
Conversation
…a first Restore… in Settings › Your data reads a file made by Export JSON…, refuses anything that isn't a Perch backup before asking, then confirms that it replaces everything. The current data is written beside store.json as store.before-restore-<time>.json first, and if that fails nothing changes. A focus timer that was running in the backup comes back paused. The settings snapshot is taller so it shows the Your data section.
…replacing anything Restore now writes the backup to the store before swapping it in, so a failed save leaves everything as it was instead of saying Restored and losing it at the next launch. The safety copy keeps a running focus timer's time, reminders that came due before the restore don't ring again, and restored screenshot and Calendar settings apply right away. The confirmation shows how many tasks and note days the backup has next to what's there now, and the messages say what failed.
ReviewRan Fixed
Declined
Needs your decision: how restore should work with Reminders syncWith sync on, the next sync, about 2 s later, partly undoes the restore.
Options:
|
…-20-restore-backup # Conflicts: # Sources/Perch/Snapshot.swift
Reminders sync stays this Mac's setting through a restore. While it's on, the restored tasks count as the newest edit and are pushed to Reminders, a task whose reminder was deleted since the backup is made again instead of deleted, and reminders for tasks added since the backup are removed. The confirmation says so.
…ven with sync off A restored task keeps the reminder its current copy is linked to, so a backup saved before sync was on no longer deletes and recreates every reminder. The backup wins once this Mac has synced at all, not only while sync is on, so turning sync back on later doesn't undo it.
Restore and Reminders sync: option ADecision: the restored backup wins over the Perch list in Reminders. This is in the last two commits on this branch.
Tests: Review of the change
|


Refs #20
Refs, notCloses: this hasn't been run in the real app yet (see Not tested). After the merge, #20 moves fromgaptoverify.What changed
tasks), Settings says so ("… isn't a Perch backup. Nothing was changed.") and stops before asking anything.Workspace.restore(_:keepingCopyIn:)writes the current data beside the store asstore.before-restore-<time>.json. It uses the export format, so Restore can load that copy too. If the copy can't be written, the restore throws and nothing changes. Then it replaces the data and saves right away. Settings shows where the copy went.recoverFocusAfterLaunch). Otherwise it would count all the time since the backup was made.Storewrites the copy's file name with the same helper as the existingcorrupt-<time>copy.product.md: restore moves from "not built" to "written, but not tried for real".Clips aren't touched: they stay outside
AppDataand the backup.Worth knowing
How it was tested
make check: 44 tests pass. Three new tests inStoreTests:testRestoreKeepsACopyOfTheCurrentDataThenReplacesIt: the copy decodes back to the old data, the data is replaced, and a timer running in the backup comes back paused.testRestoreChangesNothingIfTheCopyCantBeWrittentestFilesThatArentBackupsAreRejected: an empty file, non-JSON,[],{},tasksof the wrong type, and a task without an id all throwDecodingError, which the Settings message depends on. An export round-trips.restore).swift buildandPerch --snapshotfor the before/after Settings screenshots, posted as a comment.Not tested
store.before-restore-*.jsonexists. Then try a non-backup.jsonfile and check that it's refused.