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 package;
25mod release;
26#[cfg(feature = "self-update")]
27mod replace;
28
29#[cfg(feature = "cli")]
30pub use install::UpdateArgs;
31#[cfg(all(feature = "cli", feature = "self-update"))]
32pub use install::run;
33pub use install::{
34    BinstallSource, InstallMethod, StoreKind, advice, advice_command, asset_name, cargo_home,
35    install_method, platform,
36};
37#[cfg(feature = "self-update")]
38pub use install::{download_asset, install};
39pub use package::{PackageState, PackageStatus};
40pub use release::{Asset, Release, ReleaseSource, client, latest_release};
41#[cfg(feature = "self-update")]
42pub use replace::replace_file;
43
44/// Errors from finding, fetching or installing a release.
45#[derive(Debug, thiserror::Error)]
46pub enum Error {
47    /// Talking to GitHub failed.
48    #[error("{0}")]
49    Http(String),
50    /// The repository has no release this source matches.
51    #[error("{0}")]
52    NoRelease(String),
53    /// The release has no file for this platform.
54    #[error("{0}")]
55    NoAsset(String),
56    /// The binary does not say where its releases are, or its own version is unusable.
57    #[error("{0}")]
58    NotConfigured(String),
59    /// Reading the executable or writing its replacement failed.
60    #[error(transparent)]
61    Io(#[from] std::io::Error),
62}
63
64/// This crate's result.
65pub type Result<T> = std::result::Result<T, Error>;