Skip to content

Commit

Permalink
Merge pull request #121 from axodotdev/windows_alt_temp_dir_path
Browse files Browse the repository at this point in the history
fix: avoid possible file rename across filesystem bounds on Windows
  • Loading branch information
Gankra authored May 30, 2024
2 parents 5526966 + a9c252b commit 76b07f3
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 15 deletions.
32 changes: 22 additions & 10 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion axoupdater-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ reqwest = { version = ">=0.11.0", default-features = false, features = [
"blocking",
"rustls-tls",
] }
temp-dir = "0.1.13"
tempfile = "3.10.1"

[[bin]]
name = "axoupdater"
2 changes: 1 addition & 1 deletion axoupdater-cli/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::io::Read;
use axoasset::LocalAsset;
use axoprocess::Cmd;
use camino::{Utf8Path, Utf8PathBuf};
use temp_dir::TempDir;
use tempfile::TempDir;

static BIN: &str = env!("CARGO_BIN_EXE_axoupdater");
static RECEIPT_TEMPLATE: &str = r#"{"binaries":["axolotlsay"],"install_prefix":"INSTALL_PREFIX","provider":{"source":"cargo-dist","version":"CARGO_DIST_VERSION"},"source":{"app_name":"axolotlsay","name":"cargodisttest","owner":"mistydemeo","release_type":"github"},"version":"VERSION"}"#;
Expand Down
2 changes: 1 addition & 1 deletion axoupdater/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ axotag = { version = "0.2.0" }
camino = { version = "1.1.6", features = ["serde1"] }
homedir = "0.2.1"
serde = "1.0.197"
temp-dir = "0.1.13"
tempfile = "3.10.1"

# axo releases
gazenot = { version = "0.3.1", features = ["client_lib"], optional = true }
Expand Down
17 changes: 15 additions & 2 deletions axoupdater/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use axoprocess::Cmd;
pub use axotag::Version;
use camino::Utf8PathBuf;

use temp_dir::TempDir;
use tempfile::TempDir;

/// Provides information about the result of the upgrade operation
pub struct UpdateResult {
Expand Down Expand Up @@ -448,7 +448,20 @@ impl AxoUpdater {
// NOTE: this TempDir needs to be held alive for the whole function.
let temp_root;
let to_restore = if cfg!(target_family = "windows") {
temp_root = TempDir::new()?;
// If we know the install prefix, place the temporary directory for
// the executable there. This is because the `rename` syscall can't
// rename an executable across filesystem bounds, and there's a
// chance the system temporary directory could be on a different
// drive than the executable is.
// (A copy-and-delete move won't work because Windows won't let us
// delete a running executable - the same reason we're moving it out
// of the way to begin with!)
// See https://github.com/axodotdev/axoupdater/issues/120.
temp_root = if let Ok(prefix) = self.install_prefix_root() {
TempDir::new_in(prefix)?
} else {
TempDir::new()?
};
let old_path = std::env::current_exe()?;
let old_filename = old_path.file_name().expect("current binary has no name!?");
let ourselves = temp_root.path().join(old_filename);
Expand Down

0 comments on commit 76b07f3

Please sign in to comment.