Skip to content

Commit

Permalink
Add support for the .bz2 and .tar.bz2 file extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
autarch committed May 26, 2024
1 parent c5240cc commit a981f64
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
34 changes: 34 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ result = "1.0.0"
serde = { version = "1.0.202", features = ["derive"] }
strum = { version = "0.26.2", features = ["derive"] }
tempfile = "3.10.1"
test-case = "3.3.1"
thiserror = "1.0.61"
tokio = { version = "1.37.0", default-features = false, features = ["macros", "rt"] }
url = { version = "2.5.0", features = ["serde"] }
Expand Down
2 changes: 2 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
- Added support for the `.bz2` and `.tar.bz2 file extensions.

## 0.0.30 - 2024-05-11

- When a project's releases contain a mix of file names with and without an architecture, `ubi` will
Expand Down
6 changes: 5 additions & 1 deletion src/extension.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use itertools::Itertools;
use strum::{EnumIter, IntoEnumIterator};

#[derive(Debug, EnumIter)]
#[derive(Debug, EnumIter, PartialEq, Eq)]
pub(crate) enum Extension {
Bz,
Bz2,
Exe,
Gz,
TarBz,
TarBz2,
TarGz,
TarXz,
Tbz,
Expand All @@ -20,9 +22,11 @@ impl Extension {
pub(crate) fn extension(&self) -> &'static str {
match self {
Extension::Bz => ".bz",
Extension::Bz2 => ".bz2",
Extension::Exe => ".exe",
Extension::Gz => ".gz",
Extension::TarBz => ".tar.bz",
Extension::TarBz2 => ".tar.bz2",
Extension::TarGz => ".tar.gz",
Extension::TarXz => ".tar.xz",
Extension::Tbz => ".tbz",
Expand Down
7 changes: 5 additions & 2 deletions src/installer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ impl Installer {
.to_string_lossy();
match Extension::from_path(filename) {
Some(Extension::TarBz)
| Some(Extension::TarBz2)
| Some(Extension::TarGz)
| Some(Extension::TarXz)
| Some(Extension::Tbz)
| Some(Extension::Tgz)
| Some(Extension::Txz) => self.extract_tarball(downloaded_file),
Some(Extension::Bz) => self.unbzip(downloaded_file),
Some(Extension::Bz) | Some(Extension::Bz2) => self.unbzip(downloaded_file),
Some(Extension::Gz) => self.ungzip(downloaded_file),
Some(Extension::Xz) => self.unxz(downloaded_file),
Some(Extension::Zip) => self.extract_zip(downloaded_file),
Expand Down Expand Up @@ -170,7 +171,9 @@ fn tar_reader_for(downloaded_file: PathBuf) -> Result<Archive<Box<dyn Read>>> {
let ext = downloaded_file.extension();
match ext {
Some(ext) => match ext.to_str() {
Some("bz") | Some("tbz") => Ok(Archive::new(Box::new(BzDecoder::new(file)))),
Some("bz") | Some("tbz") | Some("bz2") | Some("tbz2") => {
Ok(Archive::new(Box::new(BzDecoder::new(file))))
}
Some("gz") | Some("tgz") => Ok(Archive::new(Box::new(GzDecoder::new(file)))),
Some("xz") | Some("txz") => Ok(Archive::new(Box::new(XzDecoder::new(file)))),
Some(e) => Err(anyhow!(
Expand Down

0 comments on commit a981f64

Please sign in to comment.