update

package
v1.47.1 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package update implements Quil's auto-update pipeline: a GitHub release checker, a download/verify/stage step, and the small state files shared between daemon (writer of state.json) and TUI (writer of notified.json). Stdlib-only by design — both binaries import it.

Index

Constants

View Source
const DefaultBaseURL = "https://api.github.com"

DefaultBaseURL is the GitHub API host; tests override Checker.BaseURL.

Variables

This section is empty.

Functions

func AssetName

func AssetName(version, goos, goarch string) string

AssetName returns the archive name GoReleaser produces for a platform (name_template "quil_{{ .Version }}_{{ .Os }}_{{ .Arch }}"; zip on windows, tar.gz elsewhere). Version carries no leading "v".

func BinaryNames

func BinaryNames(goos string) []string

BinaryNames returns the executable names inside the release archive for a platform.

func InstallWritable

func InstallWritable(dir string) bool

InstallWritable probes whether dir accepts file creation — the gate for self-update. Package-manager / system installs fail this; the pipeline then degrades to notify-only.

func LoadNotifiedVersion

func LoadNotifiedVersion(path string) string

LoadNotifiedVersion returns the last version the startup dialog was shown for, or "" (never notified / unreadable).

func PruneStaged

func PruneStaged(root, keep string)

PruneStaged removes every staged version dir except keep. Best-effort.

func SaveNotifiedVersion

func SaveNotifiedVersion(path, version string) error

SaveNotifiedVersion records that the startup dialog was shown for version.

func SaveState

func SaveState(path string, st State) error

SaveState writes atomically (temp+rename), creating parent dirs.

func VerifyStaged

func VerifyStaged(dir string, m *Manifest, required []string) error

VerifyStaged re-hashes every file listed in the manifest against the staged dir and requires the manifest to cover every name in required — the pre-swap corruption/tamper gate. Callers pass the names they are about to install (BinaryNames).

Types

type Asset

type Asset struct {
	Name        string `json:"name"`
	DownloadURL string `json:"browser_download_url"`
	Size        int64  `json:"size"`
}

Asset is one downloadable file attached to a GitHub release.

func FindAssets

func FindAssets(rel *Release, goos, goarch string) (archive, checksums *Asset, err error)

FindAssets locates the platform archive and the checksums.txt asset in a release. Both must be present — a release without either cannot be verified and is not staged.

type Checker

type Checker struct {
	BaseURL string       // DefaultBaseURL when empty; tests point it at httptest
	Client  *http.Client // nil → 10 s-timeout default
}

Checker fetches the latest published release.

func (*Checker) Latest

func (c *Checker) Latest(ctx context.Context) (*Release, error)

Latest fetches the newest published release. One GET, no retry.

func (*Checker) Release added in v1.44.0

func (c *Checker) Release(ctx context.Context, tag string) (*Release, error)

Release fetches one published release by tag, or the newest when tag is empty. The tag may be given with or without its leading "v".

Fetching by tag exists for remote provisioning: installing "latest" on the far side when this TUI is not itself latest would simply invert the version mismatch it was called to fix.

type Manifest

type Manifest struct {
	Version  string            `json:"version"`
	Files    map[string]string `json:"files"`     // base name → sha256 hex
	StagedAt string            `json:"staged_at"` // RFC3339
}

Manifest records a completed staging: which files landed and their hashes. It is written LAST — its presence marks the stage as complete; its absence means "nothing staged" regardless of other files present.

func FindStaged

func FindStaged(root string) (*Manifest, string, error)

FindStaged scans <root>/staged/* for completed stages (manifest present) and returns the highest-version one, its directory, or (nil, "", nil) when nothing is fully staged.

type Release

type Release struct {
	TagName string  `json:"tag_name"`
	URL     string  `json:"html_url"`
	Assets  []Asset `json:"assets"`
}

Release is the subset of the GitHub release JSON the pipeline needs.

func (*Release) Version

func (r *Release) Version() string

Version returns the tag without the leading "v" ("v1.37.0" → "1.37.0"), matching the version GoReleaser embeds in asset names and ldflags.

type Stager

type Stager struct {
	Root   string // config.UpdateDir()
	GOOS   string // runtime.GOOS at prod call sites
	GOARCH string
	Client *http.Client // nil → 5 min-timeout default (per request)
}

Stager downloads, verifies, and extracts a release into <Root>/staged/<version>/.

func (*Stager) Stage

func (s *Stager) Stage(ctx context.Context, rel *Release) error

Stage downloads the platform archive, verifies its sha256 against checksums.txt BEFORE extraction, extracts the quil/quild binaries, and writes manifest.json last. Any earlier failure leaves no manifest — the next check re-stages from scratch.

type State

type State struct {
	LastCheckMs     int64  `json:"last_check_ms"`
	LatestVersion   string `json:"latest_version,omitempty"`
	ReleaseURL      string `json:"release_url,omitempty"`
	StagedVersion   string `json:"staged_version,omitempty"`
	InstallWritable bool   `json:"install_writable"`
}

State is the daemon-owned check/stage status persisted at config.UpdateStatePath(). The TUI reads it never — update info reaches the TUI over IPC; this file exists so a restarted daemon remembers its last check across runs.

func LoadState

func LoadState(path string) State

LoadState returns the persisted state, or the zero State on any error (missing file, corrupt JSON) — the pipeline treats that as "never checked".

Jump to

Keyboard shortcuts

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