Skip to main content

UpdateEngine

Struct UpdateEngine 

Source
pub struct UpdateEngine<S>
where S: UpdateSource,
{ /* private fields */ }
Expand description

Blocking update orchestrator: check → download → verify → install.

All methods block; the GPUI integration runs them on a background executor.

Implementations§

Source§

impl<S> UpdateEngine<S>
where S: UpdateSource,

Source

pub fn new(source: S, config: EngineConfig) -> UpdateEngine<S>

Build an engine from a source and configuration.

Source

pub fn current_version(&self) -> &Version

The configured current version.

Source

pub fn check(&self) -> Result<Option<Release>, Error>

Fetch the latest release, returning it only if it is newer than the current version (otherwise Ok(None)).

§Errors

Propagates source/network/parse errors. A newer release is rejected instead of returned when the Verification policy cannot be met (Error::VerificationRequired), or when its artifact or signature would not be fetched over HTTPS (Error::InsecureUrl).

Source

pub fn download( &self, release: &Release, progress: impl FnMut(u64, Option<u64>), ) -> Result<Artifact, Error>

Download the update and verify it according to the configured policies. Returns the Artifact to hand to install.

Files are fetched over HTTPS only, into a fresh directory that only the current user can access (or EngineConfig::download_dir, where an earlier download of the same artifact that still verifies is reused instead of fetched again). A download larger than the size the release publishes, or than EngineConfig::max_download_size, is cut off. The file is then checked against its SHA-256 and minisign signature (see Verification and VersionBinding), and on macOS the app inside must declare the release version and carry the expected code signature (see BundleVersion and CodeSigning).

With the delta feature (macOS and Linux), published deltas are tried first: the cheapest chain from the current version, if it is smaller than the full artifact. Each delta is downloaded, verified under the same policies, and applied to the files it expects, which are checked against the hashes recorded in the delta. The result is a directory holding the rebuilt bundle or executable. If anything in that path fails — no usable delta, a modified installation, a bad checksum or signature, a network error — the full release.asset is downloaded instead, so deltas can never make an update fail.

progress is called as (downloaded_bytes, total_bytes). After a failed delta attempt it restarts from zero for the full download.

To stop a download from another thread, use download_cancellable.

§Errors

Returns an error on download failure, if verification fails, if the policy requires a check the release cannot satisfy (Error::VerificationRequired), or, before anything is downloaded, if the update could not be installed where the app is (check_location).

Source

pub fn download_cancellable( &self, release: &Release, cancel: &CancelToken, progress: impl FnMut(u64, Option<u64>), ) -> Result<Artifact, Error>

download, stopping with Error::Cancelled once cancel is cancelled. See CancelToken for when a cancel takes effect. A cancelled download removes its partial file; a delta attempt that is cancelled does not fall back to the full download.

§Errors

As download, plus Error::Cancelled.

Source

pub fn check_location(&self, release: &Release) -> Result<(), Error>

Check that release could be installed where the app is, without downloading anything: see install::check_location. download runs this first; call it yourself to tell the user before offering the download.

§Errors

Error::Location when the app runs from a read-only place, such as a disk image or an App Translocation copy, and Error::Permission when the user may not write next to it.

Source

pub fn install(&self, artifact: &Artifact) -> Result<Installed, Error>

Install a downloaded artifact over the configured install root.

Only an Artifact returned by download is accepted, so nothing reaches the installer without passing the engine’s checks.

§Errors

Propagates install failures.

Source

pub fn remove_leftovers(&self)

Remove what an earlier install left beside the install root because the old version was still running, such as the previous .exe on Windows: see install::remove_leftovers. Call it at startup.

Source

pub fn ownership(&self, hints: &OwnershipHints) -> Ownership

Who keeps the installed app up to date: the app itself, a package manager, or the packager. See install::ownership. When it is not Ownership::SelfUpdate, tell the user how to update instead of offering to. When the install root is unknown, the app is taken to update itself.

Source

pub fn update_now( &self, progress: impl FnMut(u64, Option<u64>), ) -> Result<Option<Installed>, Error>

Run the full pipeline. Returns Ok(None) when already up to date.

§Errors

Propagates any check/download/verify/install error.

Auto Trait Implementations§

§

impl<S> Freeze for UpdateEngine<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for UpdateEngine<S>
where S: RefUnwindSafe,

§

impl<S> Send for UpdateEngine<S>

§

impl<S> Sync for UpdateEngine<S>

§

impl<S> Unpin for UpdateEngine<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for UpdateEngine<S>
where S: UnsafeUnpin,

§

impl<S> UnwindSafe for UpdateEngine<S>
where S: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more