update

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package update finds the newest vrok release and, for installs that vrok owns, replaces the running binary with it.

Besides `vrok update` and `vrok doctor`, the only automatic contact is the once-a-day check behind the update notice (see State), which reads the latest release tag and nothing else. An install that belongs to a package manager is left to that package manager, because replacing a binary Homebrew or Scoop tracks would leave the manager believing an old version is installed.

Index

Constants

View Source
const CheckInterval = 24 * time.Hour

CheckInterval is how often vrok asks GitHub for the newest release on its own, so the request costs one HEAD a day rather than one per command.

View Source
const FirstWithUpdate = "0.6.0"

FirstWithUpdate is the first release that has `vrok update`. Installing an older one through `vrok update --version` would leave the user with no `vrok update` to come back with, so those go through the install script.

View Source
const GoInstall = "go install github.com/" + Repo + "/cmd/vrok@latest"

GoInstall builds the newest vrok from source.

View Source
const RemindInterval = 24 * time.Hour

RemindInterval is how long a shown notice stays quiet for the same release. Once a day is enough to be noticed without becoming the thing a user scrolls past every time.

View Source
const Repo = "AliJabbar034/vrok"

Repo is the GitHub repository releases come from.

Variables

View Source
var ErrChecksumMismatch = errors.New("update: downloaded archive does not match the published checksum")

ErrChecksumMismatch reports an archive that is not the published build. Nothing from it is written next to the binary.

View Source
var ErrNoSuchRelease = errors.New("update: no such release")

ErrNoSuchRelease reports a tag GitHub has no release for.

View Source
var ErrNotARelease = errors.New("update: not a release version")

ErrNotARelease reports a version string that is not a release number, such as "dev" from a build made without release flags.

Functions

func Apply

func Apply(ctx context.Context, client *http.Client, tag, exe string) error

Apply downloads release tag for this platform, verifies it against the release's checksums.txt, and replaces the binary at exe with it.

Verification fails closed, as install.sh does: anyone able to block checksums.txt could also swap the archive. The new binary is run once before it replaces the old one, so a truncated or wrong-platform build leaves the working install untouched.

func Compare

func Compare(a, b string) (int, error)

Compare orders two release versions: -1, 0 or 1 as a is older than, the same as, or newer than b.

func Executable

func Executable() (string, error)

Executable returns the real path of the running binary, with symlinks resolved: Homebrew's /opt/homebrew/bin/vrok is a link into its Caskroom, and only the resolved path says who installed it.

func Latest

func Latest(ctx context.Context, client *http.Client) (string, error)

Latest returns the newest release's tag, such as "v0.5.2".

It reads the redirect from /releases/latest rather than calling the JSON API, the same way install.sh does: that avoids the API's per-IP rate limit, which shared offices and CI runners hit quickly.

func Newer

func Newer(latest, current string) (bool, error)

Newer reports whether latest is a later release than current. Both must parse; a caller holding a "dev" build has nothing to compare.

func Parse

func Parse(version string) ([3]int, error)

Parse reads "v0.5.1", "0.5.1" or "0.5.2-next" into its three numbers.

func ReleaseURL

func ReleaseURL(tag string) string

ReleaseURL is the page describing a release.

func RemoveLeftover

func RemoveLeftover(exe string)

RemoveLeftover deletes the binary a previous Windows update moved aside. It is best-effort: the old file may still be running in another terminal.

func SaveState added in v0.7.0

func SaveState(path string, s State) error

SaveState writes State through a temporary file, so two vrok processes finishing together cannot leave a half-written file behind.

func StatePath added in v0.7.0

func StatePath() (string, error)

StatePath returns where State is kept. It is a cache, not configuration: deleting it only means the next run checks again.

func Tag

func Tag(version string) (string, error)

Tag normalises a version a user typed ("0.5.1" or "v0.5.1") into a release tag. It rejects anything that is not a release number, so a typo is caught before any download.

Types

type Method

type Method int

Method is how this copy of vrok was installed, which decides who updates it.

const (
	// MethodSelf is the install script, an archive, or anything unrecognised:
	// vrok replaces its own binary.
	MethodSelf Method = iota
	MethodHomebrew
	MethodScoop
	MethodGo
)

func Detect

func Detect(exe string) Method

Detect works out the install method from the binary's resolved path.

func (Method) Command

func (m Method) Command() string

Command is what updates an install vrok does not own, or "" when vrok updates itself.

func (Method) String

func (m Method) String() string

String names the method the way a user would.

type State added in v0.7.0

type State struct {
	// Latest is the newest release tag seen, such as "v0.7.0".
	Latest string `json:"latest,omitempty"`
	// CheckedAt is when GitHub was last asked.
	CheckedAt time.Time `json:"checked_at"`
	// NotifiedFor and NotifiedAt record the last notice shown.
	NotifiedFor string    `json:"notified_for,omitempty"`
	NotifiedAt  time.Time `json:"notified_at"`
}

State is what the update notice remembers between runs.

func LoadState added in v0.7.0

func LoadState(path string) State

LoadState reads State. A missing or damaged file is the zero State, which simply makes the next run check again.

func (State) Pending added in v0.7.0

func (s State) Pending(current string, now time.Time) string

Pending returns the release to announce to someone running current, or "" when there is nothing newer or the same release was announced recently.

func (State) Stale added in v0.7.0

func (s State) Stale(now time.Time) bool

Stale reports whether GitHub should be asked again. A check dated in the future means the clock moved, and is treated as stale rather than trusted.

Jump to

Keyboard shortcuts

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