Skip to content

Commit f9aa206

Browse files
committed
[rust] Improve logic for checking files that already exists while unzipping
1 parent 712904c commit f9aa206

File tree

6 files changed

+16
-23
lines changed

6 files changed

+16
-23
lines changed

rust/src/files.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ pub fn unzip(
136136
if single_file.is_none() {
137137
create_path_if_not_exists(target)?;
138138
out_path = target.join(path);
139+
} else if out_path.exists() {
140+
unzipped_files = 1;
141+
break;
139142
}
140143

141144
if single_file.is_none() && file.name().ends_with('/') {
@@ -151,11 +154,11 @@ pub fn unzip(
151154
file.size()
152155
));
153156
create_parent_path_if_not_exists(out_path.as_path())?;
157+
unzipped_files += 1;
154158

155159
if !out_path.exists() {
156160
let mut outfile = File::create(&out_path)?;
157161
io::copy(&mut file, &mut outfile)?;
158-
unzipped_files += 1;
159162

160163
// Set permissions in Unix-like systems
161164
#[cfg(unix)]

rust/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,8 @@ pub trait SeleniumManager {
840840

841841
fn set_offline(&mut self, offline: bool) {
842842
if offline {
843-
self.get_logger().debug("Using Selenium Manager in offline mode");
843+
self.get_logger()
844+
.debug("Using Selenium Manager in offline mode");
844845
self.get_config_mut().offline = true;
845846
}
846847
}

rust/tests/cache_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ fn cache_path_test() {
4343
assert!(!driver_path.contains(r#"cache\selenium"#));
4444

4545
let tmp_cache_path = Path::new(tmp_cache_folder_name);
46-
fs::remove_dir_all(&tmp_cache_path).unwrap();
46+
fs::remove_dir_all(tmp_cache_path).unwrap();
4747
assert!(!tmp_cache_path.exists());
4848
}

rust/tests/common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ pub fn get_driver_path(cmd: &mut Command) -> String {
5858

5959
#[allow(dead_code)]
6060
pub fn exec_driver(cmd: &mut Command) -> String {
61-
let mut cmd_mut = cmd.borrow_mut();
62-
let driver_path = get_driver_path(&mut cmd_mut);
61+
let cmd_mut = cmd.borrow_mut();
62+
let driver_path = get_driver_path(cmd_mut);
6363
let driver_version_command = shell::Command::new_single(format!("{} --version", &driver_path));
6464
let output = run_shell_command_by_os(OS, driver_version_command).unwrap();
6565
println!("**** EXEC DRIVER: {}", output);

rust/tests/offline_tests.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,10 @@ use std::str;
2121
#[test]
2222
fn offline_test() {
2323
let mut cmd = Command::new(env!("CARGO_BIN_EXE_selenium-manager"));
24-
cmd.args([
25-
"--debug",
26-
"--browser",
27-
"chrome",
28-
"--offline",
29-
])
30-
.assert()
31-
.success()
32-
.code(0);
24+
cmd.args(["--debug", "--browser", "chrome", "--offline"])
25+
.assert()
26+
.success()
27+
.code(0);
3328

3429
let stdout = &cmd.unwrap().stdout;
3530
let output = str::from_utf8(stdout).unwrap();

rust/tests/timeout_tests.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,7 @@ use assert_cmd::Command;
2020
#[test]
2121
fn timeout_error_test() {
2222
let mut cmd = Command::new(env!("CARGO_BIN_EXE_selenium-manager"));
23-
cmd.args([
24-
"--debug",
25-
"--browser",
26-
"edge",
27-
"--timeout",
28-
"-1",
29-
])
30-
.assert()
31-
.failure();
23+
cmd.args(["--debug", "--browser", "edge", "--timeout", "-1"])
24+
.assert()
25+
.failure();
3226
}

0 commit comments

Comments
 (0)