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
- Variables
- func Apply(ctx context.Context, client *http.Client, tag, exe string) error
- func Compare(a, b string) (int, error)
- func Executable() (string, error)
- func Latest(ctx context.Context, client *http.Client) (string, error)
- func Newer(latest, current string) (bool, error)
- func Parse(version string) ([3]int, error)
- func ReleaseURL(tag string) string
- func RemoveLeftover(exe string)
- func Tag(version string) (string, error)
- type Method
Constants ¶
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.
const GoInstall = "go install github.com/" + Repo + "/cmd/vrok@latest"
GoInstall builds the newest vrok from source.
const Repo = "AliJabbar034/vrok"
Repo is the GitHub repository releases come from.
Variables ¶
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.
var ErrNoSuchRelease = errors.New("update: no such release")
ErrNoSuchRelease reports a tag GitHub has no release for.
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 ¶
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 ¶
Compare orders two release versions: -1, 0 or 1 as a is older than, the same as, or newer than b.
func Executable ¶
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 ¶
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 ¶
Newer reports whether latest is a later release than current. Both must parse; a caller holding a "dev" build has nothing to compare.
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.