Skip to content

Commit

Permalink
feat(tauri-build): validate sidecar name, closes #4780 closes #4823 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Aug 2, 2022
1 parent d576e8a commit 5cc1fd0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changes/validate-sidecar-name.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-build": patch
---

Return an error if a sidecar is configured with the same file name as the application.
29 changes: 21 additions & 8 deletions core/tauri-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,29 @@ fn copy_file(from: impl AsRef<Path>, to: impl AsRef<Path>) -> 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();
}
Expand Down Expand Up @@ -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),
)?;
}

Expand Down

0 comments on commit 5cc1fd0

Please sign in to comment.