Documentation
¶
Overview ¶
Package selfupdate keeps a running Flockdeck up to date from its GitHub releases.
The work is split into three steps that are deliberately kept apart, because the application can afford to do the first two at any time and can only ever do the third at a moment of the user's choosing:
- Check asks GitHub what the latest release is.
- Stage downloads it, checks it against the published SHA-256 and unpacks the binary into the state directory. Nothing about the installation has changed yet.
- Apply swaps the staged binary into place. This is the only step that touches the installed program, and it is never done under a running session: panes hold live agents, and replacing the binary beneath them to save a restart would cost far more work than it saved.
Staging is recorded on disk, so an update downloaded in one run is still there to be applied by the next, and a half-finished download is never mistaken for a finished one.
Index ¶
Constants ¶
const Repo = "jmwri/flockdeck"
Repo is the repository releases are read from, as owner/name.
Variables ¶
var ErrNoAsset = errors.New("this release has no build for this platform")
ErrNoAsset is returned when a release carries nothing built for this platform, which is what a partly-uploaded release looks like from here.
Functions ¶
func Apply ¶
Apply replaces the running program's file with the staged binary.
The running file is moved aside rather than written over. Windows will not let an executable that is running be replaced, but it will let it be renamed, so moving it out of the way and putting the new one at the old name works while the program is still running from it. The moved-aside file is swept up by the next start, once nothing holds it open.
The staged binary is copied rather than renamed into place because the state directory and the installation are frequently on different volumes, and a rename across volumes fails.
func Discard ¶
func Discard(dir string)
Discard forgets a staged update and removes what it downloaded.
func Newer ¶
Newer reports whether candidate is a release worth moving to from current.
It answers no when either side cannot be read, which is the case that keeps an untagged local build in place: there is no sense in which `dev` is behind v1.4.0, because it may well be ahead of it.
Types ¶
type Asset ¶
type Asset struct {
Name string `json:"name"`
URL string `json:"browser_download_url"`
Size int64 `json:"size"`
}
Asset is one file attached to a release.
type Pending ¶
type Pending struct {
Version string `json:"version"`
Binary string `json:"binary"`
Notes string `json:"notes,omitempty"`
URL string `json:"url,omitempty"`
Staged time.Time `json:"staged"`
}
Pending is an update that has been downloaded, checked and unpacked, and is waiting for a restart to be applied.
func Load ¶
Load returns the update waiting to be applied, if there is one.
A record whose binary has gone is not an update: the file can be cleared out from under us by anything that tidies temporary directories, and reporting an update that could not possibly be applied would put a badge in the interface that a restart would never clear.
func Stage ¶
Stage downloads the release, checks it and unpacks the binary under dir.
The download is hashed as it is written rather than read back afterwards, so a file that does not match is never on disk in a state anything could mistake for finished, and a truncated transfer fails here rather than at the swap.
type Release ¶
type Release struct {
Version string `json:"tag_name"`
Notes string `json:"body"`
URL string `json:"html_url"`
Draft bool `json:"draft"`
Pre bool `json:"prerelease"`
Assets []Asset `json:"assets"`
}
Release is a published release, reduced to what an update needs.