From b8c44839c1d470270dc7c983a153a700c97bbc86 Mon Sep 17 00:00:00 2001
From: Jiahao XU <Jiahao_XU@outlook.com>
Date: Fri, 5 Aug 2022 00:18:21 +1000
Subject: [PATCH] Detect install_path & load metadata in `block_in_place`

since they involves blocking fs io.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
---
 src/main.rs | 32 ++++++++++++++++++--------------
 1 file changed, 18 insertions(+), 14 deletions(-)

diff --git a/src/main.rs b/src/main.rs
index e8cb2191..bf7f4955 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -322,21 +322,25 @@ async fn entry(jobserver_client: LazyJobserverClient) -> Result<()> {
     let mut uithread = UIThread::new(!opts.no_confirm);
 
     // 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`");
-        miette!("No install path found or specified")
-    })?;
-    fs::create_dir_all(&install_path).map_err(BinstallError::Io)?;
-    debug!("Using install path: {}", install_path.display());
+    let (install_path, metadata) = block_in_place(|| -> Result<_> {
+        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`");
+            miette!("No install path found or specified")
+        })?;
+        fs::create_dir_all(&install_path).map_err(BinstallError::Io)?;
+        debug!("Using install path: {}", install_path.display());
 
-    // Load metadata
-    let metadata = if !custom_install_path {
-        debug!("Reading binstall/crates-v1.json");
-        Some(block_in_place(metafiles::binstall_v1::Records::load)?)
-    } else {
-        None
-    };
+        // Load metadata
+        let metadata = if !custom_install_path {
+            debug!("Reading binstall/crates-v1.json");
+            Some(metafiles::binstall_v1::Records::load()?)
+        } else {
+            None
+        };
+
+        Ok((install_path, metadata))
+    })?;
 
     // Remove installed crates
     let crate_names = CrateName::dedup(crate_names).filter(|crate_name| {