update

package
v1.23.14 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultCheckIntervalStable is the default check interval for the stable channel.
	DefaultCheckIntervalStable = 24 * time.Hour
	// DefaultCheckIntervalDaily is the default check interval for the daily channel.
	DefaultCheckIntervalDaily = 4 * time.Hour
)
View Source
const (
	CodeSuccess                  = "update.success"
	CodeAlreadyUpToDate          = "update.alreadyUpToDate"
	CodeDownloadFailed           = "update.downloadFailed"
	CodeReplaceFailed            = "update.replaceFailed"
	CodeElevationFailed          = "update.elevationFailed"
	CodePackageManagerFailed     = "update.packageManagerFailed"
	CodeVersionCheckFailed       = "update.versionCheckFailed"
	CodeChannelSwitchDecline     = "update.channelSwitchDowngrade"
	CodeSkippedCI                = "update.skippedCI"
	CodeSignatureInvalid         = "update.signatureInvalid"
	CodeElevationRequired        = "update.elevationRequired"
	CodeUnsupportedInstallMethod = "update.unsupportedInstallMethod"
	CodeNonStandardInstall       = "update.nonStandardInstall"
	CodeConfigFailed             = "update.configFailed"
	CodeInvalidInput             = "update.invalidInput"
)

Result codes matching the design doc.

Variables

View Source
var ErrNeedsElevation = fmt.Errorf("applying staged update requires elevation")

ErrNeedsElevation is returned when the staged update can't be applied without elevation.

Functions

func ApplyStagedUpdate

func ApplyStagedUpdate() (string, error)

ApplyStagedUpdate replaces the current binary with the staged one and cleans up. Returns the path to the new binary if applied, or empty string if no staged update exists. Returns ErrNeedsElevation if the install location is not writable (e.g. /opt/microsoft/azd/).

func CleanStagedUpdate

func CleanStagedUpdate()

CleanStagedUpdate removes any staged binary, e.g. when auto-update is disabled after staging.

func HasStagedUpdate

func HasStagedUpdate() bool

HasStagedUpdate returns true if a staged binary exists and is ready to apply.

func HasUpdateConfig added in v1.23.14

func HasUpdateConfig(cfg config.Config) bool

HasUpdateConfig returns true if the user has any update configuration set. Also returns true for the legacy alpha.update key so that users who previously enabled the alpha feature are treated as having update config (skipping the first-use notice and showing the "azd update" hint).

func IsCacheValid

func IsCacheValid(cache *CacheFile, channel Channel) bool

IsCacheValid checks if the cache is still valid (not expired) and matches the given channel.

func IsPackageManagerInstall

func IsPackageManagerInstall() bool

IsPackageManagerInstall returns true if azd was installed via a package manager.

func PackageManagerUninstallCmd

func PackageManagerUninstallCmd(installedBy installer.InstallType) string

PackageManagerUninstallCmd returns the uninstall command for the detected package manager.

func ParseDailyBuildNumber

func ParseDailyBuildNumber(version string) (int, error)

ParseDailyBuildNumber extracts the build number from a daily version string. e.g. "1.24.0-beta.1-daily.5935787" → 5935787 Also handles internal.Version format: "1.24.0-beta.1-daily.5935787 (commit ...)" → 5935787

func ReadAppliedMarker

func ReadAppliedMarker() (string, error)

ReadAppliedMarker reads the applied update marker and returns the previous version.

func RemoveAppliedMarker

func RemoveAppliedMarker()

RemoveAppliedMarker deletes the applied update marker file.

func SaveAutoUpdate

func SaveAutoUpdate(cfg config.Config, enabled bool) error

SaveAutoUpdate persists the auto-update setting to user config.

func SaveCache

func SaveCache(cache *CacheFile) error

SaveCache writes the cached version check result.

func SaveChannel

func SaveChannel(cfg config.Config, channel Channel) error

SaveChannel persists the channel to user config.

func SaveCheckIntervalHours

func SaveCheckIntervalHours(cfg config.Config, hours int) error

SaveCheckIntervalHours persists the check interval to user config.

func StagedBinaryPath

func StagedBinaryPath() (string, error)

StagedBinaryPath returns the path where a staged binary would be placed.

func WriteAppliedMarker

func WriteAppliedMarker(fromVersion string)

WriteAppliedMarker writes a marker file recording the version before auto-update. This is read on the next startup to display an "updated" banner.

Types

type CacheFile

type CacheFile struct {
	// Channel is the update channel this cache entry is for.
	Channel string `json:"channel,omitempty"`
	// Version is the semver of the latest version.
	Version string `json:"version"`
	// BuildNumber is the Azure DevOps build ID (used for daily builds).
	BuildNumber int `json:"buildNumber,omitempty"`
	// ExpiresOn is the time at which this cached value expires, stored as an RFC3339 timestamp.
	ExpiresOn string `json:"expiresOn"`
}

CacheFile represents the cached version check result.

func LoadCache

func LoadCache() (*CacheFile, error)

LoadCache reads the cached version check result.

type Channel

type Channel string

Channel represents the update channel for azd builds.

const (
	// ChannelStable represents the stable release channel.
	ChannelStable Channel = "stable"
	// ChannelDaily represents the daily build channel.
	ChannelDaily Channel = "daily"
)

func ParseChannel

func ParseChannel(s string) (Channel, error)

ParseChannel parses a string into a Channel value.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager handles checking for and applying azd updates.

func NewManager

func NewManager(commandRunner exec.CommandRunner, httpClient *http.Client) *Manager

NewManager creates a new update Manager.

func (*Manager) CheckForUpdate

func (m *Manager) CheckForUpdate(ctx context.Context, cfg *UpdateConfig, ignoreCache bool) (*VersionInfo, error)

CheckForUpdate checks whether a newer version of azd is available.

func (*Manager) StageUpdate

func (m *Manager) StageUpdate(ctx context.Context, cfg *UpdateConfig) error

StageUpdate downloads the latest binary to ~/.azd/staging/ for later apply. This is intended to run in the background without user interaction.

func (*Manager) Update

func (m *Manager) Update(ctx context.Context, cfg *UpdateConfig, writer io.Writer) error

Update performs the update based on the install method.

type UpdateConfig

type UpdateConfig struct {
	Channel            Channel
	AutoUpdate         bool
	CheckIntervalHours int
}

UpdateConfig holds the user's update preferences.

func LoadUpdateConfig

func LoadUpdateConfig(cfg config.Config) *UpdateConfig

LoadUpdateConfig reads update configuration from the user config. When no channel is explicitly configured, the channel is inferred from the running binary's version string so that daily builds automatically check the daily update source.

func (*UpdateConfig) DefaultCheckInterval

func (c *UpdateConfig) DefaultCheckInterval() time.Duration

DefaultCheckInterval returns the default check interval for the configured channel.

type UpdateError

type UpdateError struct {
	// Code is the telemetry result code (e.g. "update.downloadFailed").
	Code string
	// Err is the underlying error.
	Err error
}

UpdateError represents a typed update error with a result code for telemetry.

func (*UpdateError) Error

func (e *UpdateError) Error() string

func (*UpdateError) Unwrap

func (e *UpdateError) Unwrap() error

type VersionInfo

type VersionInfo struct {
	Version     string
	BuildNumber int
	Channel     Channel
	HasUpdate   bool
}

VersionInfo holds the result of a version check.

Jump to

Keyboard shortcuts

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