Skip to main content

Updater

Struct Updater 

Source
pub struct Updater {
    pub client: Client,
    pub owner: String,
    pub name: String,
    pub version: String,
    pub latest_version: Option<String>,
    pub download_url: Option<String>,
    /* private fields */
}
Expand description

The update workflow: check the latest tag, download the platform asset, swap the binary keeping the old one as .bak.

Fields§

§client: Client§owner: String

Repository owner, from build-time metadata.

§name: String

Repository/app name, from build-time metadata.

§version: String

Version of the running binary.

§latest_version: Option<String>

Newer version found by the check, if any.

§download_url: Option<String>

Asset URL for this platform, set when a newer version is found.

Implementations§

Source§

impl Updater

Source

pub fn new() -> Result<Self>

Builds an updater from build-time metadata.

use kasl::libs::update::Updater;

let updater = Updater::new()?;
println!("Updater configured for {} v{}", updater.name, updater.version);
Source

pub async fn show_update_notification()

Prints an update notice when one is available - throttled to one check per day, and silent on any failure, so startup never blocks or complains because of the network.

use kasl::libs::update::Updater;

// Call during application startup
Updater::show_update_notification().await;
Source

pub async fn perform_update(&self) -> Result<Outcome>

Downloads the release archive and swaps the binary in.

Requires a prior successful Updater::check_for_latest_release (it sets download_url). The old executable stays next to the new one as .bak - restoring it is a manual copy, nothing automatic.

use kasl::libs::update::Updater;

let mut updater = Updater::new()?;
if updater.check_for_latest_release().await? {
    updater.perform_update().await?;
    println!("Update completed successfully");
}
Source

pub async fn check_for_latest_release(&mut self) -> Result<bool>

Compares the latest published tag against the running version; on a newer one, stores it and the platform asset URL.

use kasl::libs::update::Updater;

let mut updater = Updater::new()?;
if updater.check_for_latest_release().await? {
    println!("Update available: {} -> {}",
        updater.version,
        updater.latest_version.unwrap());
}
Source

pub fn sweep_backup()

Deletes the executable a previous update left behind as .bak.

Called on every command rather than from the update alone: after updating, nobody has a reason to run the updater again, and the leftover is a whole 15 MB binary that nothing ever comes back for. It exists because Windows will not delete a running image - the outgoing file is renamed aside instead - and it can only be removed once it is no longer the running one, which is the next command.

Best-effort: still locked means the next command tries again.

Trait Implementations§

Source§

impl Debug for Updater

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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<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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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<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