Skip to content

Commit bd6a71e

Browse files
committed
[rust] Improve logic for unzipping files and related tests
1 parent 16461e0 commit bd6a71e

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

rust/src/files.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,13 @@ pub fn unzip(
198198
}
199199

200200
remove_file(compressed_path)?;
201-
copy_folder_content(tmp_path, final_path, single_file)?;
201+
copy_folder_content(
202+
tmp_path,
203+
final_path,
204+
single_file,
205+
&compressed_path.to_path_buf(),
206+
&log,
207+
)?;
202208

203209
Ok(())
204210
}
@@ -207,12 +213,18 @@ pub fn copy_folder_content(
207213
source: impl AsRef<Path>,
208214
destination: impl AsRef<Path>,
209215
single_file: Option<String>,
216+
avoid_path: &PathBuf,
217+
log: &Logger,
210218
) -> io::Result<()> {
211219
fs::create_dir_all(&destination)?;
212220
for dir_entry in fs::read_dir(source)? {
213221
let entry = dir_entry?;
214222
let file_type = entry.file_type()?;
223+
let destination_path = destination.as_ref().join(entry.file_name());
215224
if file_type.is_file() {
225+
if entry.path().eq(avoid_path) {
226+
continue;
227+
}
216228
let target_file_name = entry
217229
.file_name()
218230
.to_os_string()
@@ -221,16 +233,22 @@ pub fn copy_folder_content(
221233
if single_file.is_none()
222234
|| (single_file.is_some() && single_file.clone().unwrap().eq(&target_file_name))
223235
{
224-
let destination_path = destination.as_ref().join(entry.file_name());
236+
log.trace(format!(
237+
"Copying {} to {}",
238+
entry.path().display(),
239+
destination_path.display()
240+
));
225241
if !destination_path.exists() {
226242
fs::copy(entry.path(), destination_path)?;
227243
}
228244
}
229245
} else if single_file.is_none() {
230246
copy_folder_content(
231247
entry.path(),
232-
destination.as_ref().join(entry.file_name()),
248+
destination_path,
233249
single_file.clone(),
250+
avoid_path,
251+
&log,
234252
)?;
235253
}
236254
}

rust/tests/browser_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn wrong_parameters_test(
6969
let mut cmd = Command::new(env!("CARGO_BIN_EXE_selenium-manager"));
7070
let assert_result = cmd
7171
.args([
72-
"--trace",
72+
"--debug",
7373
"--browser",
7474
&browser,
7575
"--browser-version",

rust/tests/chrome_download_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn chrome_latest_download_test() {
3131
"--force-browser-download",
3232
"--output",
3333
"json",
34-
"--trace",
34+
"--debug",
3535
])
3636
.assert()
3737
.success()
@@ -53,7 +53,7 @@ fn chrome_version_download_test(#[case] browser_version: String) {
5353
&browser_version,
5454
"--output",
5555
"json",
56-
"--trace",
56+
"--debug",
5757
])
5858
.assert()
5959
.success()

0 commit comments

Comments
 (0)