Documentation
¶
Index ¶
- Variables
- func CheckVersion(ctx context.Context, stderrLogger *zerolog.Logger)
- func DetectLatest(ctx context.Context, prerelease bool) (string, error)
- func DownloadAndApply(ctx context.Context, tag, exePath string) error
- func EnsureReplaceable(exePath string) error
- func IsDevBuild() bool
- func IsNewer(candidate, current string) bool
- func IsPrerelease() bool
Constants ¶
This section is empty.
Variables ¶
var ( AppVersion = devBuild // In release builds this will be overwritten via ldflags GitCommit = "unknown-commit" // -"- )
var ErrLeftoverInUse = errors.New("a file left over from an earlier update could not be removed")
ErrLeftoverInUse reports that a temp file from an earlier update could not be removed even though the install itself is replaceable, which means another process is holding it.
This must not be conflated with a permission problem. On Windows the file that update.Apply leaves behind after every successful swap is the mapped image of the process that performed it, and removing a mapped image fails with ERROR_ACCESS_DENIED — indistinguishable by errno from an unwritable install, but no amount of elevation can fix it.
Functions ¶
func DetectLatest ¶
DetectLatest returns the latest available version. When prerelease is true it returns the latest dev/prerelease version (from the Atom feed); otherwise it returns the latest GA release (from the /releases/latest redirect). Neither path touches the throttled api.github.com endpoint.
func DownloadAndApply ¶
DownloadAndApply downloads the release archive for the given version from the GitHub CDN (not the throttled api.github.com), extracts the 'metaplay' binary, and atomically replaces the executable at exePath.
It reuses go-selfupdate's standalone helpers for the archive handling and the safe, cross-platform binary swap, so we don't have to reimplement either.
The archive is tens of MB, so this deliberately does NOT impose a hard timeout (a slow connection should not fail a legitimate update). Cancellation is governed by ctx, so the caller can bound or interrupt it (e.g. Ctrl+C via the command context).
func EnsureReplaceable ¶
EnsureReplaceable clears anything blocking an in-place update of the executable at exePath and verifies that the swap can actually happen, so an unwritable install (a package-manager-managed or system-wide location) fails fast rather than after a download of tens of MB. It removes files, so it is not a read-only check.
It probes what update.Apply does: create a file in the install directory, then rename over the target. It deliberately never opens the target for writing — on Windows a running executable is locked against writes but can still be renamed, which is how the swap works.
Checks run cheapest and least destructive first, which also decides how failures are reported: an install that can never be updated says so, rather than blaming a leftover file that is merely a symptom.
func IsDevBuild ¶
func IsDevBuild() bool
func IsNewer ¶
IsNewer reports whether candidate is a strictly newer version than current. Both are plain version strings (no leading 'v'). On parse failure it returns false, so a malformed version is never treated as an available update.
func IsPrerelease ¶
func IsPrerelease() bool
IsPrerelease returns true if the current version is a prerelease build (e.g. "0.1.3-dev.5"), but not a local development build ("dev").
Types ¶
This section is empty.