pub use crate::binary_ops::{
DownloadUrls, cleanup_old_binary, compute_data_hash, get_asset_name, get_binary_download_url,
get_checksum_asset_name, get_download_urls,
};
pub use crate::install_methods::{InstallationType, detect_installation};
use crate::binary_ops::verify_download;
use crate::install_methods::{install_macos_bundle, install_standalone};
use std::path::PathBuf;
#[derive(Debug, Clone)]
pub struct UpdateResult {
pub old_version: String,
pub new_version: String,
pub install_path: PathBuf,
pub needs_restart: bool,
}
pub fn perform_update(new_version: &str, old_version: &str) -> Result<UpdateResult, String> {
let installation = detect_installation();
match &installation {
InstallationType::Homebrew => {
return Err(
"par-term is installed via Homebrew. Please update with:\n \
brew upgrade --cask par-term"
.to_string(),
);
}
InstallationType::CargoInstall => {
return Err("par-term is installed via cargo. Please update with:\n \
cargo install par-term"
.to_string());
}
InstallationType::MacOSBundle | InstallationType::StandaloneBinary => {
}
}
let current_exe =
std::env::current_exe().map_err(|e| format!("Failed to determine current exe: {}", e))?;
let api_url = "https://api.github.com/repos/paulrobello/par-term/releases/latest";
let urls = get_download_urls(api_url)?;
let data = crate::http::download_file(&urls.binary_url)?;
crate::http::validate_binary_content(&data)?;
verify_download(&data, urls.checksum_url.as_deref())?;
let install_path = match installation {
InstallationType::MacOSBundle => install_macos_bundle(¤t_exe, &data)?,
InstallationType::StandaloneBinary => install_standalone(¤t_exe, &data)?,
_ => unreachable!("Managed installations are rejected above"),
};
Ok(UpdateResult {
old_version: old_version.to_string(),
new_version: new_version.to_string(),
install_path,
needs_restart: true,
})
}