diff --git a/src/main.rs b/src/main.rs index 2061ee8d..08a0c59d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,7 +11,6 @@ use clap::Parser; use log::{debug, error, info, warn, LevelFilter}; use miette::{miette, Result, WrapErr}; use simplelog::{ColorChoice, ConfigBuilder, TermLogger, TerminalMode}; -use tempfile::TempDir; use tokio::{runtime::Runtime, task::block_in_place}; use cargo_binstall::{binstall, *}; @@ -250,7 +249,13 @@ async fn entry(jobserver_client: LazyJobserverClient) -> Result<()> { debug!("Using install path: {}", install_path.display()); // Create a temporary directory for downloads etc. - let temp_dir = TempDir::new() + // + // Put all binaries to a temporary directory under `dst` first, catching + // some failure modes (e.g., out of space) before touching the existing + // binaries. This directory will get cleaned up via RAII. + let temp_dir = tempfile::Builder::new() + .prefix("cargo-binstall") + .tempdir_in(&install_path) .map_err(BinstallError::from) .wrap_err("Creating a temporary directory failed.")?;