selfupdate

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: MIT Imports: 29 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 releases, published at dl.flockdeck.ai (Site) and mirrored on GitHub.

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:

  • Latest asks what the latest release is, and Newer says whether it is one to move to; an untagged local build never has one.
  • Stage downloads it, checks it against the published SHA-256, signed by the release key when it comes from the site, 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.

On Windows the program has a console twin beside it (chatName), the same program with its PE Subsystem set to console, which an API agent's pane runs. Stage and Apply carry it with the program when a release has one, and EnsureChatTwin keeps it exactly in step with the program at every start however the program was put there.

Index

Constants

View Source
const Repo = "jmwri/flockdeck"

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

View Source
const Site = "https://dl.flockdeck.ai"

Site is where releases are downloaded from first: a DigitalOcean Space behind DigitalOcean's CDN, laid out as

/latest.json                            {"version":"v1.2.3"}: which release is the latest
/<version>/manifest.json(.sig)          that release's files and their SHA-256s, signed
/<version>/<archive>                    each release's files
/<version>/checksums.txt(.sig)          and their SHA-256s, signed
/latest/<archive without the version>   for the site's download buttons

Everything under /<version>/ is written once, when the release is published, and never changes, so it is cached for a year. latest.json is the one file that moves, and it is neither signed nor purged from the CDN's edges when it does; it needs to be neither. All it can do is name a version, and the updater trusts nothing until that version's own manifest has passed the release key's signature and names the same version. So a stale latest.json, or a forged one, can only name another signed release: an older one, which Newer never moves to, or a pre-release, which latestFromSite refuses. The most it can do is hold an update back for as long as it is cached; it can never have anything unsigned installed, nor anything older.

GitHub carries every release as well and is where the updater goes when the site cannot be reached, answers with something it cannot use, or fails a signature. That is also the only place a copy from before the site knows about, which is why every release is still published there.

Asking here first is what keeps a shared office network from running out of GitHub's sixty unauthenticated API calls an hour: the site has no such limit.

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, and on Windows the console twin beside it (chatName) with the staged one.

The two go in together or not at all: a new program beside an old twin, or the other way round, would run a chat client of another version in its panes. So the twin goes in first and is taken back out if the program then cannot be put in, and the update stays staged for the next attempt.

func CheckPointer added in v0.2.10

func CheckPointer(data []byte) (string, error)

CheckPointer reads latest.json and returns the version it names, refusing anything that does not name one.

func ConsoleTwin added in v0.2.3

func ConsoleTwin(program []byte) ([]byte, bool)

ConsoleTwin is program with its PE Subsystem field set to console: the console twin of a GUI build, which is all that tells the two apart and all that decides whether Windows gives a pane's process a console. It is false for anything that is not a GUI-subsystem PE file.

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 EncodePublicKey added in v0.2.10

func EncodePublicKey(k ed25519.PublicKey) string

EncodePublicKey is a public key as `cmd/release -keygen` prints it.

func EncodeSigningKey added in v0.2.10

func EncodeSigningKey(k ed25519.PrivateKey) string

EncodeSigningKey is the content of the signing key's file -keygen writes.

func EnsureChatTwin added in v0.2.3

func EnsureChatTwin(exePath string) error

EnsureChatTwin keeps the console twin (chatName) beside the program at exePath exactly what the program makes of itself (ConsoleTwin), writing it when it is missing or differs.

A release carries the twin, but the first update to one is put in place by the release before it, whose updater knows only the program, and an installation made by an install script of before, or by `go install`, has none either: without one an API agent's pane is blank. And a program replaced by any route that leaves the twin as it was — a copy by hand, an updater of before — would have its panes run a chat client of another version, whose hook events, prompts and transcripts can have drifted.

Only a file of exactly that name in the program's own directory is ever written, never through a link, a reparse point or anything else that is not a regular file. The new twin is written beside it and renamed over it; a twin a chat pane is running from cannot be renamed over on Windows, and is left for the next start, the pane working on meanwhile. It does nothing off Windows, for the twin itself, or for a program that is not a GUI build, which runs in a pane as it is.

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 ParseSigningKey added in v0.2.10

func ParseSigningKey(s string) (ed25519.PrivateKey, error)

ParseSigningKey reads the signing key as FLOCKDECK_SIGNING_KEY holds it: the PKCS#8 PEM Terraform gives, or the base64 seed -keygen writes. The error never quotes the text, which is a secret.

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 ReleaseKey added in v0.2.10

func ReleaseKey() (ed25519.PublicKey, bool)

ReleaseKey is the public key compiled into this build, and false while it is still the placeholder.

func Sign added in v0.2.10

func Sign(k ed25519.PrivateKey, data []byte) []byte

Sign is the content of the .sig file for data.

func Sweep

func Sweep(exePath string)

Sweep removes the files previous Applies moved aside, the console twin's as well as the program's, and what an interrupted EnsureChatTwin left. It is called at startup, by which time nothing holds the old program open — or, for one an instance still running is using, fails to and leaves it for next time.

func Verify added in v0.2.10

func Verify(key ed25519.PublicKey, data, sig []byte) error

Verify reports whether sig, the content of a .sig file, is key's signature of data.

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 Manifest added in v0.2.10

type Manifest struct {
	Version  string         `json:"version"`
	Date     time.Time      `json:"date"`
	NotesURL string         `json:"notes_url"`
	Notes    string         `json:"notes,omitempty"`
	Files    []ManifestFile `json:"files"`
}

Manifest is one release as the site holds it, <version>/manifest.json: every file of it, with the SHA-256 and size of each, and its notes. It is signed, in manifest.json.sig, and never changes once published. cmd/release writes it and the updater reads it, through this one type.

func CheckManifest added in v0.2.10

func CheckManifest(key ed25519.PublicKey, data, sig []byte) (*Manifest, error)

CheckManifest reads a release's manifest.json once its signature, the content of manifest.json.sig, has been checked against key, and refuses a manifest the updater could not act on. cmd/release reads back what it wrote through this, so a release is never published with a manifest the updater would refuse.

type ManifestFile added in v0.2.10

type ManifestFile struct {
	Name   string `json:"name"`
	URL    string `json:"url"`
	SHA256 string `json:"sha256"`
	Size   int64  `json:"size"`
}

ManifestFile is one file of a release on the site.

type Pending

type Pending struct {
	Version string    `json:"version"`
	Binary  string    `json:"binary"`
	Chat    string    `json:"chat,omitempty"` // the staged console twin (chatName), when the release has one
	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, with the console twin beside it when the release has one.

A release read from the site is downloaded from there, and from GitHub when that fails for any reason, the reason logged. Either way the archive has to match the SHA-256 the release's signed manifest gave for it.

type Pointer added in v0.2.10

type Pointer struct {
	Version string `json:"version"`
}

Pointer is latest.json, the one file on the site that changes: it names the latest release and says nothing else about it. It is not signed; Site says why it need not be. cmd/release writes it and the updater reads it, through this one type.

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"`
	// contains filtered or unexported fields
}

Release is a published release, reduced to what an update needs.

func Latest

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

Latest returns the most recent published release: from the site when it answers with a manifest signed by the release key, and otherwise from GitHub, as every release before the site did, with the reason logged.

Neither is sent anything but the request itself: no version, no identifier, nothing a server could tell one installation from another by.

func (*Release) DownloadSize added in v0.2.3

func (r *Release) DownloadSize() int64

DownloadSize is the size in bytes of the archive Stage would fetch for this platform, or 0 when the release has none or does not say.

Jump to

Keyboard shortcuts

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