From fb35863faa7aa7d8ce7efba478fffb5aa5d844ac Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Fri, 22 Jul 2022 17:08:02 +1000 Subject: [PATCH] Create `temp_dir` in `install_path` Signed-off-by: Jiahao XU --- src/main.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 2061ee8d..c759de50 100644 --- a/src/main.rs +++ b/src/main.rs @@ -250,7 +250,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.")?;