Skip to content

Commit

Permalink
ref(fs): improve code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
NTBBloodbath committed Jun 13, 2024
1 parent 6c19c76 commit c170f3f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ pub async fn find_file_in_previous_dirs(filename: &str) -> Result<Option<PathBuf
loop {
// Check if the file exists in the current directory first
let path = current_dir.join(filename);
if metadata(&path).await.is_ok() && metadata(&path).await?.is_file() {
return Ok(Some(path));
if let Ok(metadata) = metadata(&path).await {
if metadata.is_file() {
return Ok(Some(path));
}
}

// Move to the parent directory if the file was not found
Expand All @@ -24,7 +26,7 @@ pub async fn find_file_in_previous_dirs(filename: &str) -> Result<Option<PathBuf
}

let mut entries = read_dir(&current_dir).await?;
if entries.next_entry().await.is_err() {
if entries.next_entry().await?.is_none() {
break;
}
}
Expand Down

0 comments on commit c170f3f

Please sign in to comment.