Skip to content

Commit

Permalink
fix(packager): crash when packaging empty file on macOS (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog-crabnebula authored Apr 15, 2024
1 parent 8e54d00 commit b04332c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changes/ignore-empty-files.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"cargo-packager": patch
---

Fixes a crash when packaging `.app` if an empty file is included in the bundle.
43 changes: 43 additions & 0 deletions bindings/packager/nodejs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,49 @@ switch (platform) {
loadError = e
}
break
case 'riscv64':
if (isMusl()) {
localFileExisted = existsSync(
join(__dirname, 'packager.linux-riscv64-musl.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./packager.linux-riscv64-musl.node')
} else {
nativeBinding = require('@crabnebula/packager-linux-riscv64-musl')
}
} catch (e) {
loadError = e
}
} else {
localFileExisted = existsSync(
join(__dirname, 'packager.linux-riscv64-gnu.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./packager.linux-riscv64-gnu.node')
} else {
nativeBinding = require('@crabnebula/packager-linux-riscv64-gnu')
}
} catch (e) {
loadError = e
}
}
break
case 's390x':
localFileExisted = existsSync(
join(__dirname, 'packager.linux-s390x-gnu.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./packager.linux-s390x-gnu.node')
} else {
nativeBinding = require('@crabnebula/packager-linux-s390x-gnu')
}
} catch (e) {
loadError = e
}
break
default:
throw new Error(`Unsupported architecture on Linux: ${arch}`)
}
Expand Down
3 changes: 2 additions & 1 deletion crates/packager/src/package/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ pub(crate) fn package(ctx: &Context) -> crate::Result<Vec<PathBuf>> {
}
};

if !metadata.is_file() {
// ignore folders and files that do not include at least the header size
if !metadata.is_file() || metadata.len() < 4 {
continue;
}

Expand Down

0 comments on commit b04332c

Please sign in to comment.