break platform cfg code into utils submodule

This commit is contained in:
Joe Ardent
2018-03-22 00:00:21 -07:00
parent c127580057
commit eb69ad19a0
2 changed files with 71 additions and 67 deletions
+4 -67
View File
@@ -1,5 +1,5 @@
use std::collections::HashSet;
use std;
use std::fs::{self, ReadDir};
use std::io;
@@ -7,6 +7,9 @@ use std::cmp;
use dust::{DirEnt, Node};
mod platform;
use self::platform::*;
extern crate ansi_term;
use self::ansi_term::Colour::Fixed;
@@ -34,72 +37,6 @@ fn examine_dir_str(loc: &str, apparent_size: bool) -> (bool, Node) {
(hp, Node::new(DirEnt::new(loc, new_size), result))
}
#[cfg(not(target_os = "macos"))]
fn get_block_size() -> u64 {
1024
}
#[cfg(target_os = "macos")]
fn get_block_size() -> u64 {
512
}
#[cfg(target_os = "linux")]
fn get_metadata(d: &std::fs::DirEntry, s: 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 s {
Some((md.len(), inode))
} else {
Some((md.st_blocks() * get_block_size(), inode))
}
}
None => None,
}
}
#[cfg(target_os = "unix")]
fn get_metadata(d: &std::fs::DirEntry, s: 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 s {
Some((md.len(), inode))
} else {
Some((md.blocks() * get_block_size(), inode))
}
}
None => None,
}
}
#[cfg(target_os = "macos")]
fn get_metadata(d: &std::fs::DirEntry, s: 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 s {
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")))]
fn get_metadata(d: &std::fs::DirEntry, _apparent: bool) -> Option<(u64, Option<(u64, u64)>)> {
match d.metadata().ok() {
Some(md) => Some((md.len(), None)),
None => None,
}
}
fn examine_dir(
a_dir: io::Result<ReadDir>,
apparent_size: bool,
+67
View File
@@ -0,0 +1,67 @@
use std;
#[cfg(not(target_os = "macos"))]
pub fn get_block_size() -> u64 {
1024
}
#[cfg(target_os = "macos")]
pub fn get_block_size() -> u64 {
512
}
#[cfg(target_os = "linux")]
pub fn get_metadata(d: &std::fs::DirEntry, s: 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 s {
Some((md.len(), inode))
} else {
Some((md.st_blocks() * get_block_size(), inode))
}
}
None => None,
}
}
#[cfg(target_os = "unix")]
pub fn get_metadata(d: &std::fs::DirEntry, s: 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 s {
Some((md.len(), inode))
} else {
Some((md.blocks() * get_block_size(), inode))
}
}
None => None,
}
}
#[cfg(target_os = "macos")]
pub fn get_metadata(d: &std::fs::DirEntry, s: 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 s {
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: &std::fs::DirEntry, _apparent: bool) -> Option<(u64, Option<(u64, u64)>)> {
match d.metadata().ok() {
Some(md) => Some((md.len(), None)),
None => None,
}
}