Skip to content

Commit 966bed6

Browse files
authored
[rust] xz uncompressor for Firefox Linux nightlies (#14832)
* [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.
1 parent ce7448b commit 966bed6

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

rust/Cargo.Bazel.lock

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"checksum": "94895b25f9b1d0a76ec78d588887353422bc623faf9ef986467b199d2a966765",
2+
"checksum": "0e8299f5a76cfec7030579fd20069b2debeacc1752e14c4a3b169492b2f18ed4",
33
"crates": {
44
"addr2line 0.21.0": {
55
"name": "addr2line",
@@ -14223,6 +14223,10 @@
1422314223
"id": "which 6.0.3",
1422414224
"target": "which"
1422514225
},
14226+
{
14227+
"id": "xz2 0.1.7",
14228+
"target": "xz2"
14229+
},
1422614230
{
1422714231
"id": "zip 2.2.0",
1422814232
"target": "zip"
@@ -22758,6 +22762,7 @@
2275822762
"toml 0.8.19",
2275922763
"walkdir 2.5.0",
2276022764
"which 6.0.3",
22765+
"xz2 0.1.7",
2276122766
"zip 2.2.0"
2276222767
],
2276322768
"direct_dev_deps": [

rust/Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ exitcode = "1.1.2"
3030
toml = "0.8.19"
3131
bzip2 = "0.4.4"
3232
sevenz-rust = "0.6.1"
33+
xz2 = "0.1.7"
3334
walkdir = "2.5.0"
3435
debpkg = "0.6.0"
3536
anyhow = { version = "1.0.89", default-features = false, features = ["backtrace", "std"] }

rust/src/files.rs

+16-6
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use std::io::{BufReader, Cursor, Read};
3535
use std::path::{Path, PathBuf};
3636
use tar::Archive;
3737
use walkdir::{DirEntry, WalkDir};
38+
use xz2::read::XzDecoder;
3839
use zip::ZipArchive;
3940

4041
pub const PARSE_ERROR: &str = "Wrong browser/driver version";
@@ -49,6 +50,7 @@ const DMG: &str = "dmg";
4950
const EXE: &str = "exe";
5051
const DEB: &str = "deb";
5152
const MSI: &str = "msi";
53+
const XZ: &str = "xz";
5254
const SEVEN_ZIP_HEADER: &[u8; 6] = b"7z\xBC\xAF\x27\x1C";
5355
const UNCOMPRESS_MACOS_ERR_MSG: &str = "{} files are only supported in macOS";
5456

@@ -123,7 +125,17 @@ pub fn uncompress(
123125
} else if extension.eq_ignore_ascii_case(GZ) {
124126
untargz(compressed_file, target, log)?
125127
} else if extension.eq_ignore_ascii_case(BZ2) {
126-
uncompress_bz2(compressed_file, target, log)?
128+
uncompress_tar(
129+
&mut BzDecoder::new(File::open(compressed_file)?),
130+
target,
131+
log,
132+
)?
133+
} else if extension.eq_ignore_ascii_case(XZ) {
134+
uncompress_tar(
135+
&mut XzDecoder::new(File::open(compressed_file)?),
136+
target,
137+
log,
138+
)?
127139
} else if extension.eq_ignore_ascii_case(PKG) {
128140
uncompress_pkg(compressed_file, target, log)?
129141
} else if extension.eq_ignore_ascii_case(DMG) {
@@ -317,15 +329,13 @@ pub fn untargz(compressed_file: &str, target: &Path, log: &Logger) -> Result<(),
317329
Ok(())
318330
}
319331

320-
pub fn uncompress_bz2(compressed_file: &str, target: &Path, log: &Logger) -> Result<(), Error> {
332+
pub fn uncompress_tar(decoder: &mut dyn Read, target: &Path, log: &Logger) -> Result<(), Error> {
321333
log.trace(format!(
322-
"Uncompress {} to {}",
323-
compressed_file,
334+
"Uncompress compressed tarball to {}",
324335
target.display()
325336
));
326-
let mut bz_decoder = BzDecoder::new(File::open(compressed_file)?);
327337
let mut buffer: Vec<u8> = Vec::new();
328-
bz_decoder.read_to_end(&mut buffer)?;
338+
decoder.read_to_end(&mut buffer)?;
329339
let mut archive = Archive::new(Cursor::new(buffer));
330340
if !target.exists() {
331341
for entry in archive.entries()? {

0 commit comments

Comments
 (0)