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
- func AssetName(version, goos, goarch string) string
- func BinaryNames(goos string) []string
- func InstallWritable(dir string) bool
- func LoadNotifiedVersion(path string) string
- func PruneStaged(root, keep string)
- func SaveNotifiedVersion(path, version string) error
- func SaveState(path string, st State) error
- func VerifyStaged(dir string, m *Manifest, required []string) error
- type Asset
- type Checker
- type Manifest
- type Release
- type Stager
- type State
Constants ¶
const DefaultBaseURL = "https://api.github.com"
DefaultBaseURL is the GitHub API host; tests override Checker.BaseURL.
Variables ¶
This section is empty.
Functions ¶
func AssetName ¶
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 ¶
BinaryNames returns the executable names inside the release archive for a platform.
func InstallWritable ¶
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 ¶
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 ¶
SaveNotifiedVersion records that the startup dialog was shown for version.
func VerifyStaged ¶
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.
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) Release ¶ added in v1.44.0
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.
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.
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>/.
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.