Skip to main content

Module update

Module update 

Source
Expand description

Auto-update: poll a GitHub Releases feed, download cargo-dist’s platform installer when a newer semver is available, and re-exec ourselves so the new binary takes over.

The update task in runtime.rs only invokes us when the worker is idle (no job in flight) so generation runs never get killed mid-flow.

All side-effecting bits (HTTP, filesystem writes, process spawn) flow through testable helpers; see apply_with for the seam.

Structs§

ExeReplaceGuard
Windows can’t overwrite a running executable (the file is locked), but it CAN rename it. Parking the running exe under a .old name frees the original path so the cargo-dist installer’s Copy-Item succeeds; the parked file is removed on the next start.
RealRunner

Enums§

CheckOutcome

Traits§

UpdateRunner
Side-effect abstraction for apply_with. The real implementation downloads via HTTP and runs sh / powershell; tests inject a fake that records calls.

Functions§

apply
Apply an update by downloading the cargo-dist installer for the current platform and running it.
apply_with
check
Compare the local version against the feed and decide whether to update.
cleanup_parked_artifact
Remove a leftover parked binary from a previous update. Called on startup; best-effort — a locked or missing file is fine.
cleanup_parked_artifact_for_current_exe
Best-effort startup cleanup for the running process’s own parked artifact. Excluded from coverage: depends on current_exe.
decide
Pure decision function so we can unit-test the prerelease/draft filters without going through HTTP.
fetch_releases
Resolve the feed URL to a JSON document and parse a release list.
installer_asset_name
The cargo-dist installer asset name for the current platform.
parked_artifact_path
Where a parked (renamed-aside) running executable lives: the full original file name with .old appended. with_extension would turn studio-worker.exe into studio-worker.old and risk clobbering an unrelated sibling.
parse_releases
Pure parser separated from the HTTP call so it’s trivially testable.
parse_tag
Parse the version from a release tag. Accepts a bare 1.2.3, a v1.2.3, and the component-prefixed tags release-please / cargo-dist actually push for this repo (studio-worker-v1.2.3). Tries the most-permissive forms in order and returns the first that parses, so a prerelease suffix (...-rc.1) survives — only the <component>-v prefix is stripped, never the version’s own -.
resolve_installer_url
Resolve which installer asset to download for the given release. Pulled out of apply for unit tests.
restart_argv
Compute the (binary, args) tuple we’d re-exec ourselves with. Pure — actual exec lives in restart_self.
restart_self
Replace the current process with a fresh exec of the (now-updated) binary. On unix we use execvp; on Windows we spawn the successor and exit cleanly. Unreachable from tests — covered by integration tests of apply_with instead.