Skip to content

Commit

Permalink
[rust] Improve logic for unzipping files and related tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bonigarcia committed Aug 9, 2023
1 parent 16461e0 commit bd6a71e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
24 changes: 21 additions & 3 deletions rust/src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,13 @@ pub fn unzip(
}

remove_file(compressed_path)?;
copy_folder_content(tmp_path, final_path, single_file)?;
copy_folder_content(
tmp_path,
final_path,
single_file,
&compressed_path.to_path_buf(),
&log,
)?;

Ok(())
}
Expand All @@ -207,12 +213,18 @@ pub fn copy_folder_content(
source: impl AsRef<Path>,
destination: impl AsRef<Path>,
single_file: Option<String>,
avoid_path: &PathBuf,
log: &Logger,
) -> io::Result<()> {
fs::create_dir_all(&destination)?;
for dir_entry in fs::read_dir(source)? {
let entry = dir_entry?;
let file_type = entry.file_type()?;
let destination_path = destination.as_ref().join(entry.file_name());
if file_type.is_file() {
if entry.path().eq(avoid_path) {
continue;
}
let target_file_name = entry
.file_name()
.to_os_string()
Expand All @@ -221,16 +233,22 @@ pub fn copy_folder_content(
if single_file.is_none()
|| (single_file.is_some() && single_file.clone().unwrap().eq(&target_file_name))
{
let destination_path = destination.as_ref().join(entry.file_name());
log.trace(format!(
"Copying {} to {}",
entry.path().display(),
destination_path.display()
));
if !destination_path.exists() {
fs::copy(entry.path(), destination_path)?;
}
}
} else if single_file.is_none() {
copy_folder_content(
entry.path(),
destination.as_ref().join(entry.file_name()),
destination_path,
single_file.clone(),
avoid_path,
&log,
)?;
}
}
Expand Down
2 changes: 1 addition & 1 deletion rust/tests/browser_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn wrong_parameters_test(
let mut cmd = Command::new(env!("CARGO_BIN_EXE_selenium-manager"));
let assert_result = cmd
.args([
"--trace",
"--debug",
"--browser",
&browser,
"--browser-version",
Expand Down
4 changes: 2 additions & 2 deletions rust/tests/chrome_download_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn chrome_latest_download_test() {
"--force-browser-download",
"--output",
"json",
"--trace",
"--debug",
])
.assert()
.success()
Expand All @@ -53,7 +53,7 @@ fn chrome_version_download_test(#[case] browser_version: String) {
&browser_version,
"--output",
"json",
"--trace",
"--debug",
])
.assert()
.success()
Expand Down

0 comments on commit bd6a71e

Please sign in to comment.