banger/internal/system
Thales Maciel fa3a7a3e31
system: add AtomicReplace + Rollback for binary swap
Prerequisite for `banger update`'s swap step. The updater renames a
staged binary into place and needs (a) atomicity per file (no
half-written bytes for a process that's about to systemctl restart
into the new binary) and (b) a backup it can restore from when
post-restart doctor reports FAIL.

  * AtomicReplace(newSrc, dst, suffixPrevious): if dst exists,
    move it to dst+suffixPrevious. Then os.Rename newSrc → dst.
    Atomic on a single fs (the only case relevant to the updater —
    everything is staged under /var/cache/banger and then renamed
    into /usr/local/bin, but those should be on the same fs in a
    typical install). On rename failure, restore the backup so we
    don't leave the caller without their binary.
  * AtomicReplaceRollback(dst, suffixPrevious): symmetric inverse.
    Removes dst, renames dst+suffixPrevious back to dst. Tolerant
    of a missing backup (fresh-install case) so the updater can
    call it unconditionally on failure paths without tracking
    backup state itself.
  * Refuses an empty suffix at compile-time-style guard: an empty
    suffix would silently no-op the backup AND break rollback.

Six tests cover: happy path, fresh install (no prior dst), stale
.previous from a half-finished prior run, empty-suffix rejection,
rollback restores, rollback tolerant of no-backup.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 18:43:04 -03:00
..
ext4.go daemon: rewrite git identity sync + file_sync on ext4 toolkit 2026-04-23 18:29:30 -03:00
ext4_test.go daemon: rewrite ensureWorkDisk no-seed path to skip the mount + cp 2026-04-23 18:09:32 -03:00
extra_test.go coverage: easy-wins batch across cli, system, paths, vmdns, toolingplan 2026-04-18 17:57:05 -03:00
files.go system: add AtomicReplace + Rollback for binary swap 2026-04-28 18:43:04 -03:00
files_test.go system: add AtomicReplace + Rollback for binary swap 2026-04-28 18:43:04 -03:00
preflight.go Refactor VM lifecycle around capabilities 2026-03-18 19:28:26 -03:00
report.go Refactor VM lifecycle around capabilities 2026-03-18 19:28:26 -03:00
report_test.go Refactor VM lifecycle around capabilities 2026-03-18 19:28:26 -03:00
system.go firecracker: adopt firecracker-jailer for VM launch (Phase B) 2026-04-28 14:38:07 -03:00
system_test.go Stop using kernel IP autoconfig for runtime VMs 2026-03-21 21:54:18 -03:00