updater

package
v0.0.0-...-6eeeea1 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package updater provides binary self-update from GitHub releases.

Uses creativeprojects/go-selfupdate for release detection, checksum verification, archive matching, and atomic binary replacement.

The three-step API (Download, VerifyChecksum, Install) supports the hot-swap upgrade flow (Phase 3) where the binary is downloaded to a temp path, verified, and installed atomically. ApplyUpdate is preserved as a backwards-compatible wrapper for Phase 1.

Index

Constants

View Source
const (
	// DefaultSlug is the GitHub repository slug for aimux releases.
	DefaultSlug = "thebtf/aimux"
)

Variables

View Source
var (
	ErrChecksumVerification = errors.New("checksum_verification_failed")
	ErrDiskFull             = errors.New("disk_full")
)

Functions

func Install

func Install(newBinaryPath string, currentExePath string) error

Install atomically replaces currentExePath with the binary at newBinaryPath.

Uses go-selfupdate/update.Apply for cross-platform safe replacement: on Windows, running executables cannot be overwritten directly (ERROR_ACCESS_DENIED), so the library renames the old binary before placing the new one. The old binary is hidden rather than deleted on Windows.

newBinaryPath must be readable; currentExePath is the installation target.

func SetTestHooks

func SetTestHooks(
	check func(ctx context.Context, currentVersion string) (*Release, error),
	download func(ctx context.Context, currentVersion string, targetPath string) (*Release, error),
	verifyChecksum func(binaryPath string, release *Release) error,
	install func(newBinaryPath string, currentExePath string) error,
)

SetTestHooks installs deterministic hooks for tests that need to control the update source without network access. Passing nil resets hooks to production.

func VerifyChecksum

func VerifyChecksum(binaryPath string, release *Release) error

VerifyChecksum validates that a downloaded binary exists and the release metadata is present.

Note: the go-selfupdate ChecksumValidator already verifies the SHA256 checksum against checksums.txt during Download via UpdateTo. This function is the explicit post-download verification hook in the three-step flow. For Phase 1, it confirms file existence and non-nil release metadata. Full cryptographic re-verification (re-downloading checksums.txt) is reserved for Phase 3 where the temp path is separate from the install destination.

Types

type ApplyError

type ApplyError struct {
	Release *Release
	Err     error
}

ApplyError carries the discovered release when apply/install fails after download.

func (*ApplyError) Error

func (e *ApplyError) Error() string

func (*ApplyError) Unwrap

func (e *ApplyError) Unwrap() error

type Release

type Release struct {
	Version      string `json:"version"`
	AssetName    string `json:"asset_name"`
	AssetURL     string `json:"asset_url"`
	ReleaseNotes string `json:"release_notes"`
	PublishedAt  string `json:"published_at"`
}

Release holds information about an available update.

func ApplyUpdate

func ApplyUpdate(ctx context.Context, currentVersion string) (*Release, error)

ApplyUpdate downloads and installs the latest release, replacing the current executable. Preserved as a backwards-compatible wrapper calling Download → VerifyChecksum → Install.

Phase 3 callers should prefer Download + VerifyChecksum + Install directly to control the download destination and enable the muxcore hot-swap flow.

func ApplyUpdateAt

func ApplyUpdateAt(ctx context.Context, currentVersion string, currentExePath string) (*Release, error)

ApplyUpdateAt downloads and installs the latest release over currentExePath. This variant exists so the upgrade coordinator can hot-swap a known binary path without relying on selfupdate.ExecutablePath().

go-selfupdate's UpdateTo handles the full lifecycle: download, decompress, checksum validation (via ChecksumValidator), and atomic binary replacement (rename old → .old, place new). On Windows, running executables can be renamed but not deleted — go-selfupdate hides the .old file instead of removing it.

func CheckUpdate

func CheckUpdate(ctx context.Context, currentVersion string) (*Release, error)

CheckUpdate detects the latest release and compares it with the current version. Returns nil release if already up to date or no release found.

func Download

func Download(ctx context.Context, currentVersion string, targetPath string) (*Release, error)

Download detects the latest release and downloads it to targetPath.

Checksum validation is performed by the embedded ChecksumValidator during the UpdateTo call — the file at targetPath is already verified when this function returns successfully.

Returns nil release if currentVersion is already up to date (no download performed). The caller is responsible for cleaning up targetPath on error.

func ReleaseFromError

func ReleaseFromError(err error) (*Release, bool)

ReleaseFromError extracts release metadata from an apply error chain.

Jump to

Keyboard shortcuts

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