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") ErrLockUnavailable = errors.New("cannot open the update lock") )
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 "the query could not answer" from "no package owns this": an empty owner reads to ClassifyPath as a manual install and to Run as permission to overwrite.
var ErrUnknownVersion = errors.New("the running build's version matches no release")
ErrUnknownVersion refuses a build no release can be placed against: compareVersions reads an unparseable core as 0.0.0, so a dev build would otherwise reinstall the latest release forever.
ErrWorkDirUnavailable tells the scratch directory's EACCES from the install path's, which sudo fixes.
Functions ¶
func ArchiveName ¶
func BinaryName ¶
BinaryName returns the name inside the archive, whatever the running binary is called on disk.
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 ¶
ReplaceBinary's 0755 applies only to a missing target; an installed binary keeps its mode.
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 StagedName ¶
StagedName returns a fresh staging name per run: a fixed name would reuse a staging file a killed run left.
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)
DetectInstallKind asks both halves together: asking either alone can give a different verdict.
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.