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
- 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 SaveState(path string, s State) error
- func StatePath() (string, error)
- func Tag(version string) (string, error)
- type Method
- type State
Constants ¶
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.
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 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.
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.
func SaveState ¶ added in v0.7.0
SaveState writes State through a temporary file, so two vrok processes finishing together cannot leave a half-written file behind.
Types ¶
type Method ¶
type Method int
Method is how this copy of vrok was installed, which decides who updates it.
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
LoadState reads State. A missing or damaged file is the zero State, which simply makes the next run check again.