From 5cc1fd0f7b01b257a461d4e867ddc8cd5072ff15 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Tue, 2 Aug 2022 10:37:16 -0300 Subject: [PATCH] feat(tauri-build): validate sidecar name, closes #4780 closes #4823 (#4814) --- .changes/validate-sidecar-name.md | 5 +++++ core/tauri-build/src/lib.rs | 29 +++++++++++++++++++++-------- 2 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 .changes/validate-sidecar-name.md diff --git a/.changes/validate-sidecar-name.md b/.changes/validate-sidecar-name.md new file mode 100644 index 000000000..850d1263b --- /dev/null +++ b/.changes/validate-sidecar-name.md @@ -0,0 +1,5 @@ +--- +"tauri-build": patch +--- + +Return an error if a sidecar is configured with the same file name as the application. diff --git a/core/tauri-build/src/lib.rs b/core/tauri-build/src/lib.rs index 56aae0a4e..752136f0c 100644 --- a/core/tauri-build/src/lib.rs +++ b/core/tauri-build/src/lib.rs @@ -35,17 +35,29 @@ fn copy_file(from: impl AsRef, to: impl AsRef) -> Result<()> { Ok(()) } -fn copy_binaries<'a>(binaries: ResourcePaths<'a>, target_triple: &str, path: &Path) -> Result<()> { +fn copy_binaries<'a>( + binaries: ResourcePaths<'a>, + target_triple: &str, + path: &Path, + package_name: Option<&String>, +) -> Result<()> { for src in binaries { let src = src?; println!("cargo:rerun-if-changed={}", src.display()); - let dest = path.join( - src - .file_name() - .expect("failed to extract external binary filename") - .to_string_lossy() - .replace(&format!("-{}", target_triple), ""), - ); + let file_name = src + .file_name() + .expect("failed to extract external binary filename") + .to_string_lossy() + .replace(&format!("-{}", target_triple), ""); + + if package_name.map_or(false, |n| n == &file_name) { + return Err(anyhow::anyhow!( + "Cannot define a sidecar with the same name as the Cargo package name `{}`. Please change the sidecar name in the filesystem and the Tauri configuration.", + file_name + )); + } + + let dest = path.join(file_name); if dest.exists() { std::fs::remove_file(&dest).unwrap(); } @@ -270,6 +282,7 @@ pub fn try_build(attributes: Attributes) -> Result<()> { ResourcePaths::new(external_binaries(paths, &target_triple).as_slice(), true), &target_triple, target_dir, + manifest.package.as_ref().map(|p| &p.name), )?; }