Skip to content

Commit d124c60

Browse files
committed
[rust] Fix cache-path handling and other smell-fixes
1 parent dcca751 commit d124c60

File tree

11 files changed

+25
-31
lines changed

11 files changed

+25
-31
lines changed

rust/src/chrome.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl ChromeManager {
7373
driver_name,
7474
http_client: create_http_client(default_timeout, default_proxy)?,
7575
config,
76-
log: Logger::default(),
76+
log: Logger::new(),
7777
driver_url: None,
7878
browser_url: None,
7979
}))

rust/src/config.rs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -171,24 +171,19 @@ impl StringKey<'_> {
171171
let config = get_config().unwrap_or_default();
172172
let keys = self.0.to_owned();
173173
let default_value = self.1.to_owned();
174-
175174
let mut result;
176-
let mut first_key = "";
177175
for key in keys {
178-
if first_key.is_empty() {
179-
first_key = key;
180-
}
181176
if config.contains_key(key) {
182177
result = config[key].as_str().unwrap().to_string()
183178
} else {
184179
result = env::var(get_env_name(key)).unwrap_or_default()
185180
}
186-
if !result.is_empty() {
181+
if key.eq(CACHE_PATH_KEY) {
187182
// The configuration key for the cache path ("cache-path") is special because
188183
// the rest of the configuration values depend on this value (since the
189184
// configuration file is stored in the cache path). Therefore, this value needs
190185
// to be discovered in the first place and stored globally (on CACHE_PATH)
191-
return check_cache_path(key, result, default_value);
186+
return check_cache_path(result, default_value);
192187
}
193188
}
194189
default_value
@@ -246,19 +241,15 @@ fn concat(prefix: &str, suffix: &str) -> String {
246241
version_label
247242
}
248243

249-
fn check_cache_path(key: &str, value_in_config_or_env: String, default_value: String) -> String {
250-
let return_value = if key.eq(CACHE_PATH_KEY) {
251-
if default_value.is_empty() {
252-
value_in_config_or_env
253-
} else {
254-
default_value
255-
}
256-
} else {
244+
fn check_cache_path(value_in_config_or_env: String, default_value: String) -> String {
245+
let return_value = if !value_in_config_or_env.is_empty() {
257246
value_in_config_or_env
247+
} else if !default_value.is_empty() {
248+
default_value
249+
} else {
250+
read_cache_path()
258251
};
259-
if key.eq(CACHE_PATH_KEY) {
260-
write_cache_path(return_value.clone());
261-
}
252+
write_cache_path(return_value.clone());
262253
return_value
263254
}
264255

rust/src/edge.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl EdgeManager {
5959
driver_name,
6060
http_client: create_http_client(default_timeout, default_proxy)?,
6161
config,
62-
log: Logger::default(),
62+
log: Logger::new(),
6363
}))
6464
}
6565
}

rust/src/files.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ pub fn unzip(
154154
// are zipped with a parent folder, while others (e.g. chromedriver 114-)
155155
// are zipped without a parent folder
156156
Some(p) => {
157-
let iter = p.clone().iter();
157+
let iter = p.iter();
158158
if iter.to_owned().count() > 1 {
159159
iter.skip(1).collect()
160160
} else {

rust/src/firefox.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl FirefoxManager {
5858
driver_name,
5959
http_client: create_http_client(default_timeout, default_proxy)?,
6060
config,
61-
log: Logger::default(),
61+
log: Logger::new(),
6262
}))
6363
}
6464
}

rust/src/grid.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl GridManager {
6363
driver_name,
6464
http_client: create_http_client(default_timeout, default_proxy)?,
6565
config,
66-
log: Logger::default(),
66+
log: Logger::new(),
6767
driver_url: None,
6868
}))
6969
}

rust/src/iexplorer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl IExplorerManager {
6868
driver_name,
6969
http_client: create_http_client(default_timeout, default_proxy)?,
7070
config,
71-
log: Logger::default(),
71+
log: Logger::new(),
7272
driver_url: None,
7373
}))
7474
}

rust/src/lib.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ pub trait SeleniumManager {
315315
}
316316
None => {
317317
self.get_logger().debug(format!(
318-
"{} has not been discovered in the system",
318+
"{} not discovered in the system",
319319
self.get_browser_name()
320320
));
321321
download_browser = true;
@@ -611,10 +611,13 @@ pub trait SeleniumManager {
611611
}
612612

613613
let mut commands = Vec::new();
614+
614615
if WINDOWS.is(self.get_os()) {
615-
let wmic_command =
616-
Command::new_single(format_one_arg(WMIC_COMMAND, &escaped_browser_path));
617-
commands.push(wmic_command);
616+
if !escaped_browser_path.is_empty() {
617+
let wmic_command =
618+
Command::new_single(format_one_arg(WMIC_COMMAND, &escaped_browser_path));
619+
commands.push(wmic_command);
620+
}
618621
if !self.is_browser_version_unstable() {
619622
let reg_command =
620623
Command::new_multiple(vec!["REG", "QUERY", reg_key, "/v", reg_version_arg]);

rust/src/logger.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub struct JsonOutput {
7171
}
7272

7373
impl Logger {
74-
pub fn default() -> Self {
74+
pub fn new() -> Self {
7575
let debug = BooleanKey("debug", false).get_value();
7676
let trace = BooleanKey("trace", false).get_value();
7777
Logger::create("", debug, trace)

rust/src/safari.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl SafariManager {
5252
driver_name,
5353
http_client: create_http_client(default_timeout, default_proxy)?,
5454
config,
55-
log: Logger::default(),
55+
log: Logger::new(),
5656
}))
5757
}
5858
}

0 commit comments

Comments
 (0)