From 0f2789cd6767e2eadbc4f7dfe32e2173e972b9a0 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Sun, 4 Feb 2024 08:45:59 -0300 Subject: [PATCH] fix(build): do not rewrite unchanged schema (#8757) * fix(build): do not rewrite unchanged schema * typo --- .changes/fix-rewrite-schema.md | 5 ++++ core/tauri-build/src/acl.rs | 32 +++++++++++++------------- core/tauri-utils/src/acl/capability.rs | 2 +- examples/api/src-tauri/Cargo.lock | 2 +- 4 files changed, 23 insertions(+), 18 deletions(-) create mode 100644 .changes/fix-rewrite-schema.md diff --git a/.changes/fix-rewrite-schema.md b/.changes/fix-rewrite-schema.md new file mode 100644 index 00000000000..eec0c0c8ac7 --- /dev/null +++ b/.changes/fix-rewrite-schema.md @@ -0,0 +1,5 @@ +--- +"tauri-build": patch:bug +--- + +Do not rewrite capability JSON schema if it did not change. diff --git a/core/tauri-build/src/acl.rs b/core/tauri-build/src/acl.rs index ebf3d75e865..a4617414dac 100644 --- a/core/tauri-build/src/acl.rs +++ b/core/tauri-build/src/acl.rs @@ -4,8 +4,7 @@ use std::{ collections::{BTreeMap, BTreeSet}, - fs::{copy, create_dir_all, read_to_string, File}, - io::{BufWriter, Write}, + fs::{copy, create_dir_all, read_to_string, write}, path::PathBuf, }; @@ -181,20 +180,21 @@ pub fn generate_schema( create_dir_all(&out_dir).context("unable to create schema output directory")?; let schema_path = out_dir.join(format!("{target}-{CAPABILITIES_SCHEMA_FILE_NAME}")); - let mut schema_file = BufWriter::new(File::create(&schema_path)?); - write!(schema_file, "{schema_str}")?; - - copy( - schema_path, - out_dir.join(format!( - "{}-{CAPABILITIES_SCHEMA_FILE_NAME}", - if target.is_desktop() { - "desktop" - } else { - "mobile" - } - )), - )?; + if schema_str != read_to_string(&schema_path).unwrap_or_default() { + write(&schema_path, "{schema_str}")?; + + copy( + schema_path, + out_dir.join(format!( + "{}-{CAPABILITIES_SCHEMA_FILE_NAME}", + if target.is_desktop() { + "desktop" + } else { + "mobile" + } + )), + )?; + } Ok(()) } diff --git a/core/tauri-utils/src/acl/capability.rs b/core/tauri-utils/src/acl/capability.rs index dfe234d699a..4f35ae782f0 100644 --- a/core/tauri-utils/src/acl/capability.rs +++ b/core/tauri-utils/src/acl/capability.rs @@ -56,7 +56,7 @@ pub struct Capability { pub description: String, /// Execution context of the capability. /// - /// At runtime, Tauri filters the IPC command together with the context to determine wheter it is allowed or not and its scope. + /// At runtime, Tauri filters the IPC command together with the context to determine whether it is allowed or not and its scope. #[serde(default)] pub context: CapabilityContext, /// List of windows that uses this capability. Can be a glob pattern. diff --git a/examples/api/src-tauri/Cargo.lock b/examples/api/src-tauri/Cargo.lock index e9d1b9d2f9b..b8f31079dd2 100644 --- a/examples/api/src-tauri/Cargo.lock +++ b/examples/api/src-tauri/Cargo.lock @@ -3677,7 +3677,7 @@ checksum = "69758bda2e78f098e4ccb393021a0963bb3442eac05f135c30f61b7370bbafae" [[package]] name = "tauri" -version = "2.0.0-beta.0" +version = "2.0.0-beta.1" dependencies = [ "anyhow", "bytes",