selfupdate

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const Repo = "jmwri/flockdeck"

Repo is the repository releases are read from, as owner/name.

Variables

View Source
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

func Apply(dir, exePath string) error

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 Dir

func Dir(state string) (string, error)

Dir is where updates are staged, given the application's state directory.

func Discard

func Discard(dir string)

Discard forgets a staged update and removes what it downloaded.

func Newer

func Newer(candidate, current string) bool

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.

func Parseable

func Parseable(v string) bool

Parseable reports whether a version string is one that can be ordered against a release at all. An untagged local build, stamped `dev`, is not, which is a different thing from being up to date and worth saying so.

func Sweep

func Sweep(exePath string)

Sweep removes the file a previous Apply moved aside. It is called at startup, by which time nothing holds the old program open.

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

func Load(dir string) (*Pending, bool)

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

func Stage(ctx context.Context, rel *Release, dir string) (*Pending, error)

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.

func Check

func Check(ctx context.Context, current string) (*Release, error)

Check returns the latest release when it is newer than the version given, and nil when there is nothing to do.

An unreadable current version — `dev`, which is what a build with no tag behind it is stamped — means nothing to do, so a local build is never replaced by a published one.

func Latest

func Latest(ctx context.Context) (*Release, error)

Latest returns the most recent published release.

Jump to

Keyboard shortcuts

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