Skip to content

Commit

Permalink
[rust] Automated Edge management (Linux) (#11681 and #11683)
Browse files Browse the repository at this point in the history
  • Loading branch information
bonigarcia committed Sep 30, 2023
1 parent 75178b5 commit d780301
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 11 deletions.
62 changes: 61 additions & 1 deletion 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 @@ -32,6 +32,7 @@ toml = "0.7.6"
bzip2 = "0.4.4"
sevenz-rust = "0.5.2"
walkdir = "2.4.0"
debpkg = "0.6.0"

[dev-dependencies]
assert_cmd = "2.0.12"
Expand Down
35 changes: 25 additions & 10 deletions rust/src/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ use crate::metadata::{
};
use crate::{
create_browser_metadata, create_http_client, download_to_tmp_folder, format_two_args,
get_browser_version_from_metadata, path_buf_to_string, uncompress, Logger, SeleniumManager,
BETA, CANARY, DASH_DASH_VERSION, DEV, NIGHTLY, OFFLINE_REQUEST_ERR_MSG,
ONLINE_DISCOVERY_ERROR_MESSAGE, REG_VERSION_ARG, STABLE,
get_binary_extension, get_browser_version_from_metadata, path_buf_to_string, uncompress,
Logger, SeleniumManager, BETA, CANARY, DASH_DASH_VERSION, DEV, NIGHTLY,
OFFLINE_REQUEST_ERR_MSG, ONLINE_DISCOVERY_ERROR_MESSAGE, REG_VERSION_ARG, STABLE,
};

pub const EDGE_NAMES: &[&str] = &["edge", "msedge", "microsoftedge"];
Expand All @@ -42,6 +42,7 @@ const DRIVER_URL: &str = "https://msedgedriver.azureedge.net/";
const LATEST_STABLE: &str = "LATEST_STABLE";
const LATEST_RELEASE: &str = "LATEST_RELEASE";
const BROWSER_URL: &str = "https://edgeupdates.microsoft.com/api/products";
const EDGE_WINDOWS_AND_LINUX_APP_NAME: &str = "msedge";
const EDGE_MACOS_APP_NAME: &str = "Microsoft Edge.app/Contents/MacOS/Microsoft Edge";
const EDGE_BETA_MACOS_APP_NAME: &str = "Microsoft Edge Beta.app/Contents/MacOS/Microsoft Edge Beta";
const EDGE_DEV_MACOS_APP_NAME: &str = "Microsoft Edge Dev.app/Contents/MacOS/Microsoft Edge Dev";
Expand Down Expand Up @@ -74,7 +75,6 @@ impl EdgeManager {
}))
}

// TODO check
fn get_browser_url(&mut self) -> Result<String, Box<dyn Error>> {
if self.browser_url.is_none() {
self.request_latest_browser_version_from_online()?;
Expand All @@ -101,7 +101,11 @@ impl EdgeManager {
};
Ok(browser_in_cache.join(macos_app_name))
} else {
Ok(browser_in_cache.join(self.get_browser_name_with_extension()))
Ok(browser_in_cache.join(format!(
"{}{}",
EDGE_WINDOWS_AND_LINUX_APP_NAME,
get_binary_extension(self.get_os())
)))
}
}
}
Expand Down Expand Up @@ -380,13 +384,26 @@ impl SeleniumManager for EdgeManager {
.get_major_browser_version()
.parse::<i32>()
.unwrap_or_default();

// TODO check
let extract_label = if original_browser_version.eq_ignore_ascii_case(BETA) {
Some("msedge-beta")
} else if original_browser_version.eq_ignore_ascii_case(DEV) {
Some("msedge-dev")
} else if original_browser_version.eq_ignore_ascii_case(NIGHTLY)
|| original_browser_version.eq_ignore_ascii_case(CANARY)
{
Some("msedge-canary")
} else {
Some("msedge")
};
uncompress(
&driver_zip_file,
&self.get_browser_path_in_cache()?,
self.get_logger(),
self.get_os(),
None,
None,
extract_label,
Some(major_browser_version_int),
)?;
}
Expand Down Expand Up @@ -442,16 +459,14 @@ impl SeleniumManager for EdgeManager {
edge_updates_url.clone(),
)?;

let edge_channel = if self.is_browser_version_empty() || self.is_browser_version_stable() {
"Stable"
} else if self.is_browser_version_beta() {
let edge_channel = if self.is_browser_version_beta() {
"Beta"
} else if self.is_browser_version_dev() {
"Dev"
} else if self.is_browser_version_nightly() {
"Canary"
} else {
return Err(format!("Incorrect {} version: {}", browser_name, browser_version).into());
"Stable"
};
let products: Vec<&EdgeProduct> = edge_products
.iter()
Expand Down
33 changes: 33 additions & 0 deletions rust/src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const BZ2: &str = "bz2";
const PKG: &str = "pkg";
const DMG: &str = "dmg";
const EXE: &str = "exe";
const DEB: &str = "deb";
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 @@ -136,6 +137,8 @@ pub fn uncompress(
uncompress_dmg(compressed_file, target, log, os, volume.unwrap_or_default())?
} else if extension.eq_ignore_ascii_case(EXE) {
uncompress_sfx(compressed_file, target, log)?
} else if extension.eq_ignore_ascii_case(DEB) {
uncompress_deb(compressed_file, target, log, volume.unwrap_or_default())?
} else if extension.eq_ignore_ascii_case(XML) || extension.eq_ignore_ascii_case(HTML) {
log.debug(format!(
"Wrong downloaded driver: {}",
Expand Down Expand Up @@ -263,6 +266,36 @@ pub fn uncompress_dmg(
Ok(())
}

pub fn uncompress_deb(
compressed_file: &str,
target: &Path,
log: &Logger,
label: &str,
) -> Result<(), Box<dyn Error>> {
let zip_parent = Path::new(compressed_file).parent().unwrap();
log.trace(format!(
"Extracting from {} to {}",
compressed_file,
zip_parent.display()
));

let deb_file = File::open(compressed_file)?;
let mut deb_pkg = debpkg::DebPkg::parse(deb_file)?;
deb_pkg.data()?.unpack(zip_parent)?;

let zip_parent_str = path_buf_to_string(zip_parent.to_path_buf());
let target_str = path_buf_to_string(target.to_path_buf());
let opt_edge_str = format!(r#"{}\opt\microsoft\{}"#, zip_parent_str, label);
log.trace(format!(
"Moving extracted files and folders from {} to {}",
opt_edge_str, target_str
));
create_parent_path_if_not_exists(target)?;
fs::rename(&opt_edge_str, &target_str)?;

Ok(())
}

pub fn untargz(compressed_file: &str, target: &Path, log: &Logger) -> Result<(), Box<dyn Error>> {
log.trace(format!(
"Untargz {} to {}",
Expand Down

0 comments on commit d780301

Please sign in to comment.