Skip to content
1        10        20        30        40        50        60        70        80        901use std::{ffi::OsString, path::Path, process::Command};23use super::error::OnceError;45pub fn run() -> Result<(), OnceError> {6    let status = if let Some(script) = std::env::var_os("INO_SELF_UPDATE_SCRIPT") {7        run_script(Path::new(&script))?8    } else {9        run_cargo_update()?10    };1112    if !status.success() {13        return Err(OnceError::CommandExit(status.code().unwrap_or(1)));14    }15    println!("Ino updated");16    Ok(())17}1819fn run_script(script: &Path) -> Result<std::process::ExitStatus, OnceError> {20    Command::new(script).status().map_err(|error| {21        OnceError::Context(22            crate::error::ContextError::new(23                format!("starting self-update script `{}`", script.display()),24                error,25            )26            .with_suggestion("check that the script exists and is executable"),27        )28    })29}3031fn run_cargo_update() -> Result<std::process::ExitStatus, OnceError> {32    let repository = option_env!("CARGO_PKG_REPOSITORY")33        .filter(|repository| !repository.is_empty())34        .ok_or_else(|| OnceError::Io("Ino repository URL is not configured".into()))?;3536    let args: [OsString; 4] = [37        "install".into(),38        "--git".into(),39        repository.into(),40        "--force".into(),41    ];42    Command::new("cargo")43        .args(args)44        .arg("--locked")45        .status()46        .map_err(|error| {47            OnceError::Context(48                crate::error::ContextError::new("starting Cargo to update Ino", error)49                    .with_suggestion("install Rust and ensure `cargo` is available on PATH"),50            )51        })52}