gravityfile-scan
High-performance parallel file system scanner for gravityfile.
This crate provides the scanning engine that traverses directories and builds the file tree structure used by other gravityfile components.
Features
- Parallel Traversal - Uses jwalk for multi-threaded directory scanning
- Progress Updates - Subscribe to real-time scan progress via broadcast channels
- Hardlink Detection - Tracks inodes to avoid double-counting hardlinked files
- Cross-Filesystem Support - Optionally traverse mount points
- Ignore Patterns - Skip directories matching configured patterns
- Size Aggregation - Automatically calculates directory sizes from contents
Usage
Basic Scan
use ;
let config = new;
let scanner = new;
let tree = scanner.scan?;
println!;
println!;
println!;
With Progress Updates
use ;
let scanner = new;
let mut progress_rx = scanner.subscribe;
// Spawn task to handle progress
spawn;
let config = new;
let tree = scanner.scan?;
Custom Configuration
use ;
let config = builder
.root
.max_depth // Limit depth
.include_hidden // Skip hidden files
.follow_symlinks // Don't follow symlinks
.cross_filesystems // Stay on same filesystem
.ignore_patterns
.threads // 0 = auto-detect CPU count
.apparent_size // Use disk usage, not apparent size
.build?;
let scanner = new;
let tree = scanner.scan?;
Output Structure
The scanner produces a FileTree containing:
- root - Root
FileNodewith nested children - root_path - Canonical path that was scanned
- stats - Summary statistics (total size, file count, etc.)
- warnings - Non-fatal issues encountered during scan
- scan_duration - How long the scan took
- config - Configuration used for the scan
Children are automatically sorted by size (largest first) for efficient display.
Performance
- Uses rayon thread pool via jwalk for parallel directory traversal
- Hardlink tracking uses DashMap for lock-free concurrent access
- Progress updates are batched (every 1000 files) to reduce overhead
- Memory-efficient: only stores aggregated tree, not individual paths
Re-exports
This crate re-exports common types from gravityfile-core for convenience:
use ;
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.