Skip to main content

corundum_framework_update/
lib.rs

1//! Newer releases of an app's binary: finding them, and installing one.
2//!
3//! A binary's releases are a GitHub repository's, tagged `<prefix><version>`
4//! ([`ReleaseSource`]). [`latest_release`] finds the newest; the app server asks it once a
5//! day and shows the answer in `status`. The `update` command (`UpdateArgs`) goes one step
6//! further and replaces the running executable with the release's, but only:
7//!
8//! - with a newer version: never a downgrade;
9//! - with the asset for this platform, `<asset>-<os>-<arch>[.exe]`, downloaded over HTTPS
10//!   from the repository's own release: GitHub is the authority on what was released;
11//! - when the executable was placed by hand, not by `cargo install`, `cargo binstall` or a
12//!   package manager, whose own bookkeeping a replaced file would contradict ([`InstallMethod`]).
13//!
14//! Downloading and replacing are behind the `self-update` feature (on by default), the
15//! command line (`UpdateArgs`, `run`) behind `cli`; without `self-update` the crate only looks
16//! releases up and words [`advice`].
17//!
18//! Restarting afterwards is the caller's: the CLI says so, and the GUI panel restarts the
19//! app, its services or a bridge itself.
20
21#![warn(missing_docs)]
22
23mod install;
24mod release;
25#[cfg(feature = "self-update")]
26mod replace;
27
28#[cfg(feature = "cli")]
29pub use install::UpdateArgs;
30#[cfg(all(feature = "cli", feature = "self-update"))]
31pub use install::run;
32pub use install::{
33    BinstallSource, InstallMethod, StoreKind, advice, advice_command, asset_name, cargo_home,
34    install_method, platform,
35};
36#[cfg(feature = "self-update")]
37pub use install::{download_asset, install};
38pub use release::{Asset, Release, ReleaseSource, client, latest_release};
39#[cfg(feature = "self-update")]
40pub use replace::replace_file;
41
42/// Errors from finding, fetching or installing a release.
43#[derive(Debug, thiserror::Error)]
44pub enum Error {
45    /// Talking to GitHub failed.
46    #[error("{0}")]
47    Http(String),
48    /// The repository has no release this source matches.
49    #[error("{0}")]
50    NoRelease(String),
51    /// The release has no file for this platform.
52    #[error("{0}")]
53    NoAsset(String),
54    /// The binary does not say where its releases are, or its own version is unusable.
55    #[error("{0}")]
56    NotConfigured(String),
57    /// Reading the executable or writing its replacement failed.
58    #[error(transparent)]
59    Io(#[from] std::io::Error),
60}
61
62/// This crate's result.
63pub type Result<T> = std::result::Result<T, Error>;