Skip to content

Commit e22f9e2

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 e22f9e2

19 files changed

+29
-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).
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: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
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+
]
213

314
[commands.clippy]
415
type = "lint"
@@ -97,7 +108,6 @@ labels = ["default", "fast-tidy"]
97108
[commands.typos]
98109
type = "lint"
99110
include = "**/*"
100-
exclude = "**/*.tar.gz"
101111
cmd = "typos"
102112
invoke = "once"
103113
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(())

ubi/test-data/no-shared-root.tar.gz

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

ubi/test-data/project.gz

-5 Bytes
Binary file not shown.

ubi/test-data/project.pyz

19 Bytes
Binary file not shown.

ubi/test-data/project.tar

0 Bytes
Binary file not shown.

ubi/test-data/project.tar.bz

2 Bytes
Binary file not shown.

ubi/test-data/project.tar.bz2

2 Bytes
Binary file not shown.

ubi/test-data/project.tar.gz

15 Bytes
Binary file not shown.

ubi/test-data/project.tar.xz

4 Bytes
Binary file not shown.

ubi/test-data/project.xz

28 Bytes
Binary file not shown.

ubi/test-data/project.zip

3 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)