From 19b696b61c95ced0f07dd7471565ad329a0badcf Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Tue, 28 May 2024 19:48:52 +0300 Subject: [PATCH] fix(build): avoid copying resource onto itself (#9710) * fix(build): avoid copying resource onto itself closes #9666 * canonicalize once --------- Co-authored-by: Lucas Nogueira --- .changes/build-resource-target-same-src.md | 6 ++++++ core/tauri-build/src/lib.rs | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 .changes/build-resource-target-same-src.md diff --git a/.changes/build-resource-target-same-src.md b/.changes/build-resource-target-same-src.md new file mode 100644 index 000000000..a394a7083 --- /dev/null +++ b/.changes/build-resource-target-same-src.md @@ -0,0 +1,6 @@ +--- +"tauri-build": "patch:bug" +--- + +Avoid copying resources if the target path is the same as source. + diff --git a/core/tauri-build/src/lib.rs b/core/tauri-build/src/lib.rs index 2134b14b0..46d6a2c76 100644 --- a/core/tauri-build/src/lib.rs +++ b/core/tauri-build/src/lib.rs @@ -93,10 +93,18 @@ fn copy_binaries( /// Copies resources to a path. fn copy_resources(resources: ResourcePaths<'_>, path: &Path) -> Result<()> { + let path = path.canonicalize()?; for resource in resources.iter() { let resource = resource?; + println!("cargo:rerun-if-changed={}", resource.path().display()); - copy_file(resource.path(), path.join(resource.target()))?; + + // avoid copying the resource if target is the same as source + let src = resource.path().canonicalize()?; + let target = path.join(resource.target()); + if src != target { + copy_file(src, target)?; + } } Ok(()) }