diff options
author | Sebastian Thiel <sthiel@thoughtworks.com> | 2019-06-01 11:24:42 +0530 |
---|---|---|
committer | Sebastian Thiel <sthiel@thoughtworks.com> | 2019-06-01 11:24:42 +0530 |
commit | 04f50bdcdbe995e7d9952788eb4cc4f736299c39 (patch) | |
tree | 6a0c029346be0455b8d45bf5caa05ba83b134e62 /src/lib.rs | |
parent | 638be3c8e7362b809c2c6558d630aa355349b1e8 (diff) |
An attempt to abstract link size, but it's not required actually :D
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 24 |
1 files changed, 21 insertions, 3 deletions
@@ -25,8 +25,26 @@ impl fmt::Display for WalkResult { } } +pub fn file_size_no_symlink_follow(meta: &fs::Metadata) -> u64 { + match meta.file_type().is_symlink() { + // true => sys::symlink_size(meta), + true => unimplemented!("{} {}", sys::symlink_size(meta), meta.len()), + false => meta.len(), + } +} + +#[cfg(target_os = "macos")] +mod sys { + use std::fs::Metadata; + use std::os::macos::fs::MetadataExt; + + pub fn symlink_size(meta: &Metadata) -> u64 { + meta.st_size() + } +} + mod aggregate { - use crate::{WalkOptions, WalkResult}; + use crate::{file_size_no_symlink_follow, WalkOptions, WalkResult}; use failure::Error; use std::io; use std::path::Path; @@ -43,7 +61,7 @@ mod aggregate { match entry { Ok(entry) => { num_bytes += match entry.metadata { - Some(Ok(m)) => m.len(), + Some(Ok(m)) => file_size_no_symlink_follow(&m), Some(Err(_)) => { res.num_errors += 1; 0 @@ -65,5 +83,5 @@ mod aggregate { pub use aggregate::aggregate; use jwalk::WalkDir; -use std::fmt; use std::path::Path; +use std::{fmt, fs}; |