Repository navigation
Refuse backups when a folder with recorded archives is missing - #791
Conversation
When an installation or world backups folder was missing (for example on an unmounted drive or moved directory) while its parent path remained writable, creating a new backup recreated the output folder to write the new archive. The subsequent prune checked archive state on the now-existing folder, saw the file missing and the parent folder present, and classified the older archive as gone rather than unreachable, dropping its record. Capture archive states before compression creates the output directory in both makeInstallationBackup and makeWorldBackup, and pass them to pruneOldestBackups so that recreated folders do not drop older records. Fixes #748
Pixnop
left a comment
There was a problem hiding this comment.
I reviewed e8c709a7 against dev adab6b96: ran your new tests against dev's code, then backed up twice in a row, and two worlds in a row, with the Backups folder missing.
This PR does what I suggested in #748, and that suggestion was wrong. The states taken before the compression only last for the prune of that one backup. The folder the compression creates is still there afterwards, so the next backup can no longer tell a missing drive from deleted archives. Sorry for sending you down that road. Two things have to change before this goes in.
Blocking
The next backup still drops the old records
initialStates is computed once per call (backup.ts:270) and only reaches that call's prune (backup.ts:283). The compression worker creates the output folder (compression.ts:168), and the folder stays. On the next backup, archiveState (backup.ts:117-125) finds the archive missing and its folder present, says "gone", and the record comes off.
Scenario: the drive holding the Backups folder is not mounted, so its mount point is an empty folder. Backup 1 recreates Backups/Installations/<name> there, and the old rows survive thanks to this PR. Backup 2 drops them. It can come soon: with automatic backups on, Play makes one first (useLaunchGame.ts:130-131). A test that makes two backups through makeInstallationBackup, with a fake archiver that creates the output folder and a limit of 3, gets [] for the first deletedBackupIds and ["old"] for the second.
World backups lose other worlds' records on their very first backup
Every world backup of every Installation goes into one folder, join(config.backupsFolder, "Worlds") (worldsHandlers.ts:226), but initialStates only covers the world being backed up (worldsHandlers.ts:230). With that folder missing, a backup of world A recreates it. The first backup of world B then reads B's old archives as gone and drops them. The same goes for the worlds of another Installation. I added that case to worldsHandlers.test.ts: two worlds, an old backup of B in the missing Worlds folder, a backup of A then of B. rb.deletedBackupIds comes back with B's old record in it.
A direction
Once the folder has been recreated, nothing on disk tells the two cases apart, so the state can't be carried inside one call. I think the fix is to not recreate it while the config still points into it. Before compressing, if the output folder is missing and a listed backup has its archive in that folder (for worlds: any world backup in Worlds, from any Installation), refuse the backup with a reason the renderer can show, something like "This Installation's Backups folder is missing. Put it back or mount the drive, or delete the backups listed from it." That also keeps archives from landing on the wrong drive under an empty mount point.
A few things to keep in mind:
- The check has to be on the records, not on the Backups root alone. The default
RiftLauncherBackupsfolder is never created up front, so a first backup into a folder that does not exist yet is normal and must still work. - Deleting a row whose archive is missing already works (
backupDeletion.ts:39-43), so the player always has a way out. - With automatic backups on, Play treats any refusal other than
compress-failedas a hard stop (useLaunchGame.ts:137-139). The new reason should get the "launch without a backup" question, or a missing drive blocks Play. archiveStatescan then go away, and #610 keeps working as it does on dev: an archive deleted from a folder that is still there is still dropped.
Tests
Two of the three new tests pass on dev's code, so they don't hold the fix:
tests/domain/installations/backup.test.ts, "keeps older backups whose folder went missing when compression recreates the folder (#748)": the fake still reports the folder as absent after the compression. For any path under/backups/Installations/,existsreturnspresent.has(path)(line 34), andpresentis empty, so the folder never comes back.tests/renderer-dom/useMakeInstallationBackup.test.tsx, "keeps older backups whose folder was missing before the backup": oncefolderRecreatedis set,checkPathExistsreturns true for every path under/parent/drive/Backups(line 270), the old archive included. The old archive reads as on disk again, which is the drive coming back rather than an empty folder being recreated.
The world test in worldsHandlers.test.ts does fail on dev, so that one is a real catch. Whatever the fix ends up being, the two-backup and two-world cases above are the tests I'd want next to it.
Not blocking
- If
archiveStatesstays, one shape would do. The array form depends on the caller passing the samebackupsarray in the same order, and aReadonlyMapkeyed by id covers both callers. InworldsHandlers.tsthe inlineexistsand the copied record repeat thefileSystemobject and mapping built a few lines below.
Translation statusen-US is the source and carries 962 keys.
The links open the strings Weblate marks Needs editing for each language: the machine drafts made before Weblate, plus any string whose English changed since it was translated. See #496. |
|
Regression tests cover two backup attempts, two worlds in different installations, and the Play prompt. Typecheck, lint, formatting, unpacked build and coverage passed locally (5,915 passed, 4 skipped). CI is running on this commit. |
Pixnop
left a comment
There was a problem hiding this comment.
I reviewed 595f3477 against e8c709a7: read the whole PR again, ran the four new tests against dev's code, took each fix back out one at a time to see which test goes red, and backed up two Installations that share a backup folder with a fake that creates the folder on compression.
Round one
The second backup no longer drops the old rows. The check at backup.ts:263 refuses before a name is picked or anything is compressed, inside the try, so the lease, the close guard and _backuping are all released. backup.test.ts:394 and useMakeInstallationBackup.test.tsx:249 fail on dev and fail again when I remove that line.
World backups no longer lose other records. worldsHandlers.ts:228-236 checks the world backups of every Installation. worldsHandlers.test.ts:773 fails on dev, and fails when I narrow the check to the Installation being backed up.
A first backup into a folder that does not exist yet still works. The check is on the records, and the existing archiving and first world backup tests pass.
Play offers to launch without a backup. useLaunchGame.ts:138, held by launchPlayGame.test.tsx:569 (see note 2).
archiveStates is gone and #610 behaves as on dev. The test at backup.test.ts:292 passes. My optional note on its shape is moot.
Approving. Thanks for taking the new direction this cleanly.
Not blocking
- Two Installations that share a backup folder can still lose rows. The folder is
Installations/<cleanFolderName(name)>, and names are not unique ("Survival" twice, or "Survival 1" and "Survival:1"). With the drive gone, an Installation with no rows in that folder passes the check and recreates it, and the other one's next backup drops its rows. I reproduced it with the realmakeInstallationBackup:deletedBackupIdscame back as["old-a"]. Passing every Installation'sbackupstoisRecordedBackupFolderUnavailable, as the world handler does, closes it, with a test of two snapshots sharing a name. - The Play test passes on dev.
checkPathExistsatlaunchPlayGame.test.tsx:584answers true for every candidate archive, so without the refusal the backup fails ascompress-failed("No free archive name") and the same prompt shows. Answering false for anything underoutputFolderwould make it hold the refusal too. - The world refusal can point at rows this page does not list.
ManageInstallationWorlds.tsx:85reuses the installation message, but the refusal can come from another Installation's world backups, as in your own test. Afeatures.worlds.error.backup-folder-unavailablekey that mentions every Installation's Worlds page would also drop that special case. - The new string reads differently from its neighbours. They all open with "No backup made:", and the ones that name the folder say "Backups folder". Something like "No backup made: the folder this Installation's backups are in is missing. Reconnect the drive or put the folder back, or delete the backups listed from it." with fr-FR to match.
docs/contribute/translation-status.md conflicts with #797 and #803. #793 merges cleanly but leaves the table stale. Whichever lands second needs to regenerate it.
Summary
A missing backup folder can be an unmounted drive. Recreating it while old archives are listed lets a later backup mistake those archives for deleted files. Refuse to recreate that folder while any installation has records pointing into it. This covers both the shared Worlds folder and installations whose names produce the same backup folder. A first backup into a new folder still works. Play offers to continue without a backup after the refusal.
Type
Testing
Covered repeated installation backups, two installations with the same backup folder, worlds in different installations and the Play prompt. Local typecheck, lint, formatting, coverage and unpacked build passed. Coverage: 305 files, 5,973 tests passed, 4 skipped.
Related issues
Fixes #748