upgrade

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package upgrade implements `dust upgrade` — checks GitHub Releases for a newer version, downloads the matching platform tarball, verifies its SHA256 checksum, and atomically replaces the running binary.

Index

Constants

View Source
const DefaultRepo = "ariefsn/dust"

DefaultRepo is the GitHub repo dust ships from. Override via DUST_REPO env var if you fork it.

Variables

This section is empty.

Functions

func CurrentBinaryPath

func CurrentBinaryPath() (string, error)

CurrentBinaryPath returns the absolute path of the currently running executable, resolving symlinks. Used to know what to overwrite.

func CurrentPlatform

func CurrentPlatform() (string, string)

CurrentPlatform returns the GOOS/GOARCH for the running binary.

func DownloadAndVerify

func DownloadAndVerify(rel *Release) (tarballPath, tempDir string, err error)

DownloadAndVerify fetches the release archive + checksums, verifies the SHA256, and returns the path to the verified tarball in a tempdir.

Caller must remove the returned tempdir when done.

func ExtractBinary

func ExtractBinary(tarballPath, tempDir string) (string, error)

ExtractBinary extracts the `dust` binary from `tarballPath` into `tempDir` and returns its path.

func IsManagedByGoInstall

func IsManagedByGoInstall(binPath string) bool

IsManagedByGoInstall reports whether the running binary appears to live under $GOPATH/bin or $GOBIN — the canonical `go install` locations. We refuse to self-update those because Go's tool chain expects to manage them.

func IsNewer

func IsNewer(current, latest string) bool

IsNewer compares two version strings (e.g. "v0.1.0" vs "v0.2.1") and reports whether `latest` is strictly greater than `current`. Returns false if either is unparseable, so a "dev" build never reports an available upgrade.

func Replace

func Replace(currentPath, newPath string) error

Replace atomically swaps the running binary with the new one. On macOS and Linux, os.Rename across the same filesystem is atomic. We rename the existing binary aside first so the caller can rollback on failure.

Types

type Release

type Release struct {
	Tag          string
	HTMLURL      string
	ArchiveURL   string // tarball for current platform
	ChecksumsURL string
}

Release describes a single GitHub release relevant to self-update.

func LatestRelease

func LatestRelease(repo, currentOS, currentArch string) (*Release, error)

LatestRelease returns metadata for the latest release of the given repo. `repo` is the "owner/name" form (e.g. "ariefsn/dust"). `currentOS` / `currentArch` should be runtime.GOOS / runtime.GOARCH; passing them in keeps the function testable.

func (*Release) EnsureAssets

func (r *Release) EnsureAssets(currentOS, currentArch string) error

EnsureAssets validates that the release carries the platform tarball and checksums file we need to install it. Caller invokes this only when an actual install is about to happen (skipping it for --check + dev-build flows that just want the tag string).

Jump to

Keyboard shortcuts

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