From cd1d026f9799c26b04acb64f49e7ee0a8b193049 Mon Sep 17 00:00:00 2001 From: Tony <68118705+Legend-Master@users.noreply.github.com> Date: Tue, 7 Jan 2025 20:22:43 +0800 Subject: [PATCH] fix: fails to build if the project path contains glob characters (#11961) * Escape glob patterns * Add change file * Reword the change --- .changes/escape-glob.md | 7 +++++++ crates/tauri-build/src/acl.rs | 14 +++++++++----- .../tauri-bundler/src/bundle/windows/msi/mod.rs | 17 ++++++++++------- crates/tauri/Cargo.toml | 1 + crates/tauri/build.rs | 16 +++++++++++----- 5 files changed, 38 insertions(+), 17 deletions(-) create mode 100644 .changes/escape-glob.md diff --git a/.changes/escape-glob.md b/.changes/escape-glob.md new file mode 100644 index 000000000000..67988e697bae --- /dev/null +++ b/.changes/escape-glob.md @@ -0,0 +1,7 @@ +--- +"tauri": "patch:bug" +"tauri-build": "patch:bug" +"tauri-bundler": "patch:bug" +--- + +Fix tauri fails to build if the project path contains glob characters diff --git a/crates/tauri-build/src/acl.rs b/crates/tauri-build/src/acl.rs index d1a1e6f647ca..be6512ab357a 100644 --- a/crates/tauri-build/src/acl.rs +++ b/crates/tauri-build/src/acl.rs @@ -199,7 +199,9 @@ permissions = [{default_permissions}] } tauri_utils::acl::build::define_permissions( - &plugin_out_dir.join("*").to_string_lossy(), + &PathBuf::from(glob::Pattern::escape(&plugin_out_dir.to_string_lossy())) + .join("*") + .to_string_lossy(), name, &plugin_out_dir, |_| true, @@ -222,10 +224,12 @@ permissions = [{default_permissions}] ); } permission_files.extend(tauri_utils::acl::build::define_permissions( - &default_permissions_path - .join("**") - .join("*") - .to_string_lossy(), + &PathBuf::from(glob::Pattern::escape( + &default_permissions_path.to_string_lossy(), + )) + .join("**") + .join("*") + .to_string_lossy(), name, &plugin_out_dir, |_| true, diff --git a/crates/tauri-bundler/src/bundle/windows/msi/mod.rs b/crates/tauri-bundler/src/bundle/windows/msi/mod.rs index e899c52e913a..6eef04fae0f1 100644 --- a/crates/tauri-bundler/src/bundle/windows/msi/mod.rs +++ b/crates/tauri-bundler/src/bundle/windows/msi/mod.rs @@ -929,12 +929,11 @@ fn get_merge_modules(settings: &Settings) -> crate::Result> { let mut merge_modules = Vec::new(); let regex = Regex::new(r"[^\w\d\.]")?; for msm in glob::glob( - settings - .project_out_directory() - .join("*.msm") - .to_string_lossy() - .to_string() - .as_str(), + &PathBuf::from(glob::Pattern::escape( + &settings.project_out_directory().to_string_lossy(), + )) + .join("*.msm") + .to_string_lossy(), )? { let path = msm?; let filename = path @@ -1042,7 +1041,11 @@ fn generate_resource_data(settings: &Settings) -> crate::Result { let mut dlls = Vec::new(); let out_dir = settings.project_out_directory(); - for dll in glob::glob(out_dir.join("*.dll").to_string_lossy().to_string().as_str())? { + for dll in glob::glob( + &PathBuf::from(glob::Pattern::escape(&out_dir.to_string_lossy())) + .join("*.dll") + .to_string_lossy(), + )? { let path = dll?; let resource_path = dunce::simplified(&path); let relative_path = path diff --git a/crates/tauri/Cargo.toml b/crates/tauri/Cargo.toml index d5492ed72195..83b83ea6ba61 100644 --- a/crates/tauri/Cargo.toml +++ b/crates/tauri/Cargo.toml @@ -136,6 +136,7 @@ libc = "0.2" swift-rs = "1" [build-dependencies] +glob = "0.3" heck = "0.5" tauri-build = { path = "../tauri-build/", default-features = false, version = "2.0.4" } tauri-utils = { path = "../tauri-utils/", version = "2.1.1", features = [ diff --git a/crates/tauri/build.rs b/crates/tauri/build.rs index 86eb0f55897d..ed8f57cb008d 100644 --- a/crates/tauri/build.rs +++ b/crates/tauri/build.rs @@ -376,10 +376,12 @@ permissions = [{default_permissions}] .unwrap_or_else(|_| panic!("unable to autogenerate default permissions")); let permissions = tauri_utils::acl::build::define_permissions( - &permissions_out_dir - .join("**") - .join("*.toml") - .to_string_lossy(), + &PathBuf::from(glob::Pattern::escape( + &permissions_out_dir.to_string_lossy(), + )) + .join("**") + .join("*.toml") + .to_string_lossy(), &format!("tauri:{plugin}"), out_dir, |_| true, @@ -432,7 +434,11 @@ permissions = [{}] .unwrap_or_else(|_| panic!("unable to autogenerate core:default set")); let _ = tauri_utils::acl::build::define_permissions( - &permissions_out_dir.join("*.toml").to_string_lossy(), + &PathBuf::from(glob::Pattern::escape( + &permissions_out_dir.to_string_lossy(), + )) + .join("*.toml") + .to_string_lossy(), "tauri:core", out_dir, |_| true,