mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-21 13:08:42 +00:00
Refactor: Run TempDir
creation in block_in_place
Since it could also issues blocking operations. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
b8c44839c1
commit
4b79abeedc
1 changed files with 14 additions and 14 deletions
28
src/main.rs
28
src/main.rs
|
@ -321,8 +321,8 @@ async fn entry(jobserver_client: LazyJobserverClient) -> Result<()> {
|
||||||
// Initialize UI thread
|
// Initialize UI thread
|
||||||
let mut uithread = UIThread::new(!opts.no_confirm);
|
let mut uithread = UIThread::new(!opts.no_confirm);
|
||||||
|
|
||||||
// Compute install directory
|
let (install_path, metadata, temp_dir) = block_in_place(|| -> Result<_> {
|
||||||
let (install_path, metadata) = block_in_place(|| -> Result<_> {
|
// Compute install directory
|
||||||
let (install_path, custom_install_path) = get_install_path(opts.install_path.as_deref());
|
let (install_path, custom_install_path) = get_install_path(opts.install_path.as_deref());
|
||||||
let install_path = install_path.ok_or_else(|| {
|
let install_path = install_path.ok_or_else(|| {
|
||||||
error!("No viable install path found of specified, try `--install-path`");
|
error!("No viable install path found of specified, try `--install-path`");
|
||||||
|
@ -339,7 +339,18 @@ async fn entry(jobserver_client: LazyJobserverClient) -> Result<()> {
|
||||||
None
|
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
|
// Remove installed crates
|
||||||
|
@ -353,17 +364,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());
|
let temp_dir_path: Arc<Path> = Arc::from(temp_dir.path());
|
||||||
|
|
||||||
// Create binstall_opts
|
// Create binstall_opts
|
||||||
|
|
Loading…
Add table
Reference in a new issue