Skip to content

Commit

Permalink
[rust] Fix cache-path handling and other smell-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bonigarcia committed Aug 14, 2023
1 parent dcca751 commit d124c60
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 31 deletions.
2 changes: 1 addition & 1 deletion rust/src/chrome.rs
Expand Up @@ -73,7 +73,7 @@ impl ChromeManager {
driver_name,
http_client: create_http_client(default_timeout, default_proxy)?,
config,
log: Logger::default(),
log: Logger::new(),
driver_url: None,
browser_url: None,
}))
Expand Down
27 changes: 9 additions & 18 deletions rust/src/config.rs
Expand Up @@ -171,24 +171,19 @@ impl StringKey<'_> {
let config = get_config().unwrap_or_default();
let keys = self.0.to_owned();
let default_value = self.1.to_owned();

let mut result;
let mut first_key = "";
for key in keys {
if first_key.is_empty() {
first_key = key;
}
if config.contains_key(key) {
result = config[key].as_str().unwrap().to_string()
} else {
result = env::var(get_env_name(key)).unwrap_or_default()
}
if !result.is_empty() {
if key.eq(CACHE_PATH_KEY) {
// The configuration key for the cache path ("cache-path") is special because
// the rest of the configuration values depend on this value (since the
// configuration file is stored in the cache path). Therefore, this value needs
// to be discovered in the first place and stored globally (on CACHE_PATH)
return check_cache_path(key, result, default_value);
return check_cache_path(result, default_value);
}
}
default_value
Expand Down Expand Up @@ -246,19 +241,15 @@ fn concat(prefix: &str, suffix: &str) -> String {
version_label
}

fn check_cache_path(key: &str, value_in_config_or_env: String, default_value: String) -> String {
let return_value = if key.eq(CACHE_PATH_KEY) {
if default_value.is_empty() {
value_in_config_or_env
} else {
default_value
}
} else {
fn check_cache_path(value_in_config_or_env: String, default_value: String) -> String {
let return_value = if !value_in_config_or_env.is_empty() {
value_in_config_or_env
} else if !default_value.is_empty() {
default_value
} else {
read_cache_path()
};
if key.eq(CACHE_PATH_KEY) {
write_cache_path(return_value.clone());
}
write_cache_path(return_value.clone());
return_value
}

Expand Down
2 changes: 1 addition & 1 deletion rust/src/edge.rs
Expand Up @@ -59,7 +59,7 @@ impl EdgeManager {
driver_name,
http_client: create_http_client(default_timeout, default_proxy)?,
config,
log: Logger::default(),
log: Logger::new(),
}))
}
}
Expand Down
2 changes: 1 addition & 1 deletion rust/src/files.rs
Expand Up @@ -154,7 +154,7 @@ pub fn unzip(
// are zipped with a parent folder, while others (e.g. chromedriver 114-)
// are zipped without a parent folder
Some(p) => {
let iter = p.clone().iter();
let iter = p.iter();
if iter.to_owned().count() > 1 {
iter.skip(1).collect()
} else {
Expand Down
2 changes: 1 addition & 1 deletion rust/src/firefox.rs
Expand Up @@ -58,7 +58,7 @@ impl FirefoxManager {
driver_name,
http_client: create_http_client(default_timeout, default_proxy)?,
config,
log: Logger::default(),
log: Logger::new(),
}))
}
}
Expand Down
2 changes: 1 addition & 1 deletion rust/src/grid.rs
Expand Up @@ -63,7 +63,7 @@ impl GridManager {
driver_name,
http_client: create_http_client(default_timeout, default_proxy)?,
config,
log: Logger::default(),
log: Logger::new(),
driver_url: None,
}))
}
Expand Down
2 changes: 1 addition & 1 deletion rust/src/iexplorer.rs
Expand Up @@ -68,7 +68,7 @@ impl IExplorerManager {
driver_name,
http_client: create_http_client(default_timeout, default_proxy)?,
config,
log: Logger::default(),
log: Logger::new(),
driver_url: None,
}))
}
Expand Down
11 changes: 7 additions & 4 deletions rust/src/lib.rs
Expand Up @@ -315,7 +315,7 @@ pub trait SeleniumManager {
}
None => {
self.get_logger().debug(format!(
"{} has not been discovered in the system",
"{} not discovered in the system",
self.get_browser_name()
));
download_browser = true;
Expand Down Expand Up @@ -611,10 +611,13 @@ pub trait SeleniumManager {
}

let mut commands = Vec::new();

if WINDOWS.is(self.get_os()) {
let wmic_command =
Command::new_single(format_one_arg(WMIC_COMMAND, &escaped_browser_path));
commands.push(wmic_command);
if !escaped_browser_path.is_empty() {
let wmic_command =
Command::new_single(format_one_arg(WMIC_COMMAND, &escaped_browser_path));
commands.push(wmic_command);
}
if !self.is_browser_version_unstable() {
let reg_command =
Command::new_multiple(vec!["REG", "QUERY", reg_key, "/v", reg_version_arg]);
Expand Down
2 changes: 1 addition & 1 deletion rust/src/logger.rs
Expand Up @@ -71,7 +71,7 @@ pub struct JsonOutput {
}

impl Logger {
pub fn default() -> Self {
pub fn new() -> Self {
let debug = BooleanKey("debug", false).get_value();
let trace = BooleanKey("trace", false).get_value();
Logger::create("", debug, trace)
Expand Down
2 changes: 1 addition & 1 deletion rust/src/safari.rs
Expand Up @@ -52,7 +52,7 @@ impl SafariManager {
driver_name,
http_client: create_http_client(default_timeout, default_proxy)?,
config,
log: Logger::default(),
log: Logger::new(),
}))
}
}
Expand Down
2 changes: 1 addition & 1 deletion rust/src/safaritp.rs
Expand Up @@ -58,7 +58,7 @@ impl SafariTPManager {
driver_name,
http_client: create_http_client(default_timeout, default_proxy)?,
config,
log: Logger::default(),
log: Logger::new(),
}))
}
}
Expand Down

0 comments on commit d124c60

Please sign in to comment.