mirror of
https://github.com/bootandy/dust.git
synced 2026-06-08 11:29:05 +03:00
c5830c5d00
target_family unix covers linux and mac and wraps up the call for inodes in a common interface.
32 lines
962 B
Rust
32 lines
962 B
Rust
use walkdir::DirEntry;
|
|
|
|
fn get_block_size() -> u64 {
|
|
// All os specific implementations of MetatdataExt seem to define a block as 512 bytes
|
|
// https://doc.rust-lang.org/std/os/linux/fs/trait.MetadataExt.html#tymethod.st_blocks
|
|
512
|
|
}
|
|
|
|
#[cfg(target_family = "unix")]
|
|
pub fn get_metadata(d: &DirEntry, use_apparent_size: bool) -> Option<(u64, Option<(u64, u64)>)> {
|
|
use std::os::unix::fs::MetadataExt;
|
|
match d.metadata().ok() {
|
|
Some(md) => {
|
|
let inode = Some((md.ino(), md.dev()));
|
|
if use_apparent_size {
|
|
Some((md.len(), inode))
|
|
} else {
|
|
Some((md.blocks() * get_block_size(), inode))
|
|
}
|
|
}
|
|
None => None,
|
|
}
|
|
}
|
|
|
|
#[cfg(not(target_family = "unix"))]
|
|
pub fn get_metadata(d: &DirEntry, _apparent: bool) -> Option<(u64, Option<(u64, u64)>)> {
|
|
match d.metadata().ok() {
|
|
Some(md) => Some((md.len(), None)),
|
|
None => None,
|
|
}
|
|
}
|