Expand description
§fdf - A High-Performance Parallel File System Traversal Library
fdf is a Rust library designed for efficient, parallel directory traversal
with extensive filtering capabilities. It leverages Rayon for parallel processing
and uses platform-specific optimisations for maximum performance.
This will be renamed before a 1.0!
§Features
- Parallel Processing: Utilises Rayon’s work-stealing scheduler for concurrent directory traversal
- Platform Optimisations: Linux/Android specific
getdentssystem calls for optimal performance, with fallbacks for other platforms - Flexible Filtering: Support for multiple filtering criteria:
- File name patterns (regex,glob)
- File size ranges
- File types (regular, directory, symlink, etc.)
- File extensions
- Hidden file handling
- Custom filter functions
- Cycle Detection: Automatic symlink cycle prevention using inode caching
- Depth Control: Configurable maximum search depth
- Path Canonicalisation: Optional path resolution to absolute paths
- Error Handling: Configurable error reporting with detailed diagnostics
§Performance Characteristics
- Uses mimalloc as global allocator on supported platforms for improved memory allocation performance
- Batched result delivery to minimise channel contention
- Zero-copy path handling where possible
- Avoids unnecessary
statcalls through careful API design - Makes up to 50% less
getdentssyscalls on linux/android, check the source code)
§Platform Support
- Linux/Android: Optimised with direct
getdentssystem calls - BSD’s/macOS: Standard
readdirwith potential for future changes likefts_open(unlikely probably) - Other Unix-like: Fallback to standard library functions
- Windows: Not currently supported (PRs welcome!)
§Quick Start
use fdf::{walk::Finder, fs::DirEntry, SearchConfigError};
use std::sync::mpsc::Receiver;
fn find_files() -> Result<impl Iterator<Item = DirEntry>, SearchConfigError> {
let finder = Finder::init("/path/to/search")
.pattern("*.rs")
.keep_hidden(false)
.max_depth(Some(3))
.follow_symlinks(true)
.canonicalise_root(true) // Resolve the root to a full path
.build()?;
finder.traverse()
}Setting custom filters example
use fdf::{walk::Finder, filters::FileTypeFilter};
use std::error::Error;
fn main() -> Result<(), Box<dyn Error>> {
let finder = Finder::init("/var/log")
.pattern("*.log")
.keep_hidden(false)
.type_filter(Some(FileTypeFilter::File))
//set the custom filter
.filter(Some(|entry| {
entry.extension().is_some_and( |ext| ext.eq_ignore_ascii_case(b"log"))
}))
.build()?;
let entries = finder.traverse()?;
let mut count = 0;
for entry in entries {
count += 1;
println!("Matched: {}", entry.as_path().display());
}
println!("Found {} log files", count);
Ok(())
}Re-exports§
Modules§
Macros§
- access_
dirent - A helper macro to safely access dirent(64 on linux)’s
fields of a
libc::dirent/libc::dirent64aka ‘dirent-type’ struct by offset. - const_
assert - A compile time assert, mirroring
static_assertfrom C++ - const_
from_ env - Macro to create a const from an env var with compile-time parsing,
Structs§
- Search
Config - This struct holds the configuration for searching a File system via traversal
- Traversal
Error - Represents a traversal error encountered during directory processing
Enums§
- DirEntry
Error - Errors that can occur when reading or processing directory entries
- FilesystemIO
Error - This enum encapsulates all possible I/O errors that can occur during filesystem operations,
- Search
Config Error - Error type for search configuration and pattern compilation failures.