selfupdate

package
v1.16.1 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 23 Imported by: 1 module, 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 replaces the running binary with the latest release.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUpdateInProgress = errors.New("another alpacon update is already running")

	ErrLockUnavailable = errors.New("cannot open the update lock") // One shape for every way the lock can fail to open, and it names the lock, which no underlying message does.
)
View Source
var DefaultReleaseAPIURL = "https://api.github.com/repos/alpacax/alpacon-cli/releases/latest"

DefaultReleaseAPIURL is a var so a test can point a real alpacon process at a stub. Exit code 8 is only observable in a process that actually exits, and a child process cannot be handed a different endpoint any other way.

View Source
var ErrChecksumMismatch = errors.New("checksum mismatch")
View Source
var ErrOwnerUnknown = errors.New("cannot tell which package owns the binary")

ErrOwnerUnknown separates "no package owns this" from "the query could not answer". Both used to arrive as the empty string, which ClassifyPath reads as a manual install and Run reads as permission to overwrite the file.

View Source
var ErrUnknownVersion = errors.New("the running build's version matches no release")

compareVersions reads an unparseable core as 0.0.0, so an importer that skips IsUnknownVersion would have a dev build reinstall the latest release forever.

View Source
var ErrWorkDirUnavailable = errors.New("cannot create the download directory") // Separates the download's scratch directory from the install path: both refuse with EACCES, and sudo answers only one of them.

Functions

func ArchiveName

func ArchiveName(version, goos, goarch string) string

func BinaryName

func BinaryName(goos string) string

func ChecksumsName

func ChecksumsName(version string) string

func ExecRunner

func ExecRunner(name string, args ...string) ([]byte, error)

ExecRunner reads stdout alone: dpkg-query warns on stderr and still exits zero, and CombinedOutput would hand the parser "dpkg-query: warning" as the package that owns the file.

func ExtractBinary

func ExtractBinary(archivePath, binaryName, destDir string) (string, error)

func FetchVerifiedBinary

func FetchVerifiedBinary(release *Release, goos, goarch, binaryName, destDir string) (string, error)

func IsOutdated

func IsOutdated(current, latest string) bool

IsOutdated only ever moves forward. The release workflow publishes a pre-release tag with --latest=false, so /releases/latest answers an rc build with the previous stable release; treating any difference as outdated would install that older binary and report it as an update.

func IsUnknownVersion

func IsUnknownVersion(version string) bool

IsUnknownVersion answers for a build this CLI cannot place against a release: the literal dev build, and anything whose first part is not a number. Both sort as 0.0.0—compareCore reads an unreadable part as zero—so without this they would pull the latest release down on top of themselves on every run.

func LockPath

func LockPath(executablePath string) string

LockPath puts the lock beside the binary it guards. In the home directory it would guard nothing: sudo moves HOME to /root on Linux, so the root run and the user run would take two different locks over one install path—and where sudo keeps HOME, root would leave a lock file the user can no longer open.

func PackageOwner

func PackageOwner(run CommandRunner, executablePath string) (string, error)

func ParseChecksums

func ParseChecksums(data []byte) map[string]string

func PreservedName

func PreservedName(path string, now time.Time) string

func ReplaceBinary

func ReplaceBinary(targetPath, newBinaryPath string) error

func ResolveExecutablePath

func ResolveExecutablePath() (string, error)

func RestorePreserved

func RestorePreserved(preservedPath, targetPath string) error

RestorePreserved falls back to a copy because a rename cannot cross a filesystem boundary, and because on Windows the target may be held open by something that took it between the failure and this call.

func StagedName

func StagedName(path string, now time.Time) string

func SweepPreserved

func SweepPreserved(dir, binaryName string) int

SweepPreserved clears what an earlier update could not delete: on Windows the preserved copy is the executable that was running then, and a staging or utils.SaveStreamAtomic temp file outlives a run killed while writing it.

func UpgradeGuidance

func UpgradeGuidance(kind InstallKind) string

UpgradeGuidance returns text only, never a command: overwriting a file dpkg, rpm, or Homebrew owns desyncs that manager, and running it for the user would spend their root password on a command they never read.

func VerifyChecksum

func VerifyChecksum(path, want string) error

Types

type Asset

type Asset struct {
	Name        string
	DownloadURL string
}

func SelectAsset

func SelectAsset(release *Release, name string) (Asset, error)

type CommandRunner

type CommandRunner func(name string, args ...string) ([]byte, error)

CommandRunner answers who owns a path. A nil error is an answer; so is an ordinary error, which means this manager does not claim the file. Only an error wrapping ErrOwnerUnknown says the question went unanswered.

type InstallKind

type InstallKind string
const (
	InstallManual         InstallKind = "manual"
	InstallHomebrew       InstallKind = "homebrew"
	InstallDeb            InstallKind = "deb"
	InstallRPM            InstallKind = "rpm"
	InstallVersionManager InstallKind = "version-manager"
)

func ClassifyPath

func ClassifyPath(executablePath, packageOwner string) InstallKind

ClassifyPath reads the path before the ownership answer: a Homebrew Cellar path is unambiguous, while /usr/local/bin is shared by the deb, the rpm, and a hand-placed binary, which only the ownership query separates.

func DetectInstallKind

func DetectInstallKind(run CommandRunner, executablePath string) (InstallKind, error)

type Lock

type Lock struct {
	// contains filtered or unexported fields
}

Lock is the advisory lock that keeps two updates off one install path. The kernel drops it when this process exits, however it exits.

func AcquireLock

func AcquireLock(path string) (*Lock, error)

func (*Lock) Release

func (l *Lock) Release() error

Release drops the lock and leaves the file behind for the next update.

type Options

type Options struct {
	ReleaseAPIURL  string
	CurrentVersion string
	GOOS           string
	GOARCH         string
	ExecutablePath string
	Runner         CommandRunner // Defaults to ExecRunner: a zero value that skipped the ownership question would read as permission to overwrite.
}

type Release

type Release struct {
	Version string
	HTMLURL string
	Assets  []Asset
}

func LatestRelease

func LatestRelease(apiURL string) (*Release, error)

type Result

type Result struct {
	Kind           InstallKind
	Guidance       string
	UpdatedTo      string
	AlreadyCurrent bool
}

func Run

func Run(opts Options) (Result, error)

Jump to

Keyboard shortcuts

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