Documentation
¶
Index ¶
- Constants
- Variables
- func ApplyStagedUpdate() (string, error)
- func CleanStagedUpdate()
- func HasStagedUpdate() bool
- func IsCacheValid(cache *CacheFile, channel Channel) bool
- func IsPackageManagerInstall() bool
- func PackageManagerUninstallCmd(installedBy installer.InstallType) string
- func ParseDailyBuildNumber(version string) (int, error)
- func ReadAppliedMarker() (string, error)
- func RemoveAppliedMarker()
- func SaveAutoUpdate(cfg config.Config, enabled bool) error
- func SaveCache(cache *CacheFile) error
- func SaveChannel(cfg config.Config, channel Channel) error
- func SaveCheckIntervalHours(cfg config.Config, hours int) error
- func StagedBinaryPath() (string, error)
- func WriteAppliedMarker(fromVersion string)
- type CacheFile
- type Channel
- type Manager
- type UpdateConfig
- type UpdateError
- type VersionInfo
Constants ¶
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 )
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" )
Result codes matching the design doc.
Variables ¶
var ErrNeedsElevation = fmt.Errorf("applying staged update requires elevation")
ErrNeedsElevation is returned when the staged update can't be applied without elevation.
var FeatureUpdate = alpha.MustFeatureKey("update")
FeatureUpdate is the alpha feature key for the azd update command.
Functions ¶
func ApplyStagedUpdate ¶
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 IsCacheValid ¶
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 ¶
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 ¶
ReadAppliedMarker reads the applied update marker and returns the previous version.
func RemoveAppliedMarker ¶
func RemoveAppliedMarker()
RemoveAppliedMarker deletes the applied update marker file.
func SaveAutoUpdate ¶
SaveAutoUpdate persists the auto-update setting to user config.
func SaveChannel ¶
SaveChannel persists the channel to user config.
func SaveCheckIntervalHours ¶
SaveCheckIntervalHours persists the check interval to user config.
func StagedBinaryPath ¶
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.
type Channel ¶
type Channel string
Channel represents the update channel for azd builds.
func ParseChannel ¶
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.
type UpdateConfig ¶
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