Documentation
¶
Overview ¶
Package update implements what `lazyshell update` needs: find the latest GitHub release, download the archive built for this OS/arch, check it against the release's checksums.txt, and swap the running binary for the one inside.
It is the in-binary equivalent of scripts/install.sh, and deliberately does the same three things in the same order — download, verify, replace. The checksum step is not optional: this code writes an executable that will be run as the user, so a truncated or tampered download must fail loudly rather than land on disk.
Nothing here knows about the CLI: pkg/app owns the messages, the flags and the "am I newer" decision. This package only knows how to fetch and install.
Index ¶
Constants ¶
const ( // Repo is where releases come from, in "owner/name" form. Same repository // scripts/install.sh downloads from. Repo = "thomas-gleizes/lazyshell" )
Variables ¶
This section is empty.
Functions ¶
func Compare ¶
Compare orders two release versions: -1 if a < b, 0 if equal, 1 if a > b. It reports false when either side is not a plain vX.Y.Z — the caller decides what to do about a version it cannot place, and guessing would be the one wrong answer (a build called "dev" is not "older than everything").
Types ¶
type Updater ¶
type Updater struct {
// Repo is the "owner/name" repository, defaulting to Repo.
Repo string
// APIBase is the GitHub API root, defaulting to https://api.github.com.
APIBase string
// DownloadBase is the release-download root, defaulting to
// https://github.com.
DownloadBase string
// GOOS and GOARCH select the archive, defaulting to the running binary's.
GOOS, GOARCH string
// Client is the HTTP client, defaulting to http.DefaultClient.
Client *http.Client
// Target is the file to replace, defaulting to the running executable
// (symlinks resolved).
Target string
}
Updater is a configured "where do I get releases from". The zero value works and targets the real GitHub repository for the running OS/arch — every field exists so the tests can point the whole thing at an httptest server and a temporary directory.
func (Updater) ArchiveName ¶
ArchiveName is the release asset for this platform, per .goreleaser.yml's name_template.
func (Updater) Download ¶
Download fetches the archive for the given tag, checks it against the release's checksums.txt and returns the verified binary's bytes. Nothing touches the filesystem here: an installation that fails halfway must not be able to leave a partial binary behind.
func (Updater) Install ¶
Install replaces the target with bin and returns the path it wrote to.
The write is a temporary file in the target's own directory followed by a rename, which is what makes it atomic: an interrupted update leaves either the old binary or the new one, never half of either. Renaming over a running executable is fine on Unix — the running process keeps the inode it started with — which is why `lazyshell update` can be run from inside lazyshell.