Expand description
In-place binary upgrade for atomcode.
Flow:
-
Fetch
latest.jsonmanifest (version + per-target sha256/size). -
Detect current platform and pick the matching binary entry.
-
Verify we can write to
current_exe()’s directory — if not, fail with a precise message telling the user to re-run withsudo. -
Download the binary to a sibling temp file, streaming progress.
-
Verify SHA256 against the manifest. Bail (and delete temp) on mismatch — we never touch the live binary until verification passes.
-
Three-way swap to replace the live binary: a.
atomcode→.atomcode.rolling(Windows allows renaming a running exe) b. new binary →atomcode(install the upgrade) c. best-effort: remove old.bak, then.atomcode.rolling→.bakSteps a–b are the critical path; step c is best-effort. If the old
.bakis locked (AV scanner, still-running process, read-only attribute), the upgrade still succeeds — the.rollingfile lingers and is cleaned up on the next upgrade attempt.
Rollback swaps the live binary with .bak in place, so one backup
always points to “the other version” — the user can toggle by
alternating /upgrade and /upgrade rollback.
Structs§
- Applied
Upgrade - Successful apply result — fed into the re-exec handoff so the new process can render a one-time “✓ Upgraded” banner on the welcome screen.
- Binary
Entry - Manifest
- Pending
Upgrade - Pointer record stored at
~/.atomcode/staged/pending.json. Describes a downloaded binary that hasn’t yet been promoted to live. Lifecycle: written byprepare_deferred_upgrade, read (and deleted on success / incremented on failure) byapply_pending_upgrade. - Rollback
Summary - Upgrade
Summary
Enums§
- Upgrade
Event - Streamed progress events from the upgrade/rollback machinery.
Constants§
- ALREADY_
LATEST - Sentinel substring in the “already latest” error so the CLI/TUI layer can render a calm informational message instead of a scary red error. Kept as a plain string to avoid an error-type refactor.
- DOWNLOAD_
BASE - MANIFEST_
URL
Functions§
- apply_
pending_ upgrade - Bootstrap entry point: called once at the very top of
main()BEFORE the tokio runtime, TUI, or any heavy init. Three outcomes: - backup_
path - Sibling path used to stash the previous binary.
- binary_
filename - Release artifact filename for a given version + target, matching
what
scripts/release.shpublishes todist/<version>/. - binary_
url - current_
exe_ path - Path of the running
atomcodeexecutable. Resolved once at the start of an upgrade so we know what to replace. - detect_
target - Return the target tag used in release artifact names
(
darwin-arm64,linux-x64,windows-x64, …). - ensure_
writable - Return
Ok(())iff we can create a file alongsideexe. - fetch_
manifest - Fetch and parse
latest.json. - fetch_
manifest_ if_ newer - Quiet variant of
check_latestused by the hourly background poll. Returns the remote(version, manifest)only when strictly newer thancurrent_version. Separate fromversion_check::check_latestbecause that one only gives back the version string; here we need the full manifest to know the per-target sha256 / size. - prepare_
deferred_ upgrade - Download + verify a new release into
staged_dir()without touching the live binary. Writespending.jsonas the final step so a partial download (crashed mid-stream) doesn’t masquerade as “ready to apply” — the pointer only appears if sha256 passed. - re_
exec_ self - Replace the current process with a fresh invocation of the live binary,
preserving argv, cwd, and env. On Unix this is
execv(same PID, old process image gone). On Windows we spawn a child and exit the parent — a separate PID, but terminal stdio is shared so the user still sees one continuous “session” from their perspective. - read_
pending - Read
pending.jsonif present. Absent file →Ok(None). Corrupt JSON returns an error so callers can delete it and retry;apply_pending_upgradedoes exactly that. - run_
rollback - Three-way swap between the live binary and
.bak, leaving.bakpointing at what was previously live. Calling rollback twice in a row returns you to the original state — intentional, so users can toggle between last-two versions without redownloading. - run_
upgrade - Top-level upgrade driver.
- staged_
dir ~/.atomcode/staged/(or equivalent on Windows). Created on demand byprepare_deferred_upgrade; safe to treat as possibly-missing at read time. Kept under the same root ashistory/recent_dirsso nothing new appears in$HOME.