Skip to content

Commit

Permalink
Look for first matching file which is a _file_ in zip archive.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
fiadliel authored and autarch committed Jan 18, 2025
1 parent f38abbd commit e22f9e2
Show file tree
Hide file tree
Showing 19 changed files with 29 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## $NEXT

- Fixed a bug where `ubi` where zip files containing a directory that matched the expected
executable name caused `ubi` to extract the directory instead of the actual executable, resulting
in a 0-length file. Based on a PR #89 from @fiadliel (Gary Coady).
- Added a new `UbiBuilder::rename_exe_to` method, along with a `--rename-exe-to` CLI flag. When this
is set, the installed executable will use the name given here, instead of the name that it has in
the downloaded file. This is useful for projects that do releases where the executable name
Expand Down
14 changes: 12 additions & 2 deletions precious.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
exclude = ["target"]
exclude = [
"target",
"**/*.AppImage",
"**/*.bz",
"**/*.bz2",
"**/*.exe",
"**/*.gz",
"**/*.pyz",
"**/*.tar",
"**/*.tar.*",
"**/*.xz",
]

[commands.clippy]
type = "lint"
Expand Down Expand Up @@ -97,7 +108,6 @@ labels = ["default", "fast-tidy"]
[commands.typos]
type = "lint"
include = "**/*"
exclude = "**/*.tar.gz"
cmd = "typos"
invoke = "once"
ok-exit-codes = 0
Expand Down
14 changes: 11 additions & 3 deletions ubi/src/installer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl ExeInstaller {
for i in 0..zip.len() {
let mut zf = zip.by_index(i)?;
let path = PathBuf::from(zf.name());
if path.ends_with(&self.exe) {
if zf.is_file() && path.ends_with(&self.exe) {
let mut buffer: Vec<u8> = Vec::with_capacity(usize::try_from(zf.size())?);
zf.read_to_end(&mut buffer)?;
self.create_install_dir()?;
Expand Down Expand Up @@ -442,10 +442,18 @@ mod tests {
archive_path: PathBuf::from(archive_path),
})?;

assert!(install_path.exists());
assert!(install_path.is_file());
// Testing the installed file's length is a shortcut to make sure we install the file we
// expected to install.
let meta = install_path.metadata()?;
let expect_len = if install_path.extension().unwrap_or_default() == "pyz" {
fs::metadata(archive_path)?.len()
} else {
3
};
assert_eq!(meta.len(), expect_len);
#[cfg(target_family = "unix")]
assert!(install_path.metadata()?.permissions().mode() & 0o111 != 0);
assert!(meta.permissions().mode() & 0o111 != 0);
}

Ok(())
Expand Down
Binary file modified ubi/test-data/no-shared-root.tar.gz
Binary file not shown.
1 change: 1 addition & 0 deletions ubi/test-data/project
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exe
Binary file modified ubi/test-data/project-with-one-file.tar.gz
Binary file not shown.
1 change: 1 addition & 0 deletions ubi/test-data/project.AppImage
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exe
Binary file modified ubi/test-data/project.bz
Binary file not shown.
Binary file modified ubi/test-data/project.bz2
Binary file not shown.
1 change: 1 addition & 0 deletions ubi/test-data/project.exe
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exe
Binary file modified ubi/test-data/project.gz
Binary file not shown.
Binary file modified ubi/test-data/project.pyz
Binary file not shown.
Binary file modified ubi/test-data/project.tar
Binary file not shown.
Binary file modified ubi/test-data/project.tar.bz
Binary file not shown.
Binary file modified ubi/test-data/project.tar.bz2
Binary file not shown.
Binary file modified ubi/test-data/project.tar.gz
Binary file not shown.
Binary file modified ubi/test-data/project.tar.xz
Binary file not shown.
Binary file modified ubi/test-data/project.xz
Binary file not shown.
Binary file modified ubi/test-data/project.zip
Binary file not shown.

0 comments on commit e22f9e2

Please sign in to comment.