update

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

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

It only ever runs because the user typed `vrok update` or `vrok doctor`: vrok never checks for updates in the background. 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 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 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 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.

Jump to

Keyboard shortcuts

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