From 3dad7abfb8cbf0b8a4879eb32f6796e534ed02d5 Mon Sep 17 00:00:00 2001 From: "andy.boot" Date: Thu, 15 Jul 2021 13:44:07 +0100 Subject: [PATCH] Change size of softlinks to 0 Instead of the size of what they point at --- src/dirwalker.rs | 7 ++++++- src/node.rs | 10 +++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/dirwalker.rs b/src/dirwalker.rs index 7874ded..a156752 100644 --- a/src/dirwalker.rs +++ b/src/dirwalker.rs @@ -27,6 +27,7 @@ pub fn walk_it( .filter_map(|d| { let n = walk( d, + false, &permissions_flag, &ignore_directories, use_apparent_size, @@ -74,6 +75,7 @@ fn clean_inodes( }); } +// todo: check for filesystem too fn ignore_file( entry: &DirEntry, ignore_hidden: bool, @@ -86,6 +88,7 @@ fn ignore_file( fn walk( dir: PathBuf, + is_symlink: bool, permissions_flag: &AtomicBool, ignore_directories: &HashSet, use_apparent_size: bool, @@ -111,6 +114,7 @@ fn walk( if data.is_dir() && !data.is_symlink() { return walk( entry.path(), + data.is_symlink(), permissions_flag, ignore_directories, use_apparent_size, @@ -122,6 +126,7 @@ fn walk( entry.path(), vec![], use_apparent_size, + data.is_symlink(), by_filecount, ); } @@ -135,7 +140,7 @@ fn walk( } else { permissions_flag.store(true, atomic::Ordering::Relaxed); } - build_node(dir, children, use_apparent_size, by_filecount) + build_node(dir, children, use_apparent_size, is_symlink, by_filecount) } mod tests { diff --git a/src/node.rs b/src/node.rs index d7b17f6..320c077 100644 --- a/src/node.rs +++ b/src/node.rs @@ -15,11 +15,19 @@ pub fn build_node( dir: PathBuf, children: Vec, use_apparent_size: bool, + is_symlink: bool, by_filecount: bool, ) -> Option { match get_metadata(&dir, use_apparent_size) { Some(data) => { - let (size, inode_device) = if by_filecount { (1, data.1) } else { data }; + let (size, inode_device) = if by_filecount { + (1, data.1) + } else if is_symlink && !use_apparent_size { + (0, None) + } else { + data + }; + Some(Node { name: dir, size,