Skip to content

Commit 5cc1fd0

Browse files
authored
feat(tauri-build): validate sidecar name, closes #4780 closes #4823 (#4814)
1 parent d576e8a commit 5cc1fd0

2 files changed

Lines changed: 26 additions & 8 deletions

File tree

.changes/validate-sidecar-name.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-build": patch
3+
---
4+
5+
Return an error if a sidecar is configured with the same file name as the application.

core/tauri-build/src/lib.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,29 @@ fn copy_file(from: impl AsRef<Path>, to: impl AsRef<Path>) -> Result<()> {
3535
Ok(())
3636
}
3737

38-
fn copy_binaries<'a>(binaries: ResourcePaths<'a>, target_triple: &str, path: &Path) -> Result<()> {
38+
fn copy_binaries<'a>(
39+
binaries: ResourcePaths<'a>,
40+
target_triple: &str,
41+
path: &Path,
42+
package_name: Option<&String>,
43+
) -> Result<()> {
3944
for src in binaries {
4045
let src = src?;
4146
println!("cargo:rerun-if-changed={}", src.display());
42-
let dest = path.join(
43-
src
44-
.file_name()
45-
.expect("failed to extract external binary filename")
46-
.to_string_lossy()
47-
.replace(&format!("-{}", target_triple), ""),
48-
);
47+
let file_name = src
48+
.file_name()
49+
.expect("failed to extract external binary filename")
50+
.to_string_lossy()
51+
.replace(&format!("-{}", target_triple), "");
52+
53+
if package_name.map_or(false, |n| n == &file_name) {
54+
return Err(anyhow::anyhow!(
55+
"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.",
56+
file_name
57+
));
58+
}
59+
60+
let dest = path.join(file_name);
4961
if dest.exists() {
5062
std::fs::remove_file(&dest).unwrap();
5163
}
@@ -270,6 +282,7 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
270282
ResourcePaths::new(external_binaries(paths, &target_triple).as_slice(), true),
271283
&target_triple,
272284
target_dir,
285+
manifest.package.as_ref().map(|p| &p.name),
273286
)?;
274287
}
275288

0 commit comments

Comments
 (0)