Skip to content

Commit

Permalink
find: New WalkEntry wrapper
Browse files Browse the repository at this point in the history
The new type wraps DirEntry when possible, but also lets us pass a valid
entry to matchers when walkdir returns a broken symlink error.  It also
implements a Metadata cache (part of uutils#430).
  • Loading branch information
tavianator committed Aug 12, 2024
1 parent e73334f commit 0551141
Show file tree
Hide file tree
Showing 27 changed files with 503 additions and 287 deletions.
5 changes: 2 additions & 3 deletions src/find/matchers/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
// https://opensource.org/licenses/MIT.

use faccess::PathExt;
use walkdir::DirEntry;

use super::{Matcher, MatcherIO};
use super::{Matcher, MatcherIO, WalkEntry};

/// Matcher for -{read,writ,execut}able.
pub enum AccessMatcher {
Expand All @@ -17,7 +16,7 @@ pub enum AccessMatcher {
}

impl Matcher for AccessMatcher {
fn matches(&self, file_info: &DirEntry, _: &mut MatcherIO) -> bool {
fn matches(&self, file_info: &WalkEntry, _: &mut MatcherIO) -> bool {
let path = file_info.path();

match self {
Expand Down
8 changes: 3 additions & 5 deletions src/find/matchers/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
* file that was distributed with this source code.
*/

use std::fs::{self, FileType};
use std::fs;
use std::io::{self, stderr, Write};
use std::path::Path;

use walkdir::DirEntry;

use super::{Matcher, MatcherIO};
use super::{FileType, Matcher, MatcherIO, WalkEntry};

pub struct DeleteMatcher;

Expand All @@ -32,7 +30,7 @@ impl DeleteMatcher {
}

impl Matcher for DeleteMatcher {
fn matches(&self, file_info: &DirEntry, _: &mut MatcherIO) -> bool {
fn matches(&self, file_info: &WalkEntry, _: &mut MatcherIO) -> bool {
let path = file_info.path();
let path_str = path.to_string_lossy();

Expand Down
4 changes: 2 additions & 2 deletions src/find/matchers/empty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{
io::{stderr, Write},
};

use super::Matcher;
use super::{Matcher, MatcherIO, WalkEntry};

pub struct EmptyMatcher;

Expand All @@ -20,7 +20,7 @@ impl EmptyMatcher {
}

impl Matcher for EmptyMatcher {
fn matches(&self, file_info: &walkdir::DirEntry, _: &mut super::MatcherIO) -> bool {
fn matches(&self, file_info: &WalkEntry, _: &mut MatcherIO) -> bool {
if file_info.file_type().is_file() {
match file_info.metadata() {
Ok(meta) => meta.len() == 0,
Expand Down
Loading

0 comments on commit 0551141

Please sign in to comment.