Skip to content

Commit

Permalink
Refactor: Run TempDir creation in block_in_place
Browse files Browse the repository at this point in the history
Since it could also issues blocking operations.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
  • Loading branch information
NobodyXu committed Aug 5, 2022
1 parent 32c5a77 commit 62317b6
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ async fn entry(jobserver_client: LazyJobserverClient) -> Result<()> {
// Initialize UI thread
let mut uithread = UIThread::new(!opts.no_confirm);

// Compute install directory
let (install_path, metadata) = block_in_place(|| -> Result<_> {
let (install_path, metadata, temp_dir) = block_in_place(|| -> Result<_> {
// Compute install directory
let (install_path, custom_install_path) = get_install_path(opts.install_path.as_deref());
let install_path = install_path.ok_or_else(|| {
error!("No viable install path found of specified, try `--install-path`");
Expand All @@ -342,7 +342,18 @@ async fn entry(jobserver_client: LazyJobserverClient) -> Result<()> {
None
};

Ok((install_path, metadata))
// Create a temporary directory for downloads etc.
//
// 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.")?;

Ok((install_path, metadata, temp_dir))
})?;

// Remove installed crates
Expand All @@ -356,17 +367,6 @@ async fn entry(jobserver_client: LazyJobserverClient) -> Result<()> {
}
});

// Create a temporary directory for downloads etc.
//
// 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.")?;

let temp_dir_path: Arc<Path> = Arc::from(temp_dir.path());

// Create binstall_opts
Expand Down

0 comments on commit 62317b6

Please sign in to comment.