Selaa lähdekoodia

fix(build): avoid copying resource onto itself (#9710)

* fix(build): avoid copying resource onto itself

closes #9666

* canonicalize once

---------

Co-authored-by: Lucas Nogueira <lucas@tauri.app>
Amr Bashir 1 vuosi sitten
vanhempi
sitoutus
19b696b61c
2 muutettua tiedostoa jossa 15 lisäystä ja 1 poistoa
  1. 6 0
      .changes/build-resource-target-same-src.md
  2. 9 1
      core/tauri-build/src/lib.rs

+ 6 - 0
.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.
+

+ 9 - 1
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(())
 }