Skip to content

Commit d1059d5

Browse files
fiadlielautarch
authored andcommitted
Look for first matching file which is a _file_ in zip archive.
It is possible that the requested path in the zip can be found as a file, in addition to directory/symlink. The outcome if we don't filter by file type is confusing for the user, as the install can appear to succeed, but the result is an empty file.
1 parent f38abbd commit d1059d5

19 files changed

+30
-5
lines changed

Changes.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## $NEXT
22

3+
- Fixed a bug where `ubi` where zip files containing a directory that matched the expected
4+
executable name caused `ubi` to extract the directory instead of the actual executable, resulting
5+
in a 0-length file. Based on a PR #89 from @fiadliel (Gary Coady). Fixes #88.
36
- Added a new `UbiBuilder::rename_exe_to` method, along with a `--rename-exe-to` CLI flag. When this
47
is set, the installed executable will use the name given here, instead of the name that it has in
58
the downloaded file. This is useful for projects that do releases where the executable name

precious.toml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
exclude = ["target"]
1+
exclude = [
2+
"target",
3+
"**/*.AppImage",
4+
"**/*.bz",
5+
"**/*.bz2",
6+
"**/*.exe",
7+
"**/*.gz",
8+
"**/*.pyz",
9+
"**/*.tar",
10+
"**/*.tar.*",
11+
"**/*.xz",
12+
"**/*.zip",
13+
]
214

315
[commands.clippy]
416
type = "lint"
@@ -97,7 +109,6 @@ labels = ["default", "fast-tidy"]
97109
[commands.typos]
98110
type = "lint"
99111
include = "**/*"
100-
exclude = "**/*.tar.gz"
101112
cmd = "typos"
102113
invoke = "once"
103114
ok-exit-codes = 0

ubi/src/installer.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl ExeInstaller {
120120
for i in 0..zip.len() {
121121
let mut zf = zip.by_index(i)?;
122122
let path = PathBuf::from(zf.name());
123-
if path.ends_with(&self.exe) {
123+
if zf.is_file() && path.ends_with(&self.exe) {
124124
let mut buffer: Vec<u8> = Vec::with_capacity(usize::try_from(zf.size())?);
125125
zf.read_to_end(&mut buffer)?;
126126
self.create_install_dir()?;
@@ -442,10 +442,18 @@ mod tests {
442442
archive_path: PathBuf::from(archive_path),
443443
})?;
444444

445-
assert!(install_path.exists());
446445
assert!(install_path.is_file());
446+
// Testing the installed file's length is a shortcut to make sure we install the file we
447+
// expected to install.
448+
let meta = install_path.metadata()?;
449+
let expect_len = if install_path.extension().unwrap_or_default() == "pyz" {
450+
fs::metadata(archive_path)?.len()
451+
} else {
452+
3
453+
};
454+
assert_eq!(meta.len(), expect_len);
447455
#[cfg(target_family = "unix")]
448-
assert!(install_path.metadata()?.permissions().mode() & 0o111 != 0);
456+
assert!(meta.permissions().mode() & 0o111 != 0);
449457
}
450458

451459
Ok(())
21 Bytes
Binary file not shown.

ubi/test-data/project

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exe
12 Bytes
Binary file not shown.

ubi/test-data/project.AppImage

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exe

ubi/test-data/project.bz

25 Bytes
Binary file not shown.

ubi/test-data/project.bz2

25 Bytes
Binary file not shown.

ubi/test-data/project.exe

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exe

0 commit comments

Comments
 (0)