Fix the search for method
This commit is contained in:
parent
391ca67890
commit
9b629fc238
1 changed files with 11 additions and 1 deletions
12
src/lib.rs
12
src/lib.rs
|
@ -71,13 +71,23 @@ pub fn search_for(
|
|||
max_depth: u8,
|
||||
regx: ®ex::Regex,
|
||||
) -> std::io::Result<Option<String>> {
|
||||
let mut search_directory = if Path::new(search_directory).is_file() {
|
||||
#[cfg(feature = "debug")]
|
||||
{
|
||||
info!("The provided search directory is a file, searching in the parent directory.");
|
||||
}
|
||||
let Some(parent) = Path::new(search_directory).parent() else { return Ok(None); };
|
||||
let Some(parent) = parent.to_str() else { return Ok(None); };
|
||||
parent
|
||||
} else {
|
||||
search_directory
|
||||
};
|
||||
#[cfg(feature = "debug")]
|
||||
{
|
||||
info!("Searching for a file that matches the regular {regx:?} expression in \"{search_directory}\" and its subdirectories.");
|
||||
info!("Max depth: {max_depth}");
|
||||
}
|
||||
let mut max_depth = max_depth;
|
||||
let mut search_directory = search_directory;
|
||||
|
||||
loop {
|
||||
if let Some(path) = search(search_directory, regx)? {
|
||||
|
|
Loading…
Reference in a new issue