Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 18 additions & 7 deletions axoupdater-cli/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ fn write_receipt(
Ok(())
}

fn executable_tempdir() -> std::io::Result<TempDir> {
if let Some(runtime_dir) = std::env::var_os("XDG_RUNTIME_DIR") {
tempfile::Builder::new()
.prefix("axoupdater-exec")
.tempdir_in(runtime_dir)
} else {
TempDir::new()
}
}

#[test]
fn bails_out_with_default_name() {
let mut command = Cmd::new(BIN, "execute axoupdater");
Expand All @@ -81,7 +91,7 @@ fn bails_out_with_default_name() {
// several noteworthy bugfixes in its installer.
#[test]
fn test_upgrade() -> std::io::Result<()> {
let tempdir = TempDir::new()?;
let tempdir = executable_tempdir()?;
let bindir_path = &tempdir.path().join("bin");
let bindir = Utf8Path::from_path(bindir_path).unwrap();
std::fs::create_dir_all(bindir)?;
Expand Down Expand Up @@ -144,7 +154,7 @@ fn test_upgrade() -> std::io::Result<()> {

#[test]
fn test_upgrade_xdg_config_home() -> std::io::Result<()> {
let tempdir = TempDir::new()?;
let tempdir = executable_tempdir()?;
let bindir_path = &tempdir.path().join("bin");
let bindir = Utf8Path::from_path(bindir_path).unwrap();
std::fs::create_dir_all(bindir)?;
Expand Down Expand Up @@ -209,7 +219,7 @@ fn test_upgrade_xdg_config_home() -> std::io::Result<()> {

#[test]
fn test_upgrade_allow_prerelease() -> std::io::Result<()> {
let tempdir = TempDir::new()?;
let tempdir = executable_tempdir()?;
let bindir_path = &tempdir.path().join("bin");
let bindir = Utf8Path::from_path(bindir_path).unwrap();
std::fs::create_dir_all(bindir)?;
Expand Down Expand Up @@ -276,7 +286,8 @@ fn test_upgrade_allow_prerelease() -> std::io::Result<()> {
#[test]
fn test_upgrade_to_specific_version() -> std::io::Result<()> {
let tempdir = TempDir::new()?;
let bindir_path = &tempdir.path().join("bin");
let executable_tmp = executable_tempdir()?;
let bindir_path = &executable_tmp.path().join("bin");
let bindir = Utf8Path::from_path(bindir_path).unwrap();
std::fs::create_dir_all(bindir)?;

Expand Down Expand Up @@ -334,7 +345,7 @@ fn test_upgrade_to_specific_version() -> std::io::Result<()> {
// version on request instead of upgrading.
#[test]
fn test_downgrade_to_specific_version() -> std::io::Result<()> {
let tempdir = TempDir::new()?;
let tempdir = executable_tempdir()?;
let bindir_path = &tempdir.path().join("bin");
let bindir = Utf8Path::from_path(bindir_path).unwrap();
std::fs::create_dir_all(bindir)?;
Expand Down Expand Up @@ -406,7 +417,7 @@ fn test_downgrade_to_specific_old_version() -> std::io::Result<()> {
_ => return Ok(()),
}

let tempdir = TempDir::new()?;
let tempdir = executable_tempdir()?;
let bindir_path = &tempdir.path().join("bin");
let bindir = Utf8Path::from_path(bindir_path).unwrap();
std::fs::create_dir_all(bindir)?;
Expand Down Expand Up @@ -469,7 +480,7 @@ fn test_downgrade_to_specific_old_version() -> std::io::Result<()> {
// https://github.com/axodotdev/cargo-dist/pull/1037
#[test]
fn test_upgrade_from_prefix_with_no_bin() -> std::io::Result<()> {
let tempdir = TempDir::new()?;
let tempdir = executable_tempdir()?;
let prefix = Utf8PathBuf::from_path_buf(tempdir.path().to_path_buf()).unwrap();
let bindir_path = &tempdir.path().join("bin");
let bindir = Utf8Path::from_path(bindir_path).unwrap();
Expand Down
4 changes: 4 additions & 0 deletions axoupdater/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@ tokio = { version = "1.48.0", features = ["full"], optional = true }
# errors
miette = "7.2.0"
thiserror = "2.0.0"
directories = "6.0.0"

[target.'cfg(windows)'.dependencies]
self-replace = "1.5.0"

[target.'cfg(unix)'.dependencies]
libc = "0.2"

[dev-dependencies]
tokio = { version = "1.48.0", features = ["test-util"] }
httpmock = "0.8.2"
Expand Down
14 changes: 11 additions & 3 deletions axoupdater/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
pub mod errors;
mod receipt;
mod release;
mod staging_dir;
pub mod test;

pub use errors::*;
Expand All @@ -27,8 +28,7 @@ use axoasset::LocalAsset;
use axoprocess::Cmd;
pub use axotag::Version;
use camino::Utf8PathBuf;

use tempfile::TempDir;
use staging_dir::select_installer_tempdir;

/// Version number for this release of axoupdater.
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
Expand Down Expand Up @@ -420,7 +420,13 @@ impl AxoUpdater {
self.requested_release.as_ref().unwrap()
}
};
let tempdir = TempDir::new()?;
let tempdir_parent_name = self
.source
.as_ref()
.map(|source| source.name.as_str())
.or(self.name.as_deref())
.unwrap_or("axoupdater");
let mut _staging_dir_guard = None;

// If we've been given an installer path to use, skip downloading and
// install from that.
Expand All @@ -429,6 +435,7 @@ impl AxoUpdater {
// Otherwise, proceed with downloading the installer from the release
// we just looked up.
} else {
let tempdir = select_installer_tempdir(tempdir_parent_name)?;
let app_name = self.name.clone().unwrap_or_default();
let installer_url = match env::consts::OS {
"macos" | "linux" => release
Expand Down Expand Up @@ -474,6 +481,7 @@ impl AxoUpdater {
.await?;

LocalAsset::write_new_all(&download, &installer_path)?;
_staging_dir_guard = Some(tempdir);

installer_path
};
Expand Down
Loading