diff --git a/Cargo.lock b/Cargo.lock index ca8fe30..1701f28 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1463,6 +1463,39 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "test-case" +version = "3.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb2550dd13afcd286853192af8601920d959b14c401fcece38071d53bf0768a8" +dependencies = [ + "test-case-macros", +] + +[[package]] +name = "test-case-core" +version = "3.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adcb7fd841cd518e279be3d5a3eb0636409487998a4aff22f3de87b81e88384f" +dependencies = [ + "cfg-if", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "test-case-macros" +version = "3.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c89e72a01ed4c579669add59014b9a524d609c0c88c6a585ce37485879f6ffb" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "test-case-core", +] + [[package]] name = "thiserror" version = "1.0.61" @@ -1629,6 +1662,7 @@ dependencies = [ "serde", "strum", "tempfile", + "test-case", "thiserror", "tokio", "url", diff --git a/Cargo.toml b/Cargo.toml index 7eadd1a..cbaa73f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] } diff --git a/Changes.md b/Changes.md index f1af520..ff6d02d 100644 --- a/Changes.md +++ b/Changes.md @@ -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 diff --git a/src/extension.rs b/src/extension.rs index 5c7a829..ba15435 100644 --- a/src/extension.rs +++ b/src/extension.rs @@ -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, @@ -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", diff --git a/src/installer.rs b/src/installer.rs index 3486eb8..44912b1 100644 --- a/src/installer.rs +++ b/src/installer.rs @@ -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), @@ -170,7 +171,9 @@ fn tar_reader_for(downloaded_file: PathBuf) -> Result>> { 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!(