Documentation
¶
Index ¶
- Constants
- func AtomicReplace(newBinary, currentBinary string) error
- func CacheDir() string
- func CacheFilePath() string
- func ExtractBinaryFromTarGz(archivePath, binaryName, destDir string) (string, error)
- func SelfPath() (string, error)
- func SelfUpdateSupported() bool
- func ShouldCheck(cf CacheFile, ttl time.Duration) bool
- func VerifySHA256(filePath, expectedHex string) (bool, error)
- func WriteCache(cf CacheFile) error
- func WriteCacheAt(dir string, cf CacheFile) error
- type Asset
- type CacheFile
- type CheckResult
- type Config
- type Release
- type Updater
Constants ¶
const DefaultCacheTTL = 24 * time.Hour
DefaultCacheTTL is the default time between update checks.
Variables ¶
This section is empty.
Functions ¶
func AtomicReplace ¶
AtomicReplace replaces the binary at currentBinary with the new binary at newBinary. It writes to a temp file in the same directory and renames, which is atomic on Linux and macOS when on the same filesystem.
The temp file uses a random, exclusive name (os.CreateTemp → O_CREAT|O_EXCL), so an attacker who can write to the directory cannot pre-plant it as a symlink and have us write the new binary through that symlink onto an arbitrary file.
func CacheDir ¶
func CacheDir() string
CacheDir returns the default cache directory for vmflow. Priority: XDG_CACHE_HOME/vmflow > ~/.cache/vmflow
func CacheFilePath ¶ added in v0.3.0
func CacheFilePath() string
CacheFilePath returns the path to vmflow's default update-check cache file. Cleanup callers should remove this file rather than recursively deleting the parent cache directory, which may be shared with other applications.
func ExtractBinaryFromTarGz ¶
ExtractBinaryFromTarGz extracts the binary named binaryName from a .tar.gz archive, writing it to destDir and returning the path to the extracted file.
func SelfPath ¶
SelfPath returns the absolute path of the currently running executable, resolving any symlinks.
func SelfUpdateSupported ¶ added in v0.3.0
func SelfUpdateSupported() bool
SelfUpdateSupported reports whether the running platform can replace its own executable in place.
func ShouldCheck ¶
ShouldCheck returns true if the cache is expired (past TTL) or missing.
func VerifySHA256 ¶
VerifySHA256 verifies that the file at filePath matches the expected hex checksum.
func WriteCache ¶
WriteCache writes the cache file to disk, creating the directory if needed.
func WriteCacheAt ¶
WriteCacheAt writes the cache file to a specific directory. Empty dir falls back to CacheDir().
Types ¶
type CacheFile ¶
type CacheFile struct {
LastCheck time.Time `json:"last_check"`
LatestVersion string `json:"latest_version"`
}
CacheFile represents the on-disk update check cache.
func ReadCache ¶
ReadCache reads the cache file from disk. Returns zero-value CacheFile if not found.
func ReadCacheAt ¶
ReadCacheAt reads the cache file from a specific directory. Empty dir falls back to CacheDir().
type CheckResult ¶
type CheckResult struct {
CurrentVersion string
LatestVersion string
UpdateAvailable bool
Release *Release
}
CheckResult is returned by check operations.
type Config ¶
type Config struct {
Repo string
BinaryName string
CurrentVer string
GitHubToken string
CacheDir string
CacheTTL time.Duration
HTTPClient *http.Client
}
Config holds configuration for the updater.
type Updater ¶
type Updater struct {
// contains filtered or unexported fields
}
Updater handles checking, downloading, and applying updates.
func (*Updater) CheckForUpdate ¶
func (u *Updater) CheckForUpdate(ctx context.Context) (*CheckResult, error)
CheckForUpdate queries the GitHub Releases API and compares versions. It uses the cache to avoid redundant API calls within CacheTTL.
func (*Updater) CheckSpecificVersion ¶
CheckSpecificVersion checks for a specific version tag.