mirror of
https://github.com/bootandy/dust.git
synced 2026-06-08 11:29:05 +03:00
Stop using target_os just use target_family
target_family unix covers linux and mac and wraps up the call for inodes in a common interface.
This commit is contained in:
+2
-34
@@ -6,23 +6,7 @@ fn get_block_size() -> u64 {
|
|||||||
512
|
512
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_family = "unix")]
|
||||||
pub fn get_metadata(d: &DirEntry, use_apparent_size: bool) -> Option<(u64, Option<(u64, u64)>)> {
|
|
||||||
use std::os::linux::fs::MetadataExt;
|
|
||||||
match d.metadata().ok() {
|
|
||||||
Some(md) => {
|
|
||||||
let inode = Some((md.st_ino(), md.st_dev()));
|
|
||||||
if use_apparent_size {
|
|
||||||
Some((md.len(), inode))
|
|
||||||
} else {
|
|
||||||
Some((md.st_blocks() * get_block_size(), inode))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_os = "unix")]
|
|
||||||
pub fn get_metadata(d: &DirEntry, use_apparent_size: bool) -> Option<(u64, Option<(u64, u64)>)> {
|
pub fn get_metadata(d: &DirEntry, use_apparent_size: bool) -> Option<(u64, Option<(u64, u64)>)> {
|
||||||
use std::os::unix::fs::MetadataExt;
|
use std::os::unix::fs::MetadataExt;
|
||||||
match d.metadata().ok() {
|
match d.metadata().ok() {
|
||||||
@@ -38,23 +22,7 @@ pub fn get_metadata(d: &DirEntry, use_apparent_size: bool) -> Option<(u64, Optio
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(not(target_family = "unix"))]
|
||||||
pub fn get_metadata(d: &DirEntry, use_apparent_size: bool) -> Option<(u64, Option<(u64, u64)>)> {
|
|
||||||
use std::os::macos::fs::MetadataExt;
|
|
||||||
match d.metadata().ok() {
|
|
||||||
Some(md) => {
|
|
||||||
let inode = Some((md.st_ino(), md.st_dev()));
|
|
||||||
if use_apparent_size {
|
|
||||||
Some((md.len(), inode))
|
|
||||||
} else {
|
|
||||||
Some((md.st_blocks() * get_block_size(), inode))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(any(target_os = "linux", target_os = "unix", target_os = "macos")))]
|
|
||||||
pub fn get_metadata(d: &DirEntry, _apparent: bool) -> Option<(u64, Option<(u64, u64)>)> {
|
pub fn get_metadata(d: &DirEntry, _apparent: bool) -> Option<(u64, Option<(u64, u64)>)> {
|
||||||
match d.metadata().ok() {
|
match d.metadata().ok() {
|
||||||
Some(md) => Some((md.len(), None)),
|
Some(md) => Some((md.len(), None)),
|
||||||
|
|||||||
Reference in New Issue
Block a user