Documentation
¶
Overview ¶
Package selfupdate replaces the running binary with the latest release.
Index ¶
- Variables
- func ArchiveName(version, goos, goarch string) string
- func BinaryName(goos string) string
- func ChecksumsName(version string) string
- func ExecRunner(name string, args ...string) ([]byte, error)
- func ExtractBinary(archivePath, binaryName, destDir string) (string, error)
- func FetchVerifiedBinary(release *Release, goos, goarch, binaryName, destDir string) (string, error)
- func IsOutdated(current, latest string) bool
- func IsUnknownVersion(version string) bool
- func LockPath(executablePath string) string
- func PackageOwner(run CommandRunner, executablePath string) (string, error)
- func ParseChecksums(data []byte) map[string]string
- func PreservedName(path string, now time.Time) string
- func ReplaceBinary(targetPath, newBinaryPath string) error
- func ResolveExecutablePath() (string, error)
- func RestorePreserved(preservedPath, targetPath string) error
- func StagedName(path string, now time.Time) string
- func SweepPreserved(dir, binaryName string) int
- func UpgradeGuidance(kind InstallKind) string
- func VerifyChecksum(path, want string) error
- type Asset
- type CommandRunner
- type InstallKind
- type Lock
- type Options
- type Release
- type Result
Constants ¶
This section is empty.
Variables ¶
var ( ErrUpdateInProgress = errors.New("another alpacon update is already running") )
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.
var ErrChecksumMismatch = errors.New("checksum mismatch")
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.
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.
Functions ¶
func ArchiveName ¶
func BinaryName ¶
func ChecksumsName ¶
func ExecRunner ¶
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 FetchVerifiedBinary ¶
func IsOutdated ¶
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 ¶
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 ¶
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 ReplaceBinary ¶
func ResolveExecutablePath ¶
func RestorePreserved ¶
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 SweepPreserved ¶
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 ¶
Types ¶
type CommandRunner ¶
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 an advisory lock the kernel drops when this process exits, however it exits. A lock named only by the file's own contents would need an age rule to survive a killed process, and no age works: shorter than a slow download and it evicts a live update, longer and a killed one strands the next run.