From cb80aaa6fb400c09f891ac4b2967cd28775e5d04 Mon Sep 17 00:00:00 2001 From: metaphorics <152830360+metaphorics@users.noreply.github.com> Date: Fri, 3 Jul 2026 05:20:37 +0900 Subject: [PATCH] refactor(pi-walker): behavior-preserving cleanup\n\nOp: compress --- crates/pi-walker/src/cache.rs | 5 +-- crates/pi-walker/src/lib.rs | 76 ++++++++++++++--------------------- 2 files changed, 31 insertions(+), 50 deletions(-) diff --git a/crates/pi-walker/src/cache.rs b/crates/pi-walker/src/cache.rs index c3bcd58a7..59cd0bf50 100644 --- a/crates/pi-walker/src/cache.rs +++ b/crates/pi-walker/src/cache.rs @@ -128,10 +128,7 @@ where E: Send, { if !should_parallelize(items.len()) { - for item in items { - operation(item)?; - } - return Ok(()); + return items.iter().try_for_each(operation); } with_walk_pool(|| items.par_iter().try_for_each(operation)) } diff --git a/crates/pi-walker/src/lib.rs b/crates/pi-walker/src/lib.rs index 430c0c16f..dbc827d61 100644 --- a/crates/pi-walker/src/lib.rs +++ b/crates/pi-walker/src/lib.rs @@ -314,10 +314,9 @@ impl WalkFilter { } fn accepts_path(&self, relative_path: &str) -> bool { - match &self.glob { - Some(glob) => glob.is_match(relative_path), - None => true, - } + self.glob + .as_ref() + .is_none_or(|glob| glob.is_match(relative_path)) } fn accepts_collected(&self, entry: &CollectedEntry) -> bool { @@ -362,12 +361,13 @@ impl WalkFilter { }) { return WalkDecision::Skip; } - match self.kind { - WalkFilterKind::All => {}, - WalkFilterKind::Files if meta.file_type == FileType::File => {}, - WalkFilterKind::Files => return WalkDecision::Skip, - WalkFilterKind::Dirs if meta.file_type == FileType::Dir => {}, - WalkFilterKind::Dirs => return WalkDecision::Skip, + let accepts_kind = match self.kind { + WalkFilterKind::All => true, + WalkFilterKind::Files => meta.file_type == FileType::File, + WalkFilterKind::Dirs => meta.file_type == FileType::Dir, + }; + if !accepts_kind { + return WalkDecision::Skip; } if self.accepts_path(meta.relative_path) { WalkDecision::Include @@ -2038,21 +2038,16 @@ impl WalkContext<'_, H> { V: EntryVisitor, H: FnMut() -> std::result::Result<(), V::Error>, { - let identity = if self.options.follow_links == FollowLinks::Always { - directory_identity(dir).ok() - } else { - None - }; - if let Some(id) = &identity { - self.symlink_ancestors.push(id.clone()); - } - - let result = self.walk_dir_inner(dir, relative_dir, depth, ignore_state, visitor); - - if identity.is_some() { + if self.options.follow_links == FollowLinks::Always + && let Ok(identity) = directory_identity(dir) + { + self.symlink_ancestors.push(identity); + let result = self.walk_dir_inner(dir, relative_dir, depth, ignore_state, visitor); self.symlink_ancestors.pop(); + return result; } - result + + self.walk_dir_inner(dir, relative_dir, depth, ignore_state, visitor) } fn walk_dir_inner( @@ -2068,26 +2063,15 @@ impl WalkContext<'_, H> { H: FnMut() -> std::result::Result<(), V::Error>, { let mut raw_entries = Vec::new(); - match self.options.order { - WalkOrder::Path => { - match platform::read_dir_entries(dir, self.options.detail, |entry| { - raw_entries.push(entry.into_owned()); - Ok(ReadDirControl::Continue) - }) { - Ok(_) => {}, - Err(err) => return handle_read_dir_error(dir, err, self.options, visitor), - } - raw_entries.sort_unstable_by(|a, b| a.name.cmp(&b.name)); - }, - WalkOrder::Unordered => { - match platform::read_dir_entries(dir, self.options.detail, |entry| { - raw_entries.push(entry.into_owned()); - Ok(ReadDirControl::Continue) - }) { - Ok(_) => {}, - Err(err) => return handle_read_dir_error(dir, err, self.options, visitor), - } - }, + match platform::read_dir_entries(dir, self.options.detail, |entry| { + raw_entries.push(entry.into_owned()); + Ok(ReadDirControl::Continue) + }) { + Ok(_) => {}, + Err(err) => return handle_read_dir_error(dir, err, self.options, visitor), + } + if self.options.order == WalkOrder::Path { + raw_entries.sort_unstable_by(|a, b| a.name.cmp(&b.name)); } for entry in raw_entries { @@ -2150,7 +2134,7 @@ impl WalkContext<'_, H> { } } return Err(WalkError::InvalidData { - path: absolute.clone(), + path: absolute, message: err.to_string(), }); }, @@ -2222,7 +2206,7 @@ impl WalkContext<'_, H> { continue; } return Err(WalkError::InvalidData { - path: absolute.clone(), + path: absolute, message: "filesystem loop detected".to_string(), }); } @@ -2245,7 +2229,7 @@ impl WalkContext<'_, H> { } } return Err(WalkError::InvalidData { - path: absolute.clone(), + path: absolute, message: err.to_string(), }); },