diff --git a/rust/Cargo.Bazel.lock b/rust/Cargo.Bazel.lock index aa489691c16ae..202d60533b672 100644 --- a/rust/Cargo.Bazel.lock +++ b/rust/Cargo.Bazel.lock @@ -1,5 +1,5 @@ { - "checksum": "94895b25f9b1d0a76ec78d588887353422bc623faf9ef986467b199d2a966765", + "checksum": "0e8299f5a76cfec7030579fd20069b2debeacc1752e14c4a3b169492b2f18ed4", "crates": { "addr2line 0.21.0": { "name": "addr2line", @@ -14223,6 +14223,10 @@ "id": "which 6.0.3", "target": "which" }, + { + "id": "xz2 0.1.7", + "target": "xz2" + }, { "id": "zip 2.2.0", "target": "zip" @@ -22758,6 +22762,7 @@ "toml 0.8.19", "walkdir 2.5.0", "which 6.0.3", + "xz2 0.1.7", "zip 2.2.0" ], "direct_dev_deps": [ diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 2696beb8223eb..2d38bee267a87 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -1907,6 +1907,7 @@ dependencies = [ "toml", "walkdir", "which", + "xz2", "zip", ] diff --git a/rust/Cargo.toml b/rust/Cargo.toml index f5854e15f80ff..3106d43a81498 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -30,6 +30,7 @@ exitcode = "1.1.2" toml = "0.8.19" bzip2 = "0.4.4" sevenz-rust = "0.6.1" +xz2 = "0.1.7" walkdir = "2.5.0" debpkg = "0.6.0" anyhow = { version = "1.0.89", default-features = false, features = ["backtrace", "std"] } diff --git a/rust/src/files.rs b/rust/src/files.rs index a753f8456b358..bbbf1682d7b0f 100644 --- a/rust/src/files.rs +++ b/rust/src/files.rs @@ -35,6 +35,7 @@ use std::io::{BufReader, Cursor, Read}; use std::path::{Path, PathBuf}; use tar::Archive; use walkdir::{DirEntry, WalkDir}; +use xz2::read::XzDecoder; use zip::ZipArchive; pub const PARSE_ERROR: &str = "Wrong browser/driver version"; @@ -49,6 +50,7 @@ const DMG: &str = "dmg"; const EXE: &str = "exe"; const DEB: &str = "deb"; const MSI: &str = "msi"; +const XZ: &str = "xz"; const SEVEN_ZIP_HEADER: &[u8; 6] = b"7z\xBC\xAF\x27\x1C"; const UNCOMPRESS_MACOS_ERR_MSG: &str = "{} files are only supported in macOS"; @@ -123,7 +125,17 @@ pub fn uncompress( } else if extension.eq_ignore_ascii_case(GZ) { untargz(compressed_file, target, log)? } else if extension.eq_ignore_ascii_case(BZ2) { - uncompress_bz2(compressed_file, target, log)? + uncompress_tar( + &mut BzDecoder::new(File::open(compressed_file)?), + target, + log, + )? + } else if extension.eq_ignore_ascii_case(XZ) { + uncompress_tar( + &mut XzDecoder::new(File::open(compressed_file)?), + target, + log, + )? } else if extension.eq_ignore_ascii_case(PKG) { uncompress_pkg(compressed_file, target, log)? } else if extension.eq_ignore_ascii_case(DMG) { @@ -317,15 +329,13 @@ pub fn untargz(compressed_file: &str, target: &Path, log: &Logger) -> Result<(), Ok(()) } -pub fn uncompress_bz2(compressed_file: &str, target: &Path, log: &Logger) -> Result<(), Error> { +pub fn uncompress_tar(decoder: &mut dyn Read, target: &Path, log: &Logger) -> Result<(), Error> { log.trace(format!( - "Uncompress {} to {}", - compressed_file, + "Uncompress compressed tarball to {}", target.display() )); - let mut bz_decoder = BzDecoder::new(File::open(compressed_file)?); let mut buffer: Vec = Vec::new(); - bz_decoder.read_to_end(&mut buffer)?; + decoder.read_to_end(&mut buffer)?; let mut archive = Archive::new(Cursor::new(buffer)); if !target.exists() { for entry in archive.entries()? {