Expand description
§gravityfile-core
The data model shared by gravityfile, a disk usage analyzer and file explorer: the scanned tree, scan settings, size formatting, configuration paths and scan history.
This crate exists for the grav binary and its sibling crates. Its API
follows their needs and can change in any minor release.
FileTreeis a scanned directory: aFileNoderoot, the absoluteroot_path,TreeStatstotals and the warnings collected on the way.FileNodeis a file, directory or symlink. Directories hold their children sorted largest first and carry the size of their whole subtree.ScanConfigholds the scan settings: depth, hidden files, ignore patterns, symlinks, filesystem boundaries and hard-link counting.unitsformats and parses sizes and ages, with SI units by default.pathsfinds the configuration and data directories, honouringGRAVITYFILE_HOMEand the platform conventions.historyappends and reads the one-line scan summaries behindgrav history.
use gravityfile_core::units::{Units, format_size, parse_size};
use gravityfile_core::{FileNode, FileTree, ScanConfig, Timestamps, TreeStats};
use std::path::Path;
use std::time::{Duration, SystemTime};
let modified = Timestamps::with_modified(SystemTime::now());
let mut tree = FileTree::new(
FileNode::new_directory("project", modified),
"/project".into(),
ScanConfig::new("/project"),
TreeStats::new(),
Duration::ZERO,
Vec::new(),
);
let file = FileNode::new_file("data.bin", 3_000_000, 5_864, modified, false);
assert!(tree.insert(Path::new("/project"), file));
tree.recount();
assert_eq!(tree.total_files(), 1);
assert_eq!(tree.total_size(), 3_000_000);
assert_eq!(format_size(3_000_000, Units::Si), "3.00 MB");
assert_eq!(format_size(3_000_000, Units::Binary), "2.86 MiB");
assert_eq!(parse_size("1.5G").unwrap(), 1_500_000_000);Most code gets a FileTree from gravityfile-scan instead of building one.
§Licence
MIT or Apache-2.0, at your option.
Modules§
- history
- Scan history: one summary line per full scan, appended to
history.jsonlin the data directory, so a place’s growth can be followed over time. - path_
serde - JSON-compatible native paths. Unicode paths retain their legacy string shape.
- paths
- Where gravityfile keeps its own files.
- units
- Human-readable sizes and ages, and parsers for their command-line forms.
Structs§
- Content
Hash - BLAKE3 content hash for duplicate detection.
- File
Node - A single file or directory in the tree.
- File
Tree - Complete scanned file tree with metadata.
- Inode
Info - Inode information for hardlink detection.
- Scan
Config - Configuration for scanning operations.
- Scan
Config Builder - Builder for
ScanConfig. - Scan
Warning - Non-fatal warning encountered during scan.
- Timestamps
- Node timestamps retained in the tree. Access and creation times are not kept per node; read them from the filesystem when a single item needs them.
- Tree
Stats - Summary statistics for a scanned tree.
Enums§
- GitStatus
- Git status for a file or directory.
- Node
Kind - Type of file system node.
- Scan
Error - Errors that can occur during scanning.
- Warning
Kind - Kind of scan warning.
Functions§
- escape_
filename - Visible filename representation that distinguishes invalid encoded bytes from literal escape text. This is display text, not a portable path format.
- escape_
terminal_ text - Escape control characters and directional formatting without changing ordinary Unicode. This is a display representation, not a reversible path encoding.