Skip to content

Commit

Permalink
[rust] xz uncompressor for Firefox Linux nightlies (#14832)
Browse files Browse the repository at this point in the history
* [rust] Add xz2 dependency

The xz2 crate is already in the dependency tree,
so use it for implementing a xz uncompressor.

* [rust] Add XZ uncompressor

Refactor the BZ uncompressor to be a generic tar uncompressor.
Implement a new XZ uncompressor based on it so selenium-manager
can deal with the new Firefox nightly builds for Linux.
  • Loading branch information
bgermann authored Dec 3, 2024
1 parent ce7448b commit 966bed6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
7 changes: 6 additions & 1 deletion rust/Cargo.Bazel.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"checksum": "94895b25f9b1d0a76ec78d588887353422bc623faf9ef986467b199d2a966765",
"checksum": "0e8299f5a76cfec7030579fd20069b2debeacc1752e14c4a3b169492b2f18ed4",
"crates": {
"addr2line 0.21.0": {
"name": "addr2line",
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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": [
Expand Down
1 change: 1 addition & 0 deletions rust/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 rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
22 changes: 16 additions & 6 deletions rust/src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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<u8> = 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()? {
Expand Down

0 comments on commit 966bed6

Please sign in to comment.