Skip to content

Harden update download lifecycle: cleanup and shutdown cancellation - #51

Merged
Balragon merged 2 commits into
mainfrom
codex/harden-update-download-lifecycle
Jul 3, 2026
Merged

Harden update download lifecycle: cleanup and shutdown cancellation#51
Balragon merged 2 commits into
mainfrom
codex/harden-update-download-lifecycle

Conversation

@Balragon

@Balragon Balragon commented Jul 3, 2026

Copy link
Copy Markdown
Owner

Stacked on #49 — merge #49 first; this branch contains its commit, so after #49 is squash-merged this PR should merge cleanly (identical changes on both sides). If GitHub reports conflicts after #49 lands, a trivial rebase resolves them.

What this fixes

1. Downloaded installer accumulation. Nothing ever deleted downloaded setup files, so %LOCALAPPDATA%\iMirror\Updates grew by one setup.exe per update forever. New UpdateService.TryCleanUpDownloadedInstallers() removes leftover .exe / partial .download files, called off the UI thread during the startup update check. Best-effort: a file locked by a still-running installer (the fresh post-update relaunch) is skipped and removed on the next start; unrelated files are untouched.

2. No cancellation path for update work. Checks and downloads used CancellationToken.None, so an in-flight download raced process teardown when the user closed the app mid-download. UpdateController now owns a shutdown CancellationTokenSource; MainWindow.ShutdownApplicationAsync cancels it first thing. The startup delay, update check, and download all observe the token. A canceled install logs and returns false quietly instead of flashing the "Retry" UI on a closing window (UpdateService.DownloadSetupAsync already deletes the partial file on any failure, including cancellation).

Unchanged

  • SHA-256 fail-closed verification in DownloadSetupAsync — untouched.
  • Close iMirror during silent update handoff #48 handoff: download → launch installer (/SILENT ... /IMIRROR_LAUNCH=1) → graceful shutdown — same order; cancellation firing during that shutdown is a no-op since nothing is in flight.
  • UI strings, SettingsWindow, installer script — untouched.

Testing

7 new tests: UpdateService cleanup (removes installer/partial files only, skips locked files without throwing, tolerates a missing directory) and UpdateController cancellation (startup check stops quietly, canceled install returns false without retry UI or shutdown, manual check propagates cancellation to the settings caller). Existing tests updated for the new controller seams.

Validation

  • dotnet build iMirror.sln -c Release — passed, 0 warnings, 0 errors.
  • dotnet test MacMirrorReceiver.Tests\MacMirrorReceiver.Tests.csproj -c Release — passed: 90 tests, 0 failed.

🤖 Generated with Claude Code

Balragon and others added 2 commits July 3, 2026 18:00
Move the update orchestration out of MainWindow into a new
UpdateController: startup/manual update checks, the automatic-notice
policy, download, installer handoff, and the graceful shutdown from #48.
MainWindow keeps only the WPF concerns (update-notice controls, status
text, download-progress text) behind a new IUpdateNoticeView seam, and
ISettingsHost/SettingsWindow are unchanged apart from delegating to the
controller.

UpdateService (SHA-256 fail-closed download) and UpdateLauncher
(/IMIRROR_LAUNCH=1 silent handoff) are reused as-is; no behavior change.
The controller takes injected delegates so it is unit-testable without
WPF; adds 18 UpdateController tests.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Two fixes to the update workflow, built on the UpdateController
extraction (#49):

1. Downloaded installers were never deleted, so
   %LOCALAPPDATA%\iMirror\Updates grew by one setup.exe per update
   forever. UpdateService.TryCleanUpDownloadedInstallers now removes
   leftover .exe/.download files at startup (best-effort; files locked
   by a still-running installer are skipped until the next start).

2. Update checks and installer downloads used CancellationToken.None,
   so an in-flight download raced process teardown when the user closed
   the app. UpdateController now owns a shutdown CancellationTokenSource
   that MainWindow cancels at the start of ShutdownApplicationAsync; a
   canceled install returns quietly without flashing the retry UI.

The SHA-256 fail-closed verification and the #48 installer handoff
(launch installer, then graceful shutdown, relaunch via
/IMIRROR_LAUNCH=1) are unchanged. Adds 7 tests.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Balragon
Balragon merged commit cb66524 into main Jul 3, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant