fix(select_device.ps1): make DTB/logo update atomic with rollback - #192
Open
bhoot1234567890 wants to merge 1 commit into
Open
fix(select_device.ps1): make DTB/logo update atomic with rollback#192bhoot1234567890 wants to merge 1 commit into
bhoot1234567890 wants to merge 1 commit into
Conversation
The Windows selector deleted all root .dtb files and logo.bmp *before*
copying the new set in. If the copy failed partway (disk full, card
pulled, unreadable source, locked file), the boot partition was left
with no DTB files and the device would not boot.
Restructure the apply step to:
1. stage the incoming .dtb + logo into a temp dir (fails fast on a bad
source, before anything on the boot volume is touched);
2. back up the current root .dtb files and logo.bmp;
3. install the staged files over the ones in root;
4. only then remove the superseded old .dtb files.
Wrap the apply in try/catch: on any failure, restore the backup so the
device is returned to its prior bootable state, then exit non-zero. The
rollback is best-effort per file (a single locked/unwritable file cannot
abort it) and also discards any new files the failed install partially
wrote, so root ends up matching its pre-update state. Temp dirs are
cleaned up on both the success and failure paths.
No change to the menu / device-selection logic.
Verified on PowerShell 7.6 with a mock filesystem:
- happy path: new files installed, old superseded files removed, logo
updated, temp dirs cleaned;
- empty source: fails at stage before touching root, exit 1;
- partial install failure (dest unwritable mid-copy): rollback restores
the exact prior file set, discards leftover new files, exit 1.
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.
Problem
select_device.ps1updates the boot partition's DTB + logo files with a delete-then-copy sequence:If the copy fails partway — disk full, card pulled mid-write, unreadable source, or a locked file — the boot partition is left with no DTB files and the device won't boot. For a tool whose whole purpose is keeping the handheld bootable, that's the one gap worth closing.
Fix
Make the apply step atomic with rollback:
.dtb+ logo into a temp dir first — a bad/unreadable source fails here, before anything on the boot volume is touched..dtbfiles andlogo.bmp..dtbfiles.Wrapped in
try/catch: on any failure the backup is restored so the device returns to its prior bootable state, then the script exits non-zero. The rollback is best-effort per file (a single locked/unwritable file can't abort it) and also discards any new files the failed install partially wrote, so root ends up matching its pre-update state. Temp dirs are cleaned up on both success and failure paths.Scope
Only the "Apply changes" section. No change to INI parsing, the menu, or device-selection logic. Behaviour is identical on the happy path; only the failure mode changes (safe rollback instead of a bricked partition).
Testing
Parsed clean with the PowerShell AST parser, then ran the extracted apply block against a mock filesystem on PowerShell 7.6: