From 4fca4b71433a1001c759b3233e8ed376abcedeb9 Mon Sep 17 00:00:00 2001 From: Muse Date: Sat, 14 Nov 2026 18:09:30 +0800 Subject: [PATCH] =?UTF-8?q?fix(rust):=20spawn=5Fblocking=20=E6=94=B9?= =?UTF-8?q?=E8=B5=B0=20tauri::async=5Fruntime=EF=BC=88=E5=B7=A5=E7=A8=8B?= =?UTF-8?q?=E6=97=A0=20tokio=20=E4=BE=9D=E8=B5=96=EF=BC=8CWindows=20?= =?UTF-8?q?=E6=9E=84=E5=BB=BA=20E0433=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6 处 tokio::task::spawn_blocking(Git 同步 4 处 + docs/29 资源 命令 2 处)全部换成工程既有写法 tauri::async_runtime::spawn_blocking; 全量核对源码外部 crate 前缀与 Cargo.toml 依赖一致。docs/29 补勘误。 --- docs/29-全项目审计.md | 8 ++++++++ src-tauri/src/commands.rs | 12 ++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/docs/29-全项目审计.md b/docs/29-全项目审计.md index 671cda9..7187851 100644 --- a/docs/29-全项目审计.md +++ b/docs/29-全项目审计.md @@ -190,3 +190,11 @@ src-tauri/src/ 全部(1289 行)。先说结论:发现 **1 个高危数据 - H1 的守卫交错无法在 jsdom 自动化复现(见上),真机侧可用 「打开 >60K 文档后立刻连开多个标签挤掉其窗格,再回看该文档 是否完整」一验。 +- **勘误(2026-11-14 晚,Windows 构建回报)**:本轮 M1 与 docs/27 + 的 Git 命令共 6 处用了 `tokio::task::spawn_blocking`,但工程并 + 没有 tokio 直接依赖(Cargo.toml 只有 tauri 等 7 个),Windows + 构建报 E0433。已全部改为工程既有写法的 + `tauri::async_runtime::spawn_blocking`(read/write 命令一直在 + 用),并全量核对源码中所有外部 crate 前缀与 Cargo.toml 依赖 + 一致、无其他幻影 crate。教训:写 Rust 时新引入的 crate 路径 + 必须先对 Cargo.toml 存量,沙箱无法完整编译时尤其如此。 diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index 7126acc..a5b508e 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -258,7 +258,7 @@ fn write_new_file(dir: &Path, file_name: &str, data: &[u8]) -> Result Result { - tokio::task::spawn_blocking(move || { + tauri::async_runtime::spawn_blocking(move || { let src = PathBuf::from(&source); let name = sanitize_file_name( &src.file_name() @@ -287,7 +287,7 @@ pub async fn save_bytes_to_assets( file_name: String, base64: String, ) -> Result { - tokio::task::spawn_blocking(move || { + tauri::async_runtime::spawn_blocking(move || { let name = sanitize_file_name(&file_name); let bytes = base64_decode(&base64)?; if bytes.len() as u64 > MAX_ASSET_BYTES { @@ -784,7 +784,7 @@ fn git_status_inner(root: &str) -> GitStatusInfo { #[tauri::command] pub async fn git_status(root: String) -> GitStatusInfo { - tokio::task::spawn_blocking(move || git_status_inner(&root)) + tauri::async_runtime::spawn_blocking(move || git_status_inner(&root)) .await .unwrap_or(GitStatusInfo { is_repo: false, @@ -799,7 +799,7 @@ pub async fn git_status(root: String) -> GitStatusInfo { #[tauri::command] pub async fn git_init_repo(root: String, remote_url: String, branch: String) -> Result { - tokio::task::spawn_blocking(move || { + tauri::async_runtime::spawn_blocking(move || { let dir = Path::new(&root); let b = validate_branch(&branch)?; let url = validate_remote_url(&remote_url)?; @@ -833,7 +833,7 @@ pub async fn git_init_repo(root: String, remote_url: String, branch: String) -> #[tauri::command] pub async fn git_set_remote(root: String, remote_url: String) -> Result { - tokio::task::spawn_blocking(move || { + tauri::async_runtime::spawn_blocking(move || { let dir = Path::new(&root); let url_owned = validate_remote_url(&remote_url)?; let url = url_owned.as_str(); @@ -855,7 +855,7 @@ pub async fn git_set_remote(root: String, remote_url: String) -> Result Result { - tokio::task::spawn_blocking(move || { + tauri::async_runtime::spawn_blocking(move || { let dir = Path::new(&root); let st = git_status_inner(&root); if !st.is_repo {