@@ -2,6 +2,7 @@ use std::path::{Path, PathBuf};
22use tokio:: fs;
33
44use super :: detect:: PackageManager ;
5+ use crate :: utils:: fs:: { entry_file_type, is_dir, list_dir_entries} ;
56
67/// Detect the package manager based on lockfiles in the project root.
78/// Checks for pnpm-lock.yaml, pnpm-lock.yml, and pnpm-workspace.yaml.
@@ -346,12 +347,7 @@ fn is_ignored_dir(name: &str) -> bool {
346347
347348/// Search one level deep for package.json files.
348349async fn search_one_level ( dir : & Path , results : & mut Vec < PathBuf > ) {
349- let mut entries = match fs:: read_dir ( dir) . await {
350- Ok ( e) => e,
351- Err ( _) => return ,
352- } ;
353-
354- while let Ok ( Some ( entry) ) = entries. next_entry ( ) . await {
350+ for entry in list_dir_entries ( dir) . await {
355351 let path = entry. path ( ) ;
356352 // A single-level `dir/*` glob follows a symlinked direct member, the
357353 // way npm/pnpm (and our cargo `glob_dir`) resolve a workspace member
@@ -361,11 +357,7 @@ async fn search_one_level(dir: &Path, results: &mut Vec<PathBuf>) {
361357 // recursive searcher below deliberately does NOT follow symlinks,
362358 // to avoid loops/escapes — there a symlink's `is_dir() == false` is the
363359 // desired skip.)
364- if !fs:: metadata ( & path)
365- . await
366- . map ( |m| m. is_dir ( ) )
367- . unwrap_or ( false )
368- {
360+ if !is_dir ( & path) . await {
369361 continue ;
370362 }
371363 // A `dir/*` pattern must not pick up node_modules/hidden/output dirs as
@@ -388,15 +380,9 @@ async fn search_recursive(dir: &Path, depth: usize, max_depth: usize, results: &
388380 return ;
389381 }
390382
391- let mut entries = match fs:: read_dir ( dir) . await {
392- Ok ( e) => e,
393- Err ( _) => return ,
394- } ;
395-
396- while let Ok ( Some ( entry) ) = entries. next_entry ( ) . await {
397- let ft = match entry. file_type ( ) . await {
398- Ok ( ft) => ft,
399- Err ( _) => continue ,
383+ for entry in list_dir_entries ( dir) . await {
384+ let Some ( ft) = entry_file_type ( & entry) . await else {
385+ continue ;
400386 } ;
401387 if !ft. is_dir ( ) {
402388 continue ;
0 commit comments