selfupdate

package
v0.0.0-...-cd8449e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 8, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package selfupdate updates the running atl binary to the latest stable release. It is the shared machinery behind the manual `atl upgrade` command and the automatic session-start auto-apply: resolve the latest stable release, compare it to the running build (only-upgrade, never downgrade), download the matching release asset, verify its sha256 against the published checksums, and atomically replace the running executable.

Safety rails, all mandatory:

  • the ATL_NO_SELF_UPDATE env var disables it entirely (the only opt-out);
  • an un-stamped "dev" build is never replaced (Check returns Upgrade=false);
  • the downloaded asset is sha256-verified before it touches the install dir;
  • Windows can't overwrite a running .exe, so Apply returns ErrWindowsManual.

Index

Constants

View Source
const (
	// EnvDisable turns self-update off entirely (the only opt-out — the feature is
	// otherwise mandatory, per the v2 "automation is mandatory" stance).
	EnvDisable = "ATL_NO_SELF_UPDATE"
)

Variables

View Source
var ErrWindowsManual = errors.New("windows binaries can't self-replace in place; rerun the install script to upgrade")

ErrWindowsManual is returned by Apply on Windows: a running .exe cannot be overwritten in place, so the user must rerun the install script instead.

Functions

func Apply

func Apply(ctx context.Context, tag string) error

Apply downloads the release asset for tag matching this OS/arch, verifies its sha256 against the published checksums, and atomically replaces the running binary. Unix only — on Windows it returns ErrWindowsManual without touching disk.

func AutoApply

func AutoApply(ctx context.Context, current string) string

AutoApply is the session-start entry point for binary self-update. Throttled to once per checkInterval, it checks for a newer stable release and, if one exists, spawns a DETACHED `atl upgrade` so the download+swap runs independently and the NEXT session gets the new binary. It returns a short notice to print (empty when there's nothing to say). It never blocks on the download and swallows every error — session-start is contractually never-fail.

func TryLock

func TryLock() (release func(), ok bool)

TryLock takes the global self-update lock so a manual `atl upgrade` and the session-start auto-apply (or two auto-applies racing) never download+swap at once. It is time-based, not pid-based: a lock older than lockStale is treated as abandoned and stolen. Returns a release func and whether the lock was acquired. It fails open — if the home dir can't be resolved, it returns acquired (never block an upgrade on a missing cache path).

Types

type Status

type Status struct {
	Current string // the running build's version (buildinfo.Version), e.g. "2.3.1" or "dev"
	Latest  string // the resolved latest stable tag, e.g. "v2.3.2" (empty when skipped)
	Upgrade bool   // true iff Latest is strictly newer than Current
	Reason  string // when Upgrade is false: why (disabled / dev build / already up to date)
}

Status is the result of a version Check.

func Check

func Check(ctx context.Context, current string) (Status, error)

Check resolves the latest stable release and compares it to current. It makes at most one network call. Disabled/dev cases are not errors — they return Upgrade=false with a Reason and no network call.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL