diff --git a/rust/src/files.rs b/rust/src/files.rs index 4061d2ab83c2c..13ff016647354 100644 --- a/rust/src/files.rs +++ b/rust/src/files.rs @@ -197,8 +197,16 @@ pub fn unzip( .into()); } + log.debug(format!("**** Deleting {}", compressed_path.display())); remove_file(compressed_path)?; - copy_folder_content(tmp_path, final_path, single_file)?; + log.debug(format!( + "**** Copying {} to {} (single file {:?})", + tmp_path.display(), + final_path.display(), + single_file + )); + copy_folder_content(tmp_path, final_path, single_file, compressed_file, &log)?; + log.debug("**** Done"); Ok(()) } @@ -207,6 +215,8 @@ pub fn copy_folder_content( source: impl AsRef, destination: impl AsRef, single_file: Option, + avoid_file: &str, + log: &Logger, ) -> io::Result<()> { fs::create_dir_all(&destination)?; for dir_entry in fs::read_dir(source)? { @@ -218,20 +228,36 @@ pub fn copy_folder_content( .to_os_string() .into_string() .unwrap_or_default(); - if single_file.is_none() - || (single_file.is_some() && single_file.clone().unwrap().eq(&target_file_name)) + if (single_file.is_none() + || (single_file.is_some() && single_file.clone().unwrap().eq(&target_file_name))) + && !target_file_name.eq(avoid_file) { let destination_path = destination.as_ref().join(entry.file_name()); + log.debug(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()), - single_file.clone(), - )?; + let destination_path = destination.as_ref().join(entry.file_name()); + log.debug(format!( + "----> Copying {} to {} (recursively)", + entry.path().display(), + destination_path.display() + )); + if !destination_path.exists() { + copy_folder_content( + entry.path(), + destination_path, + single_file.clone(), + avoid_file, + &log, + )?; + } } } Ok(()) diff --git a/rust/src/main.rs b/rust/src/main.rs index 45309fe0cb53d..d7e1893439fc1 100644 --- a/rust/src/main.rs +++ b/rust/src/main.rs @@ -15,6 +15,7 @@ // specific language governing permissions and limitations // under the License. +use std::error::Error; use std::process::exit; use clap::Parser; @@ -206,12 +207,26 @@ fn main() { log.warn(err.to_string()); flush_and_exit(OK, log); } else { - log.error(err.to_string()); + log_error(&log, err); flush_and_exit(DATAERR, log); } }); } +fn log_error(log: &Logger, err: Box) { + let error_message = err.to_string(); + let source = err.source(); + if source.is_some() { + log.error(format!( + "{}. Caused by: {}", + error_message, + source.unwrap().to_string() + )); + } else { + log.error(error_message); + } +} + fn flush_and_exit(code: i32, log: &Logger) -> ! { log.set_code(code); log.flush(); diff --git a/rust/tests/browser_tests.rs b/rust/tests/browser_tests.rs index 1d96737fb40c9..879274f4f770b 100644 --- a/rust/tests/browser_tests.rs +++ b/rust/tests/browser_tests.rs @@ -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", diff --git a/rust/tests/chrome_download_tests.rs b/rust/tests/chrome_download_tests.rs index 76926f4b42296..bc2983de61d3d 100644 --- a/rust/tests/chrome_download_tests.rs +++ b/rust/tests/chrome_download_tests.rs @@ -31,7 +31,7 @@ fn chrome_latest_download_test() { "--force-browser-download", "--output", "json", - "--trace", + "--debug", ]) .assert() .success() @@ -53,7 +53,7 @@ fn chrome_version_download_test(#[case] browser_version: String) { &browser_version, "--output", "json", - "--trace", + "--debug", ]) .assert() .success()